fix(gateway): stop Desktop retries from silently truncating session history (#86573) - #86649
Merged
Conversation
Contributor
૮ >ﻌ< ა ci reviewran on 4775aec — fix(gateway): reject unsafe ordinal-only truncation
|
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.
Salvage of #86605 by @fangliquanflq, cherry-picked onto current
mainwith 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
test_prompt_submit_refuses_ordinal_only_when_history_has_row_idsexercises the realprompt.submithandler: asserts error 4004, no history mutation, noreplace_messagescall, no turn started.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