Repository navigation
fix(core): send max-steps message as user role, not assistant prefill - #34276
Anooshiravan wants to merge 2 commits into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: Related PR:
This PR appears to be related to the same problem area (step cap messages), though it takes a different solution approach. The current PR (#34276) fixes the issue by changing the message role from |
|
Independent confirmation this fix is correct and needed: hit this exact Data point that might help build a case for merging: searched our own This PR (and the V2 fix alongside it) also happens to fully address it — Given three PRs (#32546, this one, and the now-closed duplicate) have |
e2902b0 to
61785c0
Compare
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
When an agent hits its configured step cap, opencode appends a "MAXIMUM STEPS REACHED" notice to the request. It was sent with role "assistant", which providers treat as a response prefill — the model echoes the prefill (one stop token) instead of summarizing. On Claude with thinking enabled the request fails outright with HTTP 400. Flip the role to "user" so the model treats the notice as instructions and produces a real summary. Two sites fixed: - packages/opencode/src/session/prompt.ts:1280 (V1) - packages/core/src/session/runner/llm.ts:206 (V2) Fixes anomalyco#32548.
Add regression tests locking in the fix from the previous commit: - packages/opencode/test/session/prompt.test.ts: assert the V1 loop sends the MAXIMUM STEPS REACHED notice with role "user". - packages/core/test/session-runner.test.ts: update the existing V2 assertion (which locked in the buggy "assistant" role) to expect "user". Verified: - bun test test/session/prompt.test.ts (57 pass) - bun test test/session-runner.test.ts (80 pass) - bun turbo typecheck (29/29) V1 test borrowed from anomalyco#36970. Co-authored-by: rguliyev <rguliyev@users.noreply.github.com>
61785c0 to
b8bb822
Compare
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
|
@Anooshiravan any chance you're interested in re-opening this PR? |
|
@SConaway I'd reopen it if I could, but GitHub won't let me — it 422s from both the CLI and the REST API. A brand-new PR is the only option. I'm not keen on that. All three PRs against #32548 — #32546, #36970 and this one — were closed without a single maintainer comment. Mine got auto-closed by the template bot two hours after it flagged me. Refiling just restarts that clock. For what it's worth, the fix is still valid: both call sites on If a maintainer says they'll look, I'll open a fresh PR the same day. Until then anyone who needs it can cherry-pick from my branch. |
Issue for this PR
Closes #32548
Type of change
What does this PR do?
When an agent hits its step cap, opencode appends a "MAXIMUM STEPS REACHED" notice to the request with
role: "assistant". Providers treat a trailing assistant message as a prefill — something the model should continue, not instructions to follow. So instead of summarizing its work, the model just emits a stop token and the turn ends empty. On Claude with thinking enabled it's worse: the request 400s, because you can't prefill an assistant turn that's supposed to start with a thinking block.The notice is an instruction, so it belongs in a user message. Changing the role to
"user"makes the model read it as instructions and actually produce the summary.Two call sites, both changed:
packages/opencode/src/session/prompt.ts(V1)packages/core/src/session/runner/llm.ts(V2)How did you verify your code works?
packages/opencode/test/session/prompt.test.ts— addedloop sends max steps instruction as a user message. 57 pass.packages/core/test/session-runner.test.ts— the existingforces a text response on an agent's configured final steptest assertedrole: "assistant", which locked the bug in. Updated to"user". 80 pass.bun turbo typecheck— 29/29.Screenshots / recordings
Not a UI change.
Checklist
Related