Skip to content

fix(opencode): optionally pass the prompt to opencode run verbatim - #4284

Open
i-vainn wants to merge 7 commits into
NVIDIA-NeMo:mainfrom
i-vainn:fix/opencode-verbatim-prompt
Open

i-vainn wants to merge 7 commits into
NVIDIA-NeMo:mainfrom
i-vainn:fix/opencode-verbatim-prompt

Conversation

@i-vainn

@i-vainn i-vainn commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

opencode_sandboxed_agent and the local CLI path of opencode_agent pass the task prompt as the last opencode run argument. opencode run wraps any argument containing a space in double quotes and escapes inner quotes, so the model sees "<prompt>", with every " as \", instead of the task prompt. Upstream report: anomalyco/opencode#43923, closed as not planned on 2026-10-11 in OpenCode's v1 issue triage; the proposed upstream fix (anomalyco/opencode#50245) was closed unmerged. Gym pins OpenCode 1.17.11, so this will not be fixed upstream for Gym's version.

This adds an opt-in verbatim_prompt flag. When enabled, the prompt goes to opencode run on stdin with no message argument, which OpenCode uses unchanged:

  • opencode_sandboxed_agent uploads the prompt to the sandbox and redirects it into opencode run.
  • opencode_agent (local CLI path) writes it to the subprocess's stdin.

opencode_agent sandbox sessions (#3639) already send the prompt on stdin, so the flag does not apply there; with the flag on, the other two paths match them.

Example (OpenCode 1.17.11):

dataset prompt:            … by running `python3 -c "import primesieve"`. If it …
model sees (default):      "… by running `python3 -c \"import primesieve\"`. If it … 10^7$?"
model sees (flag enabled): identical to the dataset prompt

Compatibility

  • Off by default: the launched command is unchanged and existing tests pass as is.
  • Enabling it changes the model's input, so results are not strictly comparable with earlier runs. Prompts containing quotes (most SWE-style tasks) change the most; others only lose the outer quotes. On the benchmarks we measured (below, including SWE-bench Pro), the score change was within noise.
  • Happy to make stdin the default instead (as the sandbox-session path already does) if maintainers prefer; kept opt-in here so existing baselines are untouched.

Validation

Rebased on 57cfd5140.

Unit tests

  • opencode_agent: 394 passed, 2 skipped. opencode_sandboxed_agent: 64 passed, 1 failed (test_required_mcp_extension, which needs Node >= 20; it fails identically on unmodified main with Node 18).
  • New tests (one per adapter, parametrized on the flag) run the real launch path against a stand-in opencode that records its arguments and stdin, with a prompt containing quotes, $, a newline and a leading --. Flag off: the prompt is the final argument (unchanged). Flag on: it arrives byte-exact on stdin with no message argument. The flag-on cases fail with the fix reverted.
  • pre-commit run on changed files: passed.

Live, after the rebase (inference-api.nvidia.com, OpenCode 1.17.11, recording proxy between Gym and the endpoint, comparing the first user message the endpoint received with the dataset prompt):

Adapter Model Flag off: prompt altered Flag on: prompt altered Rollouts correct
opencode_sandboxed_agent (Docker sandbox, 3 tool-use tasks with quotes in the prompt) Kimi K3 3/3 0/3 6/6
opencode_sandboxed_agent (same) Qwen 3.8 27B 3/3 0/3 6/6
opencode_agent local CLI (real _run_opencode, OpenCode in a container) Qwen 3.8 27B 1/1 ("Solve … \"import primesieve\" …") 0/1 (exact) —

Benchmark A/B, before the rebase (2026-10-09/12, PR commit cherry-picked onto Gym 6fa86e50, or backported onto 1e668906 for SWE-bench Pro; Super 3.5 checkpoint, OpenCode sandboxed benchmarks, only the prompts that contain ", 4 repeats per arm). We checked on the cluster that flag off delivers the wrapped, escaped prompt and flag on delivers it verbatim. Paired on − off, with 95% CI:

Benchmark Prompts Off On On − off
HLE 252 19.6 20.3 +0.7 [−1.3, +2.7]
HLE + search 252 28.6 27.0 −1.6 [−3.9, +0.7]
HLE-Verified 144 43.6 43.2 −0.3 [−3.3, +2.4]
HLE-Verified + search 144 46.7 48.6 +1.9 [−1.7, +5.7]
GPQA 7 85.7 85.7 0.0
APEX Shortlist 1 100.0 100.0 0.0
SWE-bench Pro 522 50.0 49.9 −0.1 [−1.8, +1.6]

No measurable effect on any of them; the reasoning flag-off arms reproduce the earlier OpenCode baselines within about 1 point. 6 of 6,392 reasoning rollouts were lost to sandbox failures, unrelated to the flag. On SWE-bench Pro, 8 of 4,176 rollouts did not finish within the 4-hour job limit, which moves either arm by at most 0.3 points; 153 tasks scored differently between the arms (77 better with the flag on, 76 worse).

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@i-vainn
i-vainn marked this pull request as ready for review October 9, 2026 09:48
@yaoyu-33 yaoyu-33 added area:agent Agent harnesses and Responses API agent behavior bug Something isn't working complexity:medium Single-domain change with interacting parts or a moderate review surface needs-review PR is ready for code review and waiting on a reviewer labels Oct 9, 2026
@zyzhou5

zyzhou5 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@i-vainn Could you rebase onto main and add validation notes showing how you tested verbatim_prompt with OpenCode?

@zyzhou5 zyzhou5 added waiting-on-customer Waiting on the original author to respond needs-review PR is ready for code review and waiting on a reviewer and removed needs-review PR is ready for code review and waiting on a reviewer labels Oct 9, 2026
@i-vainn
i-vainn force-pushed the fix/opencode-verbatim-prompt branch from 5810173 to 459fb3f Compare October 12, 2026 07:21
@i-vainn

i-vainn commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

@zyzhou5 Rebased onto main (2d6170d46) and added a Validation section to the description: unit tests, live checks after the rebase for both adapters (Kimi K3 and Qwen 3.8 27B through a recording proxy, flag off vs on), and a pre-rebase benchmark A/B on the OpenCode reasoning benchmarks. Since #3639, opencode_agent sandbox sessions already send the prompt on stdin, so on that adapter the flag now applies only to the local CLI path; the field description and README say so.

@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 12, 2026
`opencode run` wraps every message argument that contains a space in
double quotes and escapes inner quotes (anomalyco/opencode#43923), so
opencode_sandboxed_agent and the local CLI path of opencode_agent deliver
`"<prompt>"`, with each `"` as `\"`, instead of the task prompt. A new
`verbatim_prompt` flag on both sends the prompt on stdin instead, which
`opencode run` uses unchanged, as opencode_agent sandbox sessions already
do. It defaults to false, leaving the launched command and every existing
workflow exactly as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: i-vainn <[email protected]>
@i-vainn
i-vainn force-pushed the fix/opencode-verbatim-prompt branch from 459fb3f to 129b3ae Compare October 13, 2026 07:31
@yaoyu-33 yaoyu-33 removed the needs-review PR is ready for code review and waiting on a reviewer label Oct 13, 2026
@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 129b3ae

@cmunley1

Copy link
Copy Markdown
Contributor

/review

cmunley1
cmunley1 previously approved these changes Oct 15, 2026
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 15, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOLD — one RISK: staged prompts can be unreadable in non-root Docker sandboxes.

Reviewed all six changed files and traced prompt delivery, sandbox uploads, and session routing. Static review only; tests and live rollouts were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex

i-vainn and others added 2 commits October 16, 2026 05:55
…andbox users

write_text() creates the staged prompt with mode 0600 under a restrictive
umask, and the Docker uploader copies it as root without adjusting the mode,
so a non-root execution user got 'Permission denied' on the stdin redirect.
chmod it to 0644 before upload and cover it with a umask(077) test.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: i-vainn <[email protected]>
(cherry picked from commit 4c67f25e0e41ecdda6933faac3135f85f37f508c)
Signed-off-by: i-vainn <[email protected]>

# Conflicts:
#	responses_api_agents/opencode_agent/app.py
#	responses_api_agents/opencode_agent/tests/test_app.py
@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 8456ab1

@oyilmaz-nvidia

Copy link
Copy Markdown
Contributor

@i-vainn can you please address the svcnvidia-nemo-ci comments as well?

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Oct 21, 2026
@i-vainn

i-vainn commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @oyilmaz-nvidia, the bot's finding was addressed in 7fe9303 (see the reply in its thread). Could you re-run CI on the new head (/ok to test 0705e055d) and re-review?

@oyilmaz-nvidia

Copy link
Copy Markdown
Contributor

/review

… opened and refuse blank prompts

The staged prompt file stayed in /tmp for the sandbox's lifetime, and with the
local provider that is the host's shared /tmp. The launch command now opens the
file for stdin and removes it before OpenCode starts, best effort and
independent of OpenCode's exit status. A whitespace-only prompt, which OpenCode
rejects on stdin, is refused up front when verbatim_prompt is on. Tests cover
padded prompts, a failing OpenCode, cleanup, and the blank-prompt refusal.

Signed-off-by: i-vainn <[email protected]>
@i-vainn

i-vainn commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @oyilmaz-nvidia! Pushed a follow-up (7389970).

  • (a) The launch now deletes the staged prompt as soon as it's opened for stdin, so it's gone before the model starts. I kept 0644 because Docker uploads are root-owned, so 0600 would break non-root sandboxes.
  • (b) I checked OpenCode 1.17.11: it reads stdin untrimmed and only rejects blank input, so whitespace-only prompts are now refused up front. Tests cover both.

Not run: a real non-root Docker rollout. New head needs /ok to test 738997041 for CI.

@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 7389970

@cmunley1

Copy link
Copy Markdown
Contributor

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP — the prior permissions finding is resolved; no new findings meet the follow-up escalation threshold.

The staging code now sets mode 0644 before upload, addressing the reported restrictive-umask/non-root Docker failure without changing prompt bytes. The regression assertions cover umask 077, staged permissions, and exact UTF-8 contents.

Compared current source with the previously reviewed head and inspected subsequent cleanup, blank-prompt validation, tests/documentation, and affected local timeout/session paths. Applied the follow-up policy: unresolved prior findings remain eligible; new regressions must exceed the historical moderate-impact ceiling.

Static review only. Tests and live rollouts, including non-root Docker execution, were not run.

Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.

@cmunley1

cmunley1 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@i-vainn could you merge main? It conflicts now, and I'd like to approve once it's green.

@athitten

Copy link
Copy Markdown
Contributor

@i-vainn could you please resolve the merge conflicts for this PR and re-start the CI ? Thanks

This branch was previously deployed

1 inactive deployment
public — 73899704 Deployed Oct 30, 2026 by copy-pr-bot[bot] via release / finalize / notify #8847
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior bug Something isn't working complexity:medium Single-domain change with interacting parts or a moderate review surface sla:review-overdue Review response is over the one-business-day SLA waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants