Skip to content

feat: Switchyard OpenCode integration#2080

Open
drifold wants to merge 3 commits into
NVIDIA-NeMo:feature/switchyard-openhands-integrationfrom
drifold:switchyard-opencode-integration
Open

feat: Switchyard OpenCode integration#2080
drifold wants to merge 3 commits into
NVIDIA-NeMo:feature/switchyard-openhands-integrationfrom
drifold:switchyard-opencode-integration

Conversation

@drifold

@drifold drifold commented Jul 20, 2026

Copy link
Copy Markdown

Stacked on #2026 (base: feature/switchyard-openhands-integration). Adds upstream opencode as a second harness for the Switchyard token-capture integration — same zero-fork principle as the OpenHands path.

What

  • Runs opencode headless (opencode run) with an opencode.json provider pointed at Switchyard — no fork, no harness modification.
  • Captures the session tree through opencode's own correlation headers: a distinct X-Session-Id per (sub)agent session, x-parent-session-id linking subagents to the root.
  • Reconstructs the root session as the main rollout and subagent sessions as token-annotated subagent_trajectories.

Zero-fork architecture

  • The opencode.json provider id is deliberately not opencode-prefixed — opencode only emits its native correlation headers for non-opencode providers; those headers are the whole capture contract.
  • Gym mints no session ids here: opencode's own ids are discovered post-run from Switchyard's GET /v1/sessions (no harness logs read).
  • Title-generator side-calls (same session id, different conversation) are filtered before reconstruction.

Activation and safety

swe_agents:
  responses_api_agents:
    swe_agents:
      agent_framework: opencode
      opencode_source: opencode        # default remains "nv-opencode"
      switchyard_base_url: http://<host>:<port>
condition behavior
opencode_source absent / nv-opencode byte-identical to the existing fork path
enabled, capture healthy root + subagents reconstructed with exact token ids
retrieval/reconstruction failure rollout kept, mask_sample: true, switchyard_trace_error set

Changes

  • responses_api_agents/swe_agents/app.pyopencode_source config, _opencode_switchyard_config (provider JSON), the opencode run command, _list_switchyard_sessions / _reconstruct_switchyard_sessions, title-gen filtering, task_id steering via system-prompt instructions (works around an opencode task-tool crash on model-invented task_ids; upstream fix being filed).
  • nemo_gym/switchyard_trace.py — canonicalize tool-call arguments for the history-extension comparison only (opencode re-serializes compact vs. pretty-printed JSON across turns); reconstructed items keep the model's original arguments.
  • Tests: 8 new test classes across test_app.py and test_switchyard_trace.py.

Dependencies

Requires the Switchyard side on NVIDIA-NeMo/Switchyard#63: 7b33c2c (native X-Session-Id capture), be0b2c5 (parent session id + GET /v1/sessions).

Testing

  • 225 passed across the swe_agents and switchyard_trace suites.
  • Cluster E2E (vLLM 0.11.0, Qwen3): root + subagent sessions captured via native headers, both reconstruct with exact token fidelity, 0% masked.

🤖 Generated with Claude Code

drifold and others added 3 commits July 20, 2026 15:00
Adds opencode_source='opencode': runs upstream opencode headless with an
opencode.json provider pointed at Switchyard (no fork), captures the
session tree via opencode's native correlation headers
(X-Session-Id / x-parent-session-id), and reconstructs root and subagent
rollouts from the retrieved sessions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: drifold <drifold@nvidia.com>
…mparison

OpenCode re-serializes tool-call arguments differently across turns (compact vs. pretty-printed JSON), which failed the message-history extension check even though the tokens were contiguous. Canonicalize arguments for the comparison only; reconstructed training items keep the model's original arguments.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: drifold <drifold@nvidia.com>
…system-prompt instructions

Signed-off-by: drifold <drifold@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 20, 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.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request Issue reported or requested by someone from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant