Skip to content

fix(mcp-sessions): require a minimum idle age before LRU eviction at capacity (#467) - #468

Merged
James3014 merged 1 commit into
mainfrom
fix/issue-467-lru-min-idle-guard
Oct 9, 2026
Merged

James3014 merged 1 commit into
mainfrom
fix/issue-467-lru-min-idle-guard

Conversation

@James3014

Copy link
Copy Markdown
Owner

Closes #467. LRU eviction at capacity (added in #461) now only considers sessions with no in-flight request, not pending close, and idle for at least DEVSPACE_MCP_SESSION_LRU_MIN_IDLE_MS (default 60 000 ms). Younger sessions stay protected, so one noisy client can no longer evict other clients' recently active sessions; if no session qualifies, registration is rejected with the same 503 / -32004 as before #461.

  • New setting DEVSPACE_MCP_SESSION_LRU_MIN_IDLE_MS (config-file key mcpSessionLruMinIdleMs), validated as a positive integer no greater than the effective idle timeout (same Invalid <NAME>: <value> error as the sibling settings). The unset default is clamped to the idle timeout so a short idle timeout never makes the default invalid.
  • evictLruToLimit() and hasEvictableSession() share the rule, so canAcceptRegistration() / admitRegistration() still agree with register().
  • Rejection cause: register() rejections carry rejectionCause: "all_in_flight" | "no_session_idle_min" and the registry exposes capacityRejectionCause() for the pre-check path. mcp_session_capacity_rejected logs it as rejectionCause. The HTTP response is unchanged.
  • The registry option lruMinIdleMs defaults to min(60 s, idleTimeoutMs) when omitted, so callers that only set an idle timeout keep pre-P1: MCP session store rejects new sessions with 503 while idle sessions with no in-flight requests remain evictable #461 behavior for young sessions.
  • Not included: the issue's optional "prefer evicting the same client's own idle sessions" attribution.
  • Tests: 256 sessions idle 10 s is rejected (no_session_idle_min, capacityRejections +1, lruEvictions unchanged); 256 idle 90 s evicts the LRU with no rejection; exact-boundary check; all in flight rejects with all_in_flight; mixed young/in-flight case; config default, env override, config clamp, and rejection of 0, negative, non-integer, and values above the idle timeout. P1: MCP session store rejects new sessions with 503 while idle sessions with no in-flight requests remain evictable #461 tests that assumed unconditional eviction now set lruMinIdleMs explicitly and the rejection assertions include rejectionCause.

Verification: npx tsx src/mcp-sessions.test.ts, npx tsx src/config.test.ts, npx tsx src/server.test.ts (67 pass), npm run typecheck, npm run build.

🤖 Generated with Claude Code

@James3014
James3014 enabled auto-merge (squash) October 9, 2026 01:35
…capacity (#467)

LRU eviction at capacity now only evicts sessions idle for at least
DEVSPACE_MCP_SESSION_LRU_MIN_IDLE_MS (default 60s, <= idle timeout), so one
client cannot churn others' recently active sessions. Rejections report
rejectionCause (all_in_flight | no_session_idle_min) in the
mcp_session_capacity_rejected log; the HTTP response is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@James3014
James3014 force-pushed the fix/issue-467-lru-min-idle-guard branch from 31ad630 to 59bfe99 Compare October 9, 2026 01:51
@James3014
James3014 merged commit 5c008b0 into main Oct 9, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P2: LRU session eviction at capacity needs a minimum idle age so one client cannot evict others' live sessions (follow-up to #461)

1 participant