Expand description
Periodic sweep that DELs abandoned sessions.
Two session kinds, two liveness rules:
-
WS shim sessions (
client_id: Some): live while that client id is in the liveClientstore. When the client drops, aSTALE_AFTERgrace covers reconnect blips, then the session is DEL’d. Tracking is in-memory (disconnected_since); daemon restart resets it, giving every reloaded session a fresh grace window. -
Pull/hook sessions (
client_id: None): an HTTP-MCP agent that registered via the/hook/session-startendpoint has no WS client at all — it would be swept instantly by the client-id rule. Its liveness is instead itslast_activity_at(the hook bumps it every turn) plus a longHOOK_BACKSTOPgrace. The clean teardown path is the explicit/hook/session-endDEL; this grace is only a backstop for a client that crashed without firing SessionEnd. Becauselast_activity_atis wall-clock and persisted, the backstop survives daemon restarts.
Constants§
- HOOK_
BACKSTOP - How long a pull/hook session (no WS client) may go without any hook
activity before the backstop DELs it. Generous: merely-idle sessions
re-register on their next turn, so this only needs to be short enough
to eventually reclaim sessions whose client crashed without firing
/hook/session-end. 60 min. - STALE_
AFTER - How long a WS-shim session must be without a live client before DEL.
- TICK_
INTERVAL - How often the sweeper wakes up to check for stale sessions. Anything
roughly under
STALE_AFTERis fine; the trade-off is reaction latency (lower) vs. wake-ups per minute (higher).
Functions§
- run_
sweeper - Run the sweeper forever. Spawn this on a tokio task and forget it.