fix(tui): snapshot history after pending model switch applies (#76870) - #77324
Merged
kshitijk4poor merged 2 commits intoAug 3, 2026
Merged
kshitijk4poor merged 2 commits into
kshitijk4poor merged 2 commits into
Conversation
…search#76870) Deferred model switches append a marker and bump history_version at turn start; the dispatcher was snapshotting history before that mutation, so the version-mismatch guard rejected the turn's own result as a stale/concurrent write. Move the snapshot to after _apply_pending_model_switch/_sync_agent_model_with_config, under history_lock, so the turn's own preparatory mutation is included in its baseline while the anti-stale guard still catches real external writes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
teknium1 flagged ISSUE_76870_RELATORIO_CAUSA_RAIZ.md as containing stale metadata (references an unrelated local branch) and asked to drop the standalone report, keeping only the focused server.py fix and regression test.
5 tasks
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.
Summary
Fixes a deferred model-switch desync where the turn's
history/history_versionbaseline was snapshotted before_apply_pending_model_switchran, so the model-switch marker'shistory_version += 1triggered the final version-mismatch guard and silently discarded the turn's output from session history.Closes #76870. Salvage of #77021 (@JoaoMarcos44's authorship preserved via cherry-pick).
Changes
tui_gateway/server.py: moved thehistory/history_versionsnapshot from the outer function (before model switch) to inside therun()worker, after_apply_pending_model_switch+_sync_agent_model_with_config, still underhistory_lock.tests/test_tui_gateway_server.py: addedtest_prompt_submit_snapshots_history_after_pending_model_switch— fails on old ordering (empty history, spurious mismatch warning, dropped response), passes on the fix.relatorio-issue-69678-sqlite-fd-leaks.md(diagnostic report from contributor's prior merged PR; not referenced anywhere).Validation
conversation_history, spurious mismatch warning)