fix(tui_gateway): stop live-turn replay after redirect and preserve steer-mode message bursts - #86593
Merged
Merged
Conversation
A mid-turn correction (Desktop session.redirect / busy-input 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 (#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, bump _queued_prompt_generation on compression session rotation, and restore the claimed queue envelope when generation cancels mid-drain. Stabilize profile-scoped agent-build unit tests under CI load. Fixes #84417
…of interrupting Desktop/TUI busy-input `steer` mode escalated any fall-through message (steer() rejected, raised, or a non-steerable multimodal payload) into a hard interrupt of the live turn. AIAgent.interrupt() also clears the pending steer buffer, so a burst of user messages sent while the agent was busy could be silently destroyed: earlier successfully-steered messages were dropped from the buffer and the live turn was killed. Steer-mode fall-throughs now keep pure queue semantics: preserved FIFO in queued_prompt/queued_prompts and drained on turn end, per the existing steer contract. Only explicit `interrupt` mode still fires _interrupt_busy_session. No synthetic user messages are injected mid-loop; accepted steers continue through the sanctioned OOB steer-marker path. Regression tests cover: rejected steer queues without interrupting, steer exception falls back to queue, multimodal payload queues, a mixed burst preserves accepted steers plus the queued fall-through, and a fall-through burst drains all texts FIFO after turn end. Fixes #86134
Contributor
૮ >ﻌ< ა ci reviewran on 6e4d62d — fix(tui_gateway): keep steer-mode fall-through bursts queued
|
19 tasks
12 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.
What does this PR do?
Salvages and completes the Desktop steer-and-queued-messages cluster into one green branch:
1. Cherry-pick of #84589 (credit: @StanleyStetson) —
fix(tui_gateway): stop replaying live-turn user text after redirect. Applied cleanly onto currentorigin/mainwith original authorship preserved. Stops the tui_gateway server queue from re-firing the live turn's original user prompt P after a mid-turn correction Q (Desktopsession.redirect/ busy-input redirect), which produced a duplicate agent turn and duplicaterole=userrow (#84417):inflight_turn.useron successful redirect/steer; rewrite merged{P}\n\n{Q}→Q._enqueue_prompt._queued_prompt_generationon compression session rotation; a generation-cancelled drain claim is restored to the queue so legitimate follow-ups are never dropped.2. New fix for #86134 —
fix(tui_gateway): keep steer-mode fall-through bursts queued instead of interrupting.Root cause: in
_handle_busy_submit, the escalation guard wasif mode != "queue"— so steer mode fall-throughs (agentsteer()rejected, raised, or a non-steerable multimodal payload) fired_interrupt_busy_session.AIAgent.interrupt()both kills the live turn and clears the pending steer buffer, so a burst of user messages sent while the agent was busy could be silently destroyed: earlier successfully-steered messages vanished from the buffer and the in-flight work was killed. Exactly the reported symptom: "messages become steer / OOB and older asks get dropped."Fix: steer-mode fall-throughs now keep pure queue semantics — preserved FIFO in
queued_prompt/queued_prompts, drained on turn end via the existing_drain_queued_promptpath. Only explicitinterruptmode still escalates to a hard interrupt. Message-role alternation invariants are untouched: accepted steers continue through the sanctioned OOB steer-marker mechanism (apply_pending_steer_to_tool_results), and no synthetic user messages are injected mid-loop.Related Issues
Type of Change
Changes Made
tui_gateway/server.py— fix(tui_gateway): stop replaying live-turn user text after redirect #84589's scrub/refuse/generation logic; Desktop: queued burst of user messages dropped when treated as steer #86134:mode != "queue"→mode == "interrupt"escalation guard with contract comment.tui_gateway/methods_session.py— (fix(tui_gateway): stop replaying live-turn user text after redirect #84589) scrub on successfulsession.redirect/session.steerRPCs.tests/test_tui_gateway_queue_on_busy.py— fix(tui_gateway): stop replaying live-turn user text after redirect #84589's suite plus 5 new Desktop: queued burst of user messages dropped when treated as steer #86134 regressions:tests/test_tui_gateway_server.py— (fix(tui_gateway): stop replaying live-turn user text after redirect #84589)session.redirectRPC scrub coverage.How to Test
Evidence (local, venv pytest):
tests/test_tui_gateway_queue_on_busy.py— 30 passed (25 from fix(tui_gateway): stop replaying live-turn user text after redirect #84589 + 5 new)tests/test_tui_gateway_queue_on_busy.py+tests/test_tui_gateway_server.py— 587 passedtests/tui_gateway/— 450 passed;tests/test_tui_gateway_ws.py— 6 passedserver.py, pass post-fix.ruff checkclean; Windows-footgun checker clean; attribution audit: all emails mapped.Salvage sweep
Open-PR sweep for #86134 ('queued burst', 'steer drop', 'busy queue desktop', 'queue follow-up') found no PR fixing this specific steer-path burst drop: #63298 (FIFO boundaries, different scope/architecture), #77892 (gateway platform debounce), #60555 (leftover steer marker), #65205 (desktop TurnQueue feature) are adjacent but none remove the steer-mode hard-interrupt escalation that destroys the burst. Implemented directly, minimal one-guard change.
Checklist
Code
Documentation & Housekeeping
cli-config.yaml.example— N/A (no config keys changed)Infographic
Nous Research