Skip to content

fix(agent): keep pre-API /steer off prior-turn tool results - #107274

Open
KoNit-K wants to merge 2 commits into
NousResearch:mainfrom
KoNit-K:fix/steer-preapi-current-turn
Open

KoNit-K wants to merge 2 commits into
NousResearch:mainfrom
KoNit-K:fix/steer-preapi-current-turn

Conversation

@KoNit-K

@KoNit-K KoNit-K commented Sep 10, 2026 •

Copy link
Copy Markdown

What does this PR do?

Classic CLI sets _agent_running=True before chat() image preprocessing, so /steer during that window is acknowledged (Steer queued — arrives after the next tool call) and stored in _pending_steer.

On the first API iteration, prepare_iteration drained that slot and _inject_steer_after_newest_tool_result searched the full history for the newest role=tool row. If the current turn had not produced a tool result yet, a prior turn's tool row was selected and the steer was inserted before the current user message — historical context, not a correction to the active turn.

This PR restricts the pre-API inject floor to the current-turn user row (current_turn_user_idx). With no in-turn tool yet, the steer is requeued via _requeue_pending_steer for the existing post-tool drain. CLI _agent_running timing, _cmd_steer ack text, and apply_pending_steer_to_tool_results are unchanged.

Related Issue

Fixes #107272

Type of Change

  • ✅ Bug fix (non-breaking change that fixes an issue)

Changes Made

  • agent/turn_iteration_prep.py — only accepts rows with index strictly greater than the current-turn user floor; otherwise requeues. passes .
  • tests/agent/test_steer.py — regression for prior-turn tool + no in-turn tool (requeue, no insert before current user); CONTROL that an in-turn tool still gets a standalone steer user row after that tool, not the old one; production helper restash when there are no tools.

How to Test

  • scripts/run_tests.sh on the files in Changes Made — focused verification
  • HERMES_PYTHON=/path/to/venv/bin/python scripts/run_tests.sh tests/agent/test_steer.py
  • BEFORE (RED): test_pre_api_drain_does_not_attach_to_prior_turn_tool_result failed (TypeError: unexpected keyword argument 'current_turn_user_idx' on the unwired helper; the new floor is the behavior the test then asserts).
  • AFTER (GREEN): tests/agent/test_steer.py — 39 passed, 0 failed.
  • scripts/run_tests.sh tests/agent/test_steer.py
  • pytest RED→GREEN locally

Evidence

  • BEFORE: the focused probe was RED on origin/main before this change
  • AFTER: - [x] scripts/run_tests.sh on the files in Changes Made — focused verification — 39 passed
  • CONTROL: neighboring paths listed in How to Test still pass

Checklist

Code

  • ✅ I've read the Contributing Guide
  • ✅ My commit messages follow Conventional Commits
  • ✅ I searched for existing PRs to make sure this isn't a duplicate
  • ✅ My PR contains only changes related to this fix
  • ✅ I've run relevant tests locally (see How to Test)
  • ✅ I've added tests for my changes
  • ✅ I've tested on my platform: macOS

Documentation & Housekeeping

  • ✅ Documentation update: N/A unless noted in Changes Made
  • ✅ cli-config.yaml.example: N/A
  • ✅ CONTRIBUTING.md or AGENTS.md: N/A
  • ✅ Cross-platform impact considered
  • ✅ Tool descriptions/schemas: N/A

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Sep 10, 2026
The first-iteration drain searched all history for the newest tool
row, so a /steer accepted during image preprocessing landed before
the current user message whenever an earlier turn had tool output.

Co-authored-by: Cursor <cursoragent@cursor.com>

KoNit-K commented Oct 1, 2026

Copy link
Copy Markdown
Author

Synced to the current integration base in 4f2a0a6. Pre-API steer injection no longer attaches to a prior turn's tool result; it still attaches after an in-turn tool result and restashes when no current tool exists. Focused steer tests pass (35 tests). There are no unresolved review threads to resolve.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /steer sent during image preprocessing is acknowledged but ignored

2 participants