Skip to content

fix(gateway): stop Desktop retries from silently truncating session history (#86573) - #86649

Merged
teknium1 merged 1 commit into
mainfrom
salv-86605-desktop
Aug 15, 2026
Merged

fix(gateway): stop Desktop retries from silently truncating session history (#86573)#86649
teknium1 merged 1 commit into
mainfrom
salv-86605-desktop

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #86605 by @fangliquanflq, cherry-picked onto current main with authorship preserved.

What this fixes

Fixes #86573: a Desktop retry/resubmit of a failed turn could silently truncate durable session history at the wrong user turn. The retry path traveled the ordinal-only back-compat branch of prompt.submit, and after in-place compactions/rebuilds the renderer's and gateway's ordinal address spaces drift — in the reported incident a stale ordinal cut 68 messages (4 user-turns deeper than intended) out of the model's active context while the Desktop transcript still showed them.

This is the residual hole of #82959 that the row-id guard from #83785 explicitly did not cover: #83785 protects requests that carry truncate_before_row_id / message-id targets, but the ordinal-only fallback still trusted the client's positional ordinal unconditionally.

The fix

tui_gateway/methods_prompt.py: when the session's active user turns carry durable row ids, an ordinal-only truncation request is refused with error 4004 ("include truncate_before_row_id") before any in-memory or DB mutation. Ephemeral histories without row ids keep the legacy ordinal-only compatibility path unchanged.

Verification

  • New regression test test_prompt_submit_refuses_ordinal_only_when_history_has_row_ids exercises the real prompt.submit handler: asserts error 4004, no history mutation, no replace_messages call, no turn started.
  • Full file green: tests/test_tui_gateway_server.py — 567 passed.

Credit

All substantive work by @fangliquanflq (reliable repeat contributor); reported with a full production forensic trace by @CCXXXI in #86573.

Infographic

infographic

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 15, 2026
@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 4775aec — fix(gateway): reject unsafe ordinal-only truncation

⚠️ Warnings

CI timings · View report · View job

Wall time 23m29s vs 9m59s (+135.2%). 9 job(s) slower, 14 faster, 1 unchanged.

  • Python tests / Run tests slice 4/12: +29.0s
  • Python tests / Run tests slice 8/12: -25.0s
  • Python tests / Run tests slice 11/12: +25.0s
  • Python tests / Run tests slice 1/12: -24.0s
  • Python tests / Run tests slice 9/12: +18.0s

OSV vulnerability scan · View job

5 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop retry of a failed turn silently truncates history via ordinal-only path — row-id guard (#83785) does not cover it

3 participants