Skip to content

Preserve interrupted OpenCode tool outcomes - #5198

Merged
yaoyu-33 merged 1 commit into
mainfrom
flafrance/opencode-tool-outcomes
Oct 29, 2026
Merged

yaoyu-33 merged 1 commit into
mainfrom
flafrance/opencode-tool-outcomes

Conversation

@lafrancef

@lafrancef lafrancef commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

OpenCode shell timeouts and aborts can appear as completed or unknown tools, and interrupted tools can lose their partial output. Interpret native tool outcomes consistently across both OpenCode adapters, preserve partial output and compaction markers, and propagate invocation cancellation or timeout to tools left running.

Interrupted task tools retain their precise outcome while child invocation fallbacks use the valid incomplete status. Native child completion evidence takes precedence.

Representative real-model checks cover ordinary commands, shell timeouts with partial output, and active-tool cancellation in both adapters using OpenCode 1.17.11 and gpt-5.5. A separate legacy whole-invocation timeout yielded no exported tool evidence and is excluded from interrupted-tool qualification.

@copy-pr-bot

copy-pr-bot Bot commented Oct 28, 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.

@lafrancef

Copy link
Copy Markdown
Contributor Author

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:agent Agent harnesses and Responses API agent behavior bug Something isn't working labels Oct 28, 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.

SHIP WITH CARE

One correctness RISK: an interrupted task can invalidate the entire observation bundle, as detailed inline.

RISK — Record representative real smoke-rollout validation. The supplied PR description contains no validation results or rollout evidence. Trusted AGENTS.md requires representative real model rollouts for behavior-changing agent work and requires recording that evidence. The added tests construct persisted states; they do not establish what the installed OpenCode runtime actually records.

Could you run representative model-backed smoke rollouts through both affected adapters and record the commands/configuration, OpenCode version, and inspected results? Include interrupted shell execution with partial output, invocation cancellation/timeout, and an ordinary successful tool. Compare native artifacts with normalized outcomes/output and inspect the resulting agent/verifier behavior. Preserve integer-exit handling, native terminal outcomes, and the compacted-output marker. Acceptance: recorded results demonstrate correct stop attribution and retained partial output without altering ordinary tool results or verifier behavior. This is a validation-evidence request, not a claim that those runs failed.

Completed static inspection of all six changed files and their directly affected parsing, lifecycle, observation-schema, and regression-test paths. No tests or rollouts were executed in this read-only review.


Inline comments (escaped v1):

  • responses_api_agents/opencode_agent/artifacts.py line 304: RISK — Normalize tool outcomes before using them as invocation statuses

    Failure: Given root/child session rows, a child containing only its user message, and a root task tool with:

    {"status":"error","error":"Tool execution aborted","metadata":{"interrupted":true,"sessionId":"child","output":"partial"}}

    the new helper returns status="cancelled". This assignment copies it into child_status, and the invocation fallback passes it into AgentInvocation.status. That contract permits only completed/failed/incomplete/unknown, so validation rejects the entire bundle instead of preserving the interrupted task and child. The capture handler then replaces valid transcript/tool evidence with capture-failure gaps. The sibling assignment has the same problem. Before this change, the errored task supplied the valid fallback failed.

    Correction: Could you replace this assignment and its sibling with the following, verifying it before adoption?

                    child_status[child_id] = {"timeout": "incomplete", "cancelled": "incomplete"}.get(status, status)
    

    The invariant is that tool observations keep their precise outcomes while invocation fallbacks satisfy the narrower invocation-status contract.

    Preservation: Keep the parent tool cancelled/tool_aborted with output partial; do not normalize the tool observation itself. Leave completed, failed, incomplete, and unknown fallbacks unchanged. Preserve the existing precedence of a child's own message-derived outcome over its parent-tool fallback.

    Acceptance — proposed tests, not executed: Parameterize both parsers with the root/child setup above. Assert parsing succeeds, the child invocation is incomplete, and the parent tool remains cancelled/tool_aborted with output partial. Also assert ordinary error→failed, completed→completed, and running/pending→incomplete fallbacks; a child with its own completed assistant message must retain its message-derived status. Retain the existing interrupted-output assertions in test_interrupted_tools_keep_only_the_output_opencode_recorded; its root-only setup does not exercise this fallback.

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

