Skip to content

fix(tui_gateway): stop live-turn replay after redirect and preserve steer-mode message bursts - #86593

Merged
teknium1 merged 2 commits into
mainfrom
salvage/desktop-steer-queue
Aug 15, 2026
Merged

teknium1 merged 2 commits into
mainfrom
salvage/desktop-steer-queue

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

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 current origin/main with 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 (Desktop session.redirect / busy-input redirect), which produced a duplicate agent turn and duplicate role=user row (#84417):

  • Scrub text-only self-duplicates of inflight_turn.user on successful redirect/steer; rewrite merged {P}\n\n{Q}Q.
  • Refuse admitting a text-only self-copy of the live user in _enqueue_prompt.
  • Bump _queued_prompt_generation on compression session rotation; a generation-cancelled drain claim is restored to the queue so legitimate follow-ups are never dropped.

2. New fix for #86134fix(tui_gateway): keep steer-mode fall-through bursts queued instead of interrupting.

Root cause: in _handle_busy_submit, the escalation guard was if mode != "queue" — so steer mode fall-throughs (agent steer() 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_prompt path. Only explicit interrupt mode 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

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

How to Test

scripts/run_tests.sh tests/test_tui_gateway_queue_on_busy.py tests/test_tui_gateway_server.py

Evidence (local, venv pytest):

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

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs (sweep documented above)
  • My PR contains only changes related to this fix
  • Tests pass locally (see evidence above)
  • I've added tests for my changes
  • I've tested on my platform: Linux

Documentation & Housekeeping

  • Docs — N/A (behavior fix, docstrings updated in-line)
  • cli-config.yaml.example — N/A (no config keys changed)
  • Cross-platform — pure Python gateway session-dict logic
  • Tool descriptions/schemas — N/A

Infographic

Steer & Queue: no message left behind

Nous Research

StanleyStetson and others added 2 commits August 14, 2026 18:43
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
@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 6e4d62d — fix(tui_gateway): keep steer-mode fall-through bursts queued

⚠️ Warnings

CI timings · View report · View job

Wall time 4m39s vs 3m27s (+34.8%). 15 job(s) slower, 9 faster,

  • Python tests / Run tests slice 1/12: -17.0s
  • Python tests / Run tests slice 4/12: -12.0s
  • Python tests / Run tests slice 3/12: -12.0s
  • Python tests / Run tests slice 2/12: -12.0s
  • OSV scan / Scan lockfiles / osv-scan: +12.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.

@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/) area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 15, 2026
@teknium1
teknium1 merged commit 4ac12d5 into main Aug 15, 2026
48 checks passed
@teknium1
teknium1 deleted the salvage/desktop-steer-queue branch August 15, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history 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

3 participants