Skip to content

fix(tui): snapshot history after pending model switch applies (#76870) - #77324

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/77021-history-snapshot
Aug 3, 2026
Merged

kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/77021-history-snapshot

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Contributor

Summary

Fixes a deferred model-switch desync where the turn's history/history_version baseline was snapshotted before _apply_pending_model_switch ran, so the model-switch marker's history_version += 1 triggered 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 the history/history_version snapshot from the outer function (before model switch) to inside the run() worker, after _apply_pending_model_switch + _sync_agent_model_with_config, still under history_lock.
  • tests/test_tui_gateway_server.py: added test_prompt_submit_snapshots_history_after_pending_model_switch — fails on old ordering (empty history, spurious mismatch warning, dropped response), passes on the fix.
  • Deleted stale relatorio-issue-69678-sqlite-fd-leaks.md (diagnostic report from contributor's prior merged PR; not referenced anywhere).

Validation

Before fix After fix
New regression test FAIL (empty conversation_history, spurious mismatch warning) PASS
38 prompt_submit + model_switch tests PASS PASS
Mutation check (revert fix) Test fails as expected
/simplify-code (3 reviewers) No material findings

JoaoMarcos44 and others added 2 commits August 3, 2026 09:43
…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.
@kshitijk4poor
kshitijk4poor merged commit 3b53a3c into NousResearch:main Aug 3, 2026
35 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage/77021-history-snapshot branch August 5, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Model switch mid-session triggers history_version mismatch — all subsequent agent output discarded (empty assistant messages in DB)

2 participants