Skip to content

fix(token-id-capture): match a tool call OpenCode rewrote as unavailable - #4936

Draft
pthombre wants to merge 1 commit into
pthombre/partial-ckpt-sandbox-snapshot-retryfrom
pthombre/lineage-renamed-tool-call
Draft

pthombre wants to merge 1 commit into
pthombre/partial-ckpt-sandbox-snapshot-retryfrom
pthombre/lineage-renamed-tool-call

Conversation

@pthombre

@pthombre pthombre commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

OpenCode echoes a model call to a tool it does not have as a call to its own invalid tool. It keeps the call ID and moves the original name into the arguments as {"tool": <name>, "error": <message>}. #4014's tool-call-turn key tolerates rewritten arguments but keeps tool names, so the echo stopped matching the served call. The next request then had no parent (Unresolved parent … poisoning the call), and because a poisoned call can never be a parent, every later call of the rollout was poisoned too.

Observed in two OpenCode SWE runs on this stack:

  • 16-node full-SWE run: the model called mkdir; 47 calls of that rollout were poisoned.
  • 32-node checkpoint-restore run: the model called globals; the last 8 calls of that rollout were poisoned. This was the run's only rewrite in about 15,750 tool calls, and the run's only unresolved-parent rollout.

tool_call_turn_fingerprint now hashes the name the model emitted when the echoed call has exactly that shape: the name is invalid and the arguments are a JSON object with exactly the keys tool (a non-empty string) and error. Everything else is unchanged.

Safety:

  • Tool names still have to match. The original name is restored, not ignored, so two responses that share per-response tool IDs (for example call_0) but call different tools stay apart. The only newly accepted match is one feat(token-id-capture): resolve parent and terminal call by tool-call ids #4014 already accepts: same ID and same name, different arguments.
  • Other shapes are untouched. Extra keys, a missing or empty tool, non-JSON arguments, or a different name keep their name and stay unresolved, as before.
  • Final-call selection benefits too. terminal.py uses the same key, so a final turn containing a rewritten call is now attributed as well.

This does not address the post-resume duplicate requests (two calls continuing the same parent) seen after a park where harness launches could not be paused. That is a separate issue.

No issue filed: the root cause and fix are described here.

Validation

  • Ran pytest tests/unit_tests/test_tool_call_turn_fallback.py tests/unit_tests/test_tool_call_turn_lineage_store.py tests/unit_tests/test_conversation_fingerprint.py tests/unit_tests/test_token_id_capture.py tests/unit_tests/test_terminal_attribution.py tests/unit_tests/test_token_capture_*.py: 819 passed.
  • Added 24 tests, all passing:
    • the rewrite resolves to the served call in the Responses and Chat formats, through record, add_entry and terminal attribution, and through all four lineage stores (local and custody, file and in-memory);
    • two t1 responses calling mkdir and bash stay distinguishable;
    • the non-matching shapes listed above stay unresolved.
  • Reverted the fix and reran the new tests: the 11 tests that expect a match fail, and the 13 that expect a rejection still pass.
  • On the current head (7b31f9a93, replayed with the stack below it): 1379 passed and 0 failed at the top of the stack in the rl-gym.nightly container on Slurm (job 8281677).
  • ruff check and ruff format --check pass on the changed files. pre-commit run has not been run yet (the authoring environment could not download the hook repos); it will be run before this leaves draft.

Rollouts

The stack with this fix ran in six 16-node full-SWE GRPO jobs: OpenCode on 5 SWE routes, 2,048 rollouts in flight, about 10 h in total. Unresolved-parent warnings:

Job Poisoned calls Cause
8205027 1, in 1 rollout before any checkpoint; not determined
8208396 212, in 5 rollouts each rollout's harness pause had failed, and its relaunch repeated requests (fixed in #4274)
8213273 32, in 1 rollout the same: its pause was killed at the command budget
8216755, 8243255, 8270615 0
  • The 16-node run before this fix (job 8143368) had 47 poisoned calls in the rollout where OpenCode rewrote mkdir, besides about 1,500 after failed pauses.
  • No poisoning in these runs began at an invalid rewrite. Whether the model called an unavailable tool in them is not known, though: neither OpenCode's rewrite nor this fix's match is logged, and the rewrite came about once per 15,000 tool calls before. These runs show no regression; they do not show the fix exercised.
  • The tests use the rewritten call exactly as it appears in the OpenCode session export ({"tool": "globals", "error": "Model tried to call unavailable tool 'globals'. Available tools: …"}). Before this leaves draft, an OpenCode rollout that triggers an unavailable tool still needs to be checked for a tool_call_turn resolution and no unresolved-parent warnings.

Compatibility and benchmark impact

  • Ledgers and checkpoints: none. Stored keys are computed from served responses, which never contain OpenCode's rewrite, so existing ledger rows and checkpoint snapshots keep their keys. No fingerprint version bump is needed.
  • Training data: rollouts that hit an unavailable tool are no longer masked from that call onward, so more of their calls reach training.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification. (N/A: internal matching behavior, described in the function docstrings.)
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header. (No new files.)
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

@pthombre
pthombre added this pull request to stack #4696 October 22, 2026 18:37
@copy-pr-bot

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

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:agent Agent harnesses and Responses API agent behavior bug Something isn't working labels Oct 22, 2026
@pthombre
pthombre force-pushed the pthombre/lineage-renamed-tool-call branch from 4303db9 to e6bd457 Compare October 25, 2026 02:47
OpenCode echoes a model call to a tool it lacks as a call to its own `invalid`
tool: it keeps the call ID and moves the original name into the arguments as
{"tool": <name>, "error": <message>}. #4014's tool-call-turn key ignores
rewritten arguments but keeps tool names, so the echo no longer matched the
served call, the next request had no parent, and every later call of the
rollout was poisoned (47 calls in one rollout of a 16-node full-SWE run, 8 in
one of the 32-node restore run).

The key now hashes the name the model emitted when the echo has exactly that
shape. Names still have to match, so two responses that share per-response
tool IDs but call different tools stay apart, and any other shape keeps its
name and stays unresolved as before. Recorded keys hash served responses,
which never carry the rewrite, so existing ledgers and checkpoints are
unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Thombre <[email protected]>

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

area:agent Agent harnesses and Responses API agent behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants