Skip to main content

Module cleanup

Module cleanup 

Source
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 live Client store. When the client drops, a STALE_AFTER grace 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-start endpoint has no WS client at all — it would be swept instantly by the client-id rule. Its liveness is instead its last_activity_at (the hook bumps it every turn) plus a long HOOK_BACKSTOP grace. The clean teardown path is the explicit /hook/session-end DEL; this grace is only a backstop for a client that crashed without firing SessionEnd. Because last_activity_at is 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_AFTER is 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.