Repository navigation
fix(server): one handle per session when two requests load it at once - #503
Merged
Merged
Conversation
load_or_get_session checked the map, loaded from the database, then inserted. After idle eviction, two requests for the same id (a run and a history poll) could both miss, each load a copy, and the second insert replaced the first. A turn on the replaced copy then saved over the other's messages. The loaded session is now inserted only when the id is still absent; otherwise the existing handle is returned. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
load_or_get_sessionchecked the in-memory map, loaded the session from the database, then inserted it, and these steps were not atomic. After idle eviction, two requests for the same id (a run and a history poll, say) could both miss the map, each load its own copy, and the second insert replaced the first. A turn running on the replaced copy then saved over the other request's messages.The new
AppState::adopt_sessioninserts the loaded session only if the id is still absent, under the map lock, and otherwise returns the existing handle. Every request now shares one handle per session.Test: loading the same id twice returns the same
Arc, and it is the one stored in the map. The poisoned-map test also coversadopt_session. All 94 server tests pass, andlib.rsandroutes.rshave 100% line coverage.🤖 Generated with Claude Code