fix(tui_gateway): stop replaying live-turn user text after redirect - #84520
Closed
StanleyStetson wants to merge 2 commits into
Closed
StanleyStetson wants to merge 2 commits into
StanleyStetson wants to merge 2 commits into
Conversation
A mid-turn correction (Desktop session.redirect / busy interrupt redirect) must not leave a server-queue self-copy of the live inflight user prompt. Otherwise post-turn _drain_queued_prompt restarts that original text as a fresh agent turn after Q completes — duplicate active role=user rows and a second conversation turn (NousResearch#84417). Scrub text-only self-duplicates of inflight_turn.user on successful redirect/steer, refuse admitting them in _enqueue_prompt, rewrite merged "{P}\n\n{Q}" slots to Q-only, and bump _queued_prompt_generation when compression rotates session_key so in-flight drain claims cannot dispatch against the continuation with a stale generation. Fixes NousResearch#84417
When _queued_prompt_generation advances between claim and dispatch (Stop, compress re-anchor), do not drop the claimed envelope. Put it back at the head of the queue so legitimate follow-ups survive. Part of NousResearch#84417 belt accuracy.
Contributor
Author
|
Superseded by #84589 — same fix as a single conventional commit (full scrub + generation-cancel requeue) with an up-to-date PR template body. Closing this two-commit branch to keep 1 PR = 1 commit. |
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.
What does this PR do?
Stops the tui_gateway server queue from re-firing the live turn's original user prompt P after a mid-turn correction Q (Desktop
session.redirect/ busy-input interrupt redirect). That re-fire produced a second agent turn and a second activerole=userrow with the same content (#84417).Root cause (contract layer): while turn P was live, a text-only self-copy of P could sit in
session["queued_prompt"]/queued_prompts(e.g. mid-busy re-submit while redirect was not available; consecutive-text merge could also glueP\n\nQ). Successful redirect/steer of Q did not scrub that self-duplicate, so post-settle_drain_queued_promptrestarted P.Approach:
inflight_turn.useron successful redirect/steer; rewrite merged{P}\n\n{Q}→Qonly._enqueue_prompt(scrub first so merge cannot re-glue P+Q)._queued_prompt_generationso an in-flight drain claim cannot dispatch against the continuation with a stale generation (queue contents for legitimate follow-ups are kept).Scope / residual (honest limits of this PR):
$queuedPromptsBySession) is unchanged; a user-queued follow-up can still drain by design.Related Issue
Fixes #84417
Type of Change
Changes Made
tui_gateway/server.py—_sanitize_queued_entry_vs_inflight_user,_drop_queued_duplicates_of_inflight_user; scrub on successful busy redirect/steer; refuse self-dup in_enqueue_prompt; bump_queued_prompt_generationin_sync_session_key_after_compresson rotation.tui_gateway/methods_session.py— scrub on successfulsession.redirectandsession.steer(Desktop production path).tests/test_tui_gateway_queue_on_busy.py— redirect scrub, hard-interrupt path, merge rewrite, drain E2E (no second P), enqueue refuse, compress generation bump / no-op.tests/test_tui_gateway_server.py—session.redirectRPC scrub + build-window queue of Q scrubs stale P.How to Test
tests/test_tui_gateway_queue_on_busy.py— 24 passed; relatedsession.redirect/ compress re-anchor tests passed viascripts/run_tests.sh.session.redirectRPC)session.redirectenqueue of Q scrubs P_drain_queued_promptdoes not start a turn with PP\n\nQrewrites to Q-onlyqueued_prompt=P+ redirect(Q) → pre-fix drain re-fired P; post-fix queue scrubbed, drain no-op.Checklist
Code
fix(scope):,feat(scope):, etc.)scripts/run_tests.shon the affected tests and they pass (project canonical runner)scripts/run_tests.shDocumentation & Housekeeping
docs/, docstrings) — N/Acli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/A