fix(session): reclaim sessions whose worker is gone; raise cap to 2048 (v0.4.3) #14
No reviewers
Labels
No labels
waiting-on-julian
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jlxq0/hevy-mcp!14
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/session-reclaim"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Incident fix: caldav-mcp and carddav-mcp refused every new
initializetoday with "session cap reached (256 sessions active)" while/healthstayed green; both pods were restarted as a stopgap at 15:27 SGT on 2026-10-07. The sameCappedSessionManageris in this repo, so it leaks the same way.Root cause. rmcp 1.x removes a session from
LocalSessionManageronly inclose_session. The streamable-HTTP service callscreate_sessionfor every POST without a session id and only then checks that the body isinitialize(and the protocol header); on those error paths the transport is dropped andclose_sessionnever runs, so the handle stays in the map forever. The cap counted those dead handles.Fix.
CappedSessionManagerkeeps each session's worker-transport cancellation token, which fires exactly when the transport is dropped. Sessions in that state are closed before every cap check (under the existing create gate) and by a 60 s background sweeper. Sessions whose transport is still held, including idle ones on a standalone SSE stream, are never reclaimed; rmcp's 30-minute keep-alive still ends them. This is the signal m365-mcp has shipped since v0.4.1 (#60).MAX_SESSIONS256 → 2048.Tests. Session-less non-
initializePOSTs no longer burn slots (end to end throughStreamableHttpService); dead sessions are reclaimed and free capacity; live and idle initialized sessions are never reclaimed and the cap still holds; the sweeper reclaims without a newinitializeand stops with the manager. Mutation: removing the reclaim fromcreate_sessionreddens two of them.Gates run locally:
cargo fmt --all --check,cargo clippy --all-targets --all-features --locked -- -D warnings,cargo test --all-features --locked.🤖 Generated with Claude Code