fix(gateway): session resolution is not newest-first, so restart resumes a stale session #603

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

Found independently by two reviewers, CONFIRMED by execution.

sessionTracker.resolve (session_commands.go:54-59) comments 'Find the most recent session matching this thread and bot' but returns the first element GetByChannel yields. The wired-up NellDB store returns document-ID order (listAllLocked reverses AllDocs, which sorts by document ID), i.e. UUID-lexicographic -- effectively random. LastActiveAt is populated on every record and never consulted.

Scenario: user runs /new 'old', chats, runs /new 'current'; daemon restarts (the tracker cache is in-memory only); the next message resolves to whichever session sorts first. Probed over 10 runs: 4 landed in the OLDER session, answering against pre-/new history. This is the user-visible lost-context class.

Also a silent backend divergence: SQLite's GetByChannel orders created_at DESC, NellDB does not, and the shared conformance suite does not pin it. Separately, SessionStore.List's doc comment (session_store.go:34-36) promises newest-first and does not deliver: saving zzz-oldest, aaa-middle, mmm-newest returns [zzz-oldest mmm-newest aaa-middle].

Blocks archie-core-b4i and archie-core-gih.


Imported from beads archie-core-1786637491754-75-8e621216 · GitHub #96 · type bug · priority P2 · created 2026-08-08 · closed 2026-08-08

Found independently by two reviewers, CONFIRMED by execution. sessionTracker.resolve (session_commands.go:54-59) comments 'Find the most recent session matching this thread and bot' but returns the first element GetByChannel yields. The wired-up NellDB store returns document-ID order (listAllLocked reverses AllDocs, which sorts by document ID), i.e. UUID-lexicographic -- effectively random. LastActiveAt is populated on every record and never consulted. Scenario: user runs /new 'old', chats, runs /new 'current'; daemon restarts (the tracker cache is in-memory only); the next message resolves to whichever session sorts first. Probed over 10 runs: 4 landed in the OLDER session, answering against pre-/new history. This is the user-visible lost-context class. Also a silent backend divergence: SQLite's GetByChannel orders created_at DESC, NellDB does not, and the shared conformance suite does not pin it. Separately, SessionStore.List's doc comment (session_store.go:34-36) promises newest-first and does not deliver: saving zzz-oldest, aaa-middle, mmm-newest returns [zzz-oldest mmm-newest aaa-middle]. Blocks archie-core-b4i and archie-core-gih. --- _Imported from beads `archie-core-1786637491754-75-8e621216` · GitHub #96 · type bug · priority P2 · created 2026-08-08 · closed 2026-08-08_
sam added the mediumbug labels 2026-10-27 13:36:59 +00:00
sam self-assigned this 2026-10-27 13:36:59 +00:00
sam closed this issue 2026-10-27 13:36:59 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#603