← Back to PRs

#16609: fix: resolve session store race condition and contextTokens updates

by battman21 open 2026-02-14 23:06 View on GitHub →
channel: telegram commands agents size: S
## Summary Two focused fixes for session state correctness: - **Session store race condition (#14979):** Moved session entry construction inside the `updateSessionStore` lock callback so it reads fresh data from disk, preventing compaction or concurrent agent runs from silently overwriting updates. - **contextTokens not updated on model override (#14969):** `applyModelOverrideToSessionEntry` now calls `lookupContextTokens` for the selected model, keeping `entry.contextTokens` in sync when the user switches models via `/model`. ## Test plan - [x] `pnpm build` passes - [x] `pnpm lint` clean - [x] Existing session-store and model-override tests pass Closes #14979 Closes #14969 <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes two session state correctness issues: prevents race conditions during concurrent session updates by moving entry construction inside the lock callback, and ensures `contextTokens` stays in sync when users override the model via `/model` command. Both changes are minimal, focused, and follow existing patterns in the codebase. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - Both fixes are minimal, focused, and correct. The race condition fix properly moves the entry construction inside the lock callback to read fresh data from disk. The contextTokens fix ensures consistency when models are overridden. The changes follow existing patterns, existing tests cover the locking mechanism well, and the test plan shows build and lint passing. - No files require special attention <sub>Last reviewed commit: 710d093</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs