fix: deliver leftover /steer as out-of-band user message (#60543) - #60555
astraltrekkin wants to merge 2 commits into
Conversation
…usResearch#60543) A /steer that lands after the final assistant turn — with no remaining tool batch to drain into — is returned as result["pending_steer"] and delivered as the next user turn. Both delivery sites forwarded it as raw text, so the model received bare /steer text instead of the [OUT-OF-BAND USER MESSAGE] marker the mid-batch and pre-API drain paths use. On the gateway path, a steer whose text starts with "/" could additionally be swallowed by the slash-command discard net. Add format_leftover_steer_for_delivery() beside the existing steer helpers and route both consumers (cli.py, gateway/run.py) through it. Tests: tests/run_agent/test_steer_leftover_marker.py (6 cases) cover both paths, the marker contract, and the gateway slash-command net. 52 passing across the steer, concurrent-interrupt, tui-gateway-queue and turn_finalizer suites.
…pping it A /steer that lands after the final tool batch (e.g. during the final API call when the model returns text with no further tool calls) cannot be injected into any tool result. run_conversation() hands it back in result["pending_steer"]; gateway/run.py and cli.py re-deliver it as the next user turn, but the desktop/web surface (tui_gateway) never read it — the UI accepted the steer (showed 'queued'), then silently lost it. Add _deliver_leftover_steer(): capture pending_steer in _run_prompt_submit's run() closure and dispatch it in the turn tail, after _drain_queued_prompt (an explicit queued/interrupt prompt wins). If a fresh user turn already claimed the session, re-stash the steer via agent.steer() so that turn's own drain picks it up. Upstream context: NousResearch#60543 tracks the leftover- steer mechanism for CLI/gateway (PR NousResearch#60555, unmerged); the tui_gateway consumer gap is unreported upstream as of c552984.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for covering the verified CLI and gateway raw-delivery paths. Current main still has the raw passthroughs at cli.py:12884-12888 and gateway/run.py:20028-20032, and the marker approach preserves the existing trusted-steer contract from agent/prompt_builder.py:595-614.
Problems
- The standard Ink TUI remains unfixed. It sends
/steerthroughtui_gateway/server.py:8427-8449, while_run_prompt_submit()callsrun_conversation()attui_gateway/server.py:9103and processes the result at9148-9205without readingpending_steer; the tail only drains queued prompts at9376-9380. This still drops a leftover steer for the reported TUI flow. - The regression tests duplicate the intended delivery statements (
tests/run_agent/test_steer_leftover_marker.py:198-202and229-250) instead of invokingcli.pyorgateway/run.py, so they do not prove those production call sites are wired.
Suggested changes
- Add the
tui_gatewayconsumer after_drain_queued_prompt()so an explicit queued prompt retains priority. - Test the actual CLI, gateway, and TUI delivery seams, including a
/stop …leftover through the gateway safety net.
Automated hermes-sweeper review.
| pending_input: "queue.Queue[str]" = queue.Queue() | ||
| _leftover_steer = result.get("pending_steer") if result else None | ||
| if _leftover_steer: | ||
| pending_input.put(format_leftover_steer_for_delivery(_leftover_steer)) |
There was a problem hiding this comment.
This mirrors the proposed CLI statement rather than invoking the CLI handler, so it still passes if cli.py forwards raw pending_steer. Please exercise a production delivery seam (or a helper actually called by it) to make the regression test wiring-sensitive.
|
@teknium1 Adressed both:
|
Cover the Ink TUI leftover path after queued prompts, and exercise the real CLI/gateway/TUI seams so regressions catch raw pending_steer passthrough. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Verified on a clean Repro on the tui_gateway/desktop path (independent of the CLI/gateway repro in #60543): a Semantics match the gateway path: all three seams (cli/gateway/tui) now wrap the leftover via the shared Tests: Minimal fix for #60543 on the tui path; #65205 covers the broader queue unification (agent-side TurnQueue). |
What does this PR do?
Fixes a
/steermessage being lost / delivered without its trust marker when it arrives after the final assistant turn./steerhas three delivery paths. Two wrap the user's message in the[OUT-OF-BAND USER MESSAGE]marker so the model treats it as a genuine user instruction rather than tool output / prompt injection (apply_pending_steer_to_tool_results, and the pre-API drain inconversation_loop.py). The third — the "leftover" path, taken when a steer lands after the final assistant turn with no remaining tool batch to drain into — did not.turn_finalizer.pyhands the raw steer back asresult["pending_steer"], and both consumers delivered it verbatim as the next user turn, so the model saw bare/steertext instead of the marker.On the gateway path there was a sharper failure: its downstream slash-command discard net drops any pending text starting with
/, so a leftover steer whose text begins with/(e.g. steering with/stop the search) was silently discarded. Wrapping it in the marker means it no longer starts with/, so it survives and is delivered.Approach: add one shared helper next to the existing steer helpers and route both consumers through it, rather than duplicating the wrap at each call site.
Related Issue
Fixes #60543
Type of Change
Changes Made
agent/agent_runtime_helpers.py— addformat_leftover_steer_for_delivery()(format_steer_marker(text).strip(); the marker is the whole standalone message here, so the append-oriented leading newlines are stripped) and export it.cli.py— CLI REPL leftover handler now deliversformat_leftover_steer_for_delivery(_leftover_steer)instead of the raw text.gateway/run.py— gateway leftover handler (TUI / Telegram / Slack / WhatsApp) routed through the same helper.tests/run_agent/test_steer_leftover_marker.py— new regression suite (6 cases).How to Test
/steer "..."so it lands after the final tool batch (the leftover window).[OUT-OF-BAND USER MESSAGE], not as raw/steertext — and that a steer beginning with/is delivered rather than silently dropped.Automated:
tests/run_agent/test_steer_leftover_marker.pycovers both delivery paths, the marker contract, and the gateway slash-command net. Each assertion was confirmed to fail against the pre-fix raw passthrough (red → green).Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass — CI Python tests green on Linux (amd64 + arm64); targeted steer/finalizer/gateway suites (52) pass locally on macOS.Documentation & Housekeeping
docs/, docstrings) — new helper is documented via docstring; no user-facing docs affected — or N/Acli-config.yaml.example)CONTRIBUTING.md/AGENTS.md)Screenshots / Logs
tests/run_agent/test_steer_leftover_marker.py— 6 passed. Fullpytest tests/ -qresult noted in the checklist above.