fix(tui_gateway): queue mid-turn prompts instead of dropping them on a busy retry - #52594
Merged
Conversation
…a busy retry A prompt sent while a turn was in flight got rejected with 4009 "session busy", which pushed clients (the desktop app) into a deadline-bounded busy-retry. When turn teardown outlived that deadline — e.g. the user hits stop while a slow, non-interruptible tool (web_search, read_file, an MCP call) is mid-flight, since the sequential executor only checks the interrupt flag between tools — the resubmitted message was silently dropped: "it just doesn't listen". Wire the previously-dead display.busy_input_mode config into prompt.submit: instead of rejecting, apply the policy and queue the message to run as the next turn (drained in run()'s tail, ahead of goal/notification follow-ups). Modes: interrupt (default) interrupts the live turn so it winds down promptly then runs the queued message; queue runs it after the current turn finishes; steer injects it into the live turn when accepted, else queues. The queued slot pins the sender's transport and losslessly merges a second arrival. No client deadline, no dropped sends.
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:2989: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
✅ Fixed issues (1):
| Rule | Count |
|---|---|
invalid-assignment |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
Unchanged: 5941 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
…bmit-on-busy fix(tui_gateway): queue mid-turn prompts instead of dropping them on a busy retry
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
…bmit-on-busy fix(tui_gateway): queue mid-turn prompts instead of dropping them on a busy retry
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…bmit-on-busy fix(tui_gateway): queue mid-turn prompts instead of dropping them on a busy retry
8 tasks
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…bmit-on-busy fix(tui_gateway): queue mid-turn prompts instead of dropping them on a busy retry
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…bmit-on-busy fix(tui_gateway): queue mid-turn prompts instead of dropping them on a busy retry
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.
Summary
Follow-up to #52592. Symptom reported (desktop app): "if I send a msg and then interrupt and send another one, it doesn't just stop and listen with prev context in mind — it'll often just not listen."
The fix is in the shared
tui_gateway, so it covers both the desktop app and the TUI.Root cause
When a turn is in flight,
prompt.submitrejected the next message with4009 "session busy"and left clients to cope. The desktop app turns that into a deadline-bounded busy-retry (withSessionBusyRetry, 6s). But turn teardown can outlive that window: the sequential tool executor only checks the interrupt flag between tools (agent/tool_executor.py), so a slow, non-interruptible tool already in flight (web_search,read_file, an MCP call, a longterminal) keeps running after stop. Teardown > 6s → the retry gives up → the resubmitted message is dropped → "it just doesn't listen".Fix
Wire the previously-dead
display.busy_input_modeconfig intoprompt.submit. Instead of rejecting a mid-turn prompt, queue it to run as the next turn (drained inrun()'s tail, ahead of goal/notification follow-ups):interrupt(default): interrupt the live turn so it winds down promptly, then run the queued message.queue: run it after the current turn finishes (no interrupt).steer: inject into the live turn if accepted, else queue.The queued slot pins the sender's transport (so the drained turn streams to the right client) and losslessly merges a second arrival (mirroring the consecutive-user merge in
repair_message_sequence). No client deadline, no dropped sends. Combined with #52592, the resumed turn also keeps full alternation-clean context.Surfaces / compatibility
prompt.submitresponse body, and{status:"queued"}makes its busy-retry resolve immediately instead of racing the deadline.busy → false), not a fixed deadline — so it didn't drop messages, it waited. This change does not conflict or double-run: the TUI doesn't callprompt.submitwhile busy on the normal path (it intercepts and queues locally), so the server queue isn't even hit there. The one place it optimistically sends (useSubmission.tsrace fallback) previously relied on thesession busyerror to re-queue; now the server queues it once and returns success, so that race window gets strictly more robust. Net: the gateway becomes the single source of truth for both clients.Test plan
tests/test_tui_gateway_queue_on_busy.py(10 tests): enqueue pin/merge;_handle_busy_submitper-mode (interrupt/queue/steer + steer-rejected fallback);_drain_queued_promptfires/claims-running/restores-transport, no-ops when empty or already-running, and releasesrunningon dispatch failure.tests/test_tui_gateway_server.py+tests/tui_gateway/green (289 passed; 1 pre-existing failure unrelated —test_browser_manage_connect_default_local_reports_launch_hintasserts no Chromium is installed, fails only on machines that have Chrome).