feat(sessions): edit session heartbeat and stale session sweeper #164
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Context
Sub-issue of #125 (Context-Aware Part Subscription System).
Edit sessions must be kept alive by the client's SSE connection. If a client crashes, loses network, or the user walks away, the session becomes stale and must be auto-released to avoid orphaned locks.
Heartbeat Mechanism
The SSE connection is the heartbeat signal. While a workstation has an active SSE connection, its sessions are alive.
1. SSE Heartbeat Integration
In the SSE handler, when the broker heartbeat fires (every 30s), update all edit sessions for connected workstations:
The
TouchHeartbeatmethod (from #163) runs:2. Stale Session Sweeper
Add a background goroutine started in
cmd/silod/main.go:session_timeout_minutesfrom config (default 15 min)ExpireStale()returns the list of released sessions so SSE events can be broadcast3. SSE Disconnect Cleanup
When an SSE connection closes (client disconnect), release all sessions for that workstation:
This provides immediate cleanup rather than waiting for the sweeper.
4. Config
Uses the
session_timeout_minutesfield from the sessions module config (#161):Files to Modify
internal/api/sse_handler.go— disconnect cleanup, heartbeat touchcmd/silod/main.go— start sweeper goroutineinternal/api/session_handlers.goor new file — sweeper logicAcceptance Criteria
last_heartbeatfor workstation's sessionssession_timeout_minutesedit.session_releasedSSE eventsDepends On
Part Of
#125