fix: session Update clobbers user_turns from stale in-memory structs#766
Closed
sam-saffron-jarvis wants to merge 1 commit into
Closed
fix: session Update clobbers user_turns from stale in-memory structs#766sam-saffron-jarvis wants to merge 1 commit into
sam-saffron-jarvis wants to merge 1 commit into
Conversation
Owner
|
Implemented the important fixes directly in the main worktree; closing this PR. |
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.
What changed
user_turnsfromSQLiteStore.Updateso metadata-only updates no longer write a caller-supplied turn count back intosessions.user_turnslike the other counters that must be mutated through atomic store paths.TestUpdateDoesNotClobberUserTurnsto cover the failure mode whereIncrementUserTurnsis followed byUpdateon a stale in-memory session struct.Why this is high-value
user_turnsis a durable counter used for user-visible state and downstream logic. In the current code,IncrementUserTurnsatomically increments the database value, but a laterUpdatecall can overwrite that increment with a stale in-memory value. The Telegram path already does exactly that when it increments the counter and then persists the first-message summary without first updatingsess.meta.UserTurns. This fix removes the clobber path entirely and keeps turn-count mutations on the atomic update path.Validation
internal/session/sqlite.goand the Telegram call path ininternal/serve/telegram.go.go test ./internal/session -run 'TestUpdateDoesNotClobber(TokenMetrics|UserTurns)$'go build ./...go test ./...git diff --check