@lafrancef
lafrancef force-pushed the flafrance/opencode-tool-outcomes branch from 6df5215 to 75b763d Compare October 28, 2026 19:16
@lafrancef

Copy link
Copy Markdown
Contributor Author

The child-invocation fallback now maps cancelled and timeout tool outcomes to incomplete, which is valid for AgentInvocation. The parent tool retains its precise outcome, error and partial output; a child’s own assistant messages still take precedence. Both parsers are covered across seven fallback outcomes, with and without child completion evidence.

Fresh model-backed acceptance used OpenCode 1.17.11 and gpt-5.5 on this source. Both adapters executed an ordinary shell command and a shell command with a 1,000 ms timeout. Native artifacts showed completed/exit-zero for the ordinary command and completed/null-exit plus a timeout trailer for the interrupted command; normalized results were completed and timeout/tool_timeout respectively, with partial stdout preserved. The legacy adapter’s verifier received both results and returned an unmasked reward. Its explicit caller-cancellation case preserved a running tool’s partial stdout as incomplete, propagated cancellation, and never invoked the verifier.

Native session cancellation was also exercised after a real long-running shell started: its retained native database showed the running tool and partial stdout; session close reported the tool as cancelled/invocation_cancelled and the invocation as incomplete, with cleanup confirmed. The native fixture exercises session APIs directly and does not fabricate verifier results. All successful cases stopped their owned sandbox and revoked their dependency lease.

The legacy whole-invocation timeout attempt produced no exported tool evidence, so it is not counted as interrupted-tool qualification. Pre-model fixture startup failures are also excluded from the successful evidence. This is targeted adapter acceptance, not full-benchmark qualification.

@lafrancef

Copy link
Copy Markdown
Contributor Author

/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

LGTM — no remaining eligible concerns in this follow-up.

  • The prior child-invocation validation failure is fixed in both artifact parsing and the sandboxed adapter. Cancelled/timeout tool outcomes map to incomplete only for invocation fallbacks; precise parent-tool outcomes, partial output, and child-message precedence remain intact. The regression cases assert those behaviors across both parsers.
  • The author-reported model-backed checks address the earlier missing-validation-evidence finding, covering ordinary commands, shell timeouts with partial output, cancellation, verifier behavior, and cleanup. Their stated qualification limits are explicit.

Completed the scoped follow-up and directly affected contract checks, not a fresh whole-PR review. The previously reviewed tree was unavailable, limiting independent comparison of subsequent changes. No tests or rollouts were executed in this read-only review; runtime results remain author-reported.

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

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

@lafrancef
lafrancef marked this pull request as ready for review October 28, 2026 20:31
@lafrancef

Copy link
Copy Markdown
Contributor Author

/ok to test 75b763d

@github-actions

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 28, 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.

SHIP

LGTM — no remaining eligible concerns in this same-head follow-up.

  • The earlier child-invocation validation failure remains fixed in both artifact parsing and the sandboxed adapter. Cancelled/timeout outcomes become incomplete only for invocation fallbacks; parent-tool outcomes, errors, partial output, and child-completion precedence remain intact. The regression assertions cover both parsers and the neighboring fallback statuses.
  • The author-reported model-backed checks continue to address the earlier validation-evidence concern. They cover ordinary commands, shell timeouts with partial output, cancellation, verifier behavior, and cleanup, with qualification limits explicitly stated.

Completed the scoped verification and directly affected contract checks. The latest reviewed baseline equals the current head, so there are no subsequent changes eligible for new discovery; this is not a fresh whole-PR review. No tests or rollouts were executed in this read-only review; runtime results remain author-reported.

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

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

@yaoyu-33
yaoyu-33 enabled auto-merge October 28, 2026 22:03
@yaoyu-33 yaoyu-33 added Ready for QA ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Oct 28, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40816437888

Merged via the queue into main with commit 03f51b6 Oct 29, 2026
159 of 186 checks passed
@yaoyu-33
yaoyu-33 deleted the flafrance/opencode-tool-outcomes branch October 29, 2026 04:50

This branch was previously deployed

1 inactive deployment
public — 75b763dd Deployed Oct 28, 2026 by copy-pr-bot[bot] via release / finalize / notify #7920
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 Ready for QA ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants