Repository navigation
Conversation
A concurrent append can commit after get_session reads the session row but before it reads the events or the app and user state. The returned session then combines values from different revisions. list_sessions reads scoped state in separate queries as well. Hold a read transaction across those queries and release it before building the returned sessions. Exercise both reads with an append that commits on a second connection between the session and scoped reads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
With a file-backed SQLite session, a tool can update session, app and user state together, yet a concurrent
get_session()can return the old event history and session state alongside the new app and user values.list_sessions()can return the same mix. Each SELECT sees the latest commit independently.Start a read transaction before fetching the session rows and release it after the last state query. Event parsing and list construction happen after the transaction ends.
Testing Plan
Unit Tests:
Both regression cases failed before the fix and passed afterward. The full suite passed on Python 3.11, 3.12 and 3.14 on the first run. On 3.13 one in-memory streaming telemetry test failed on the first run. It passed in isolation on both main and this branch, and the full 3.13 suite passed on rerun. All 14 pre-commit hooks passed.
Manual End-to-End (E2E) Tests:
On a WAL database, start reading a session with three counters set to zero. Between the history read and the app-state read, run a scripted agent on a second connection. Its tool increments all three counters. Before this change the reader saw
(0, 1, 1)and no events. It now sees(0, 0, 0). A fresh read sees(1, 1, 1)and four events, and the next turn receives the original tool result. The same check passed with streaming on and off.Checklist
Additional context
The regression uses WAL so the writer can commit at a known point while the reader is still active. With the default rollback journal, the writer waited for the active reader. Both read methods returned the old counters, and a fresh read returned the updated counters and event.