fix(gateway): resolve() orphans a session when it loses the double-check race #933

Closed
opened 2026-10-27 13:38:21 +00:00 by sam · 0 comments
Owner

CONFIRMED by execution with a blocking store decorator. sessionTracker.resolve calls sessions.Save BEFORE cacheActive, which may then discard the ID in favour of a racing caller's. The write is not rolled back.

Interleaving: goroutine A misses the cache and GetByChannel returns empty; meanwhile /new saves a UUID session and setActives it; A resumes, saves the deterministic session 'chat-y', then cacheActive returns the UUID. Store holds 2 sessions; 'chat-y' is unreachable, shows up in /sessions and /topic listings as '(untitled)', and per the newest-first bug can be silently resurrected on restart.

Applies equally to a racing /resume, /branch or /topic -- the daemon genuinely runs commands on lane goroutines while submitTurn resolves on the bot worker.

Note the synchronization itself is correct: all four accesses to sessionTracker.active are guarded, and stripping the locks produces 12 race-detector reports plus an assertion failure, so the test is load-bearing. This is a logic bug inside the guarded code, not a race.


Imported from beads archie-core-1786637500430-405-40bc3a73 · GitHub #426 · type bug · priority P2 · created 2026-08-08 · closed 2026-08-08

CONFIRMED by execution with a blocking store decorator. sessionTracker.resolve calls sessions.Save BEFORE cacheActive, which may then discard the ID in favour of a racing caller's. The write is not rolled back. Interleaving: goroutine A misses the cache and GetByChannel returns empty; meanwhile /new saves a UUID session and setActives it; A resumes, saves the deterministic session 'chat-y', then cacheActive returns the UUID. Store holds 2 sessions; 'chat-y' is unreachable, shows up in /sessions and /topic listings as '(untitled)', and per the newest-first bug can be silently resurrected on restart. Applies equally to a racing /resume, /branch or /topic <id> -- the daemon genuinely runs commands on lane goroutines while submitTurn resolves on the bot worker. Note the synchronization itself is correct: all four accesses to sessionTracker.active are guarded, and stripping the locks produces 12 race-detector reports plus an assertion failure, so the test is load-bearing. This is a logic bug inside the guarded code, not a race. --- _Imported from beads `archie-core-1786637500430-405-40bc3a73` · GitHub #426 · type bug · priority P2 · created 2026-08-08 · closed 2026-08-08_
sam added the mediumbug labels 2026-10-27 13:38:21 +00:00
sam self-assigned this 2026-10-27 13:38:21 +00:00
sam closed this issue 2026-10-27 13:38:21 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#933