Skip to content

docs(tutorials): add black-box coding agent training tutorial (OpenCode + AsyncGRPO) - #1027

Closed
sergiopaniego wants to merge 1 commit into
mainfrom
feature/docs-opencode-harness-recipe
Closed

docs(tutorials): add black-box coding agent training tutorial (OpenCode + AsyncGRPO)#1027
sergiopaniego wants to merge 1 commit into
mainfrom
feature/docs-opencode-harness-recipe

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

Adds a tutorial page for the black-box (loop-owning) training path: training the real OpenCode agent with TRL's experimental AsyncGRPOTrainer and the opencode_env transparent interception proxy. The recipe itself lives in TRL (docs section plus examples/scripts/openenv/opencode.py), so this page explains when to use the pattern, how the pieces fit, and links out. It also adds the row to the tutorials index and the toctree entry.

Until now this recipe was not discoverable from OpenEnv docs at all: the BrowserGym harness tutorial covers the white-box pattern where the trainer keeps sampling, and nothing pointed at the black-box path.

This is the index/discoverability piece discussed in RFC #924 (GRPO harness training recipes): recipes live in each framework's repo, OpenEnv curates the index.

Type of Change

  • Documentation

Alignment Checklist

  • I have read .claude/docs/PRINCIPLES.md and this PR aligns with our principles
  • I have checked .claude/docs/INVARIANTS.md and no invariants are violated
  • I have run /pre-submit-pr (or bash .claude/hooks/lint.sh and tests) and addressed all issues

RFC Status

Test Plan

  • _toctree.yml parses (yaml.safe_load) and the new entry mirrors the existing tutorial entries.
  • Docs-only change, no code paths touched.
  • Links point at TRL main (docs/trl/openenv harness section, examples/scripts/openenv/opencode.py) and envs/opencode_env, all verified to exist.

Claude Code Review

N/A (docs-only)


Note

Low Risk
Documentation-only changes with no runtime or API impact.

Overview
Adds discoverability for the black-box GRPO path where the production OpenCode agent keeps its own tool loop and TRL trains from captured traces.

A new tutorial page (opencode-agent-grpo.md) explains when to use this pattern versus Wordle-style reset()/step() GRPO and the white-box BrowserGym harness, walks through the flow (OpenCodeSessionFactory transparent proxy → trace → HarnessRolloutWorkerAsyncGRPOTrainer with NCCL weight sync), and points to TRL’s runnable recipe plus opencode_env. The tutorials overview table and _toctree.yml gain a Training a Real Coding Agent entry (GPU required, no Colab notebook).

Reviewed by Cursor Bugbot for commit 98d20fb. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI review requested due to automatic review settings July 31, 2026 10:11

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sergiopaniego
sergiopaniego deleted the feature/docs-opencode-harness-recipe branch July 31, 2026 10:11
@burtenshaw burtenshaw added documentation Improvements or additions to documentation size: small Small pull request labels Jul 31, 2026 — with Cursor
@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Alignment Review Report

Two-tier alignment-review of this docs-only PR (3 files, +87): a new OpenCode + AsyncGRPO tutorial plus its _toctree.yml / index.md registration.

Automated Checks

  • Lint: PASS (N/A to this diff). The PR changes only Markdown/YAML (0 Python files). bash .claude/hooks/lint.sh (ruff/usort, Python-only) exits non-zero solely on ~21 pre-existing envs/**/*.py reformat candidates (chat_env, coding_tools_env, opencode_env, repl_env, …) — none are in this diff. (uv isn't preinstalled on the review VM; I installed it to run the hook.)
  • Debug code: CLEAN. check-debug.sh scans only src/ and reports pre-existing console.print/TODO items in cli/…, unrelated to this PR. The new docs contain none.

Open RFCs Context

  • RFC 005 — Agentic Harness Integration (In Review): directly relevant; this tutorial teaches the harness / black-box training path. See RFC flag below.
  • RFC 010 — ECHO env-token world modeling (Draft): tangentially related (token-role masking / "which turns receive gradient"), but not in conflict — the tutorial uses standard agent-token masking. Noted for context only; cc @thegovind if relevant.
  • RFCs 000–004 are also "In Review" but foundational; no interaction with a docs-only tutorial.

Tier 1: Fixes Required

None. The page and its registration are well-formed and technically accurate:

  • _toctree.yml + tutorials/index.md are updated consistently (same title/link, placed between BrowserGym and SFT).
  • > [!NOTE] admonition and .md cross-links match existing tutorial conventions.
  • OpenEnv-side claims verified against the code: OpenCodeSessionFactory + mode="transparent_proxy" (envs/opencode_env/harness.py); the in-sandbox proxy capturing per-turn completion_token_ids + per_token_logps (fetch_proxy_trace, sandbox/interception.py); the held-out OpenCodeSession.verify() (list_tools() returns []); the pip package openenv-opencode-env + subdirectory; and the white-box/black-box framing (run_white_box / run_black_box).

Tier 2: Alignment Discussion

Principle Conflicts

None identified — the taught design is aligned:

  • Rewards in environment: reward is the session's held-out verify(); openenv.core.harness enforces that verify only forwards the env-produced reward (_resolve_env_reward raises otherwise).
  • Agent isolation / agents-cannot-reset: reset/step/state/close are reserved and never exposed to the harness; the agent owns only its own tool loop.

RFC Conflicts

ALIGNMENT FLAG: Tutorial publishes an experimental, RFC-005-pending harness API as a first-class recipe

  • Principle/RFC at stake: RFC 005 (Agentic Harness Integration) — In Review
  • The concern: the page documents the shipped openenv.core.harness runtime (ResourceSession / ResourceSessionFactory + run_white_box / run_black_box, used by OpenCodeSessionFactory). That module's own docstring says it lives "outside the stable openenv.core package surface while RFC 005 is still under review", and the shipped design has diverged from RFC 005's proposed HarnessConfig + HarnessAdapter (start/stop/inject_tools/send_message) + HarnessEnvironment(MCPEnvironment) per-turn-step() model. This PR does not introduce the divergence (it documents already-merged code), but two things merit a maintainer decision: (1) reconcile RFC 005 with the shipped ResourceSession / white-box / black-box design (the RFC reads stale); (2) optionally add a one-line "experimental / unstable API" caveat for the OpenEnv side — the page already flags TRL's AsyncGRPOTrainer as experimental, but not openenv.core.harness.
  • Suggested reviewer: @Darktex (RFC 005 author); cc @sergiopaniego (PR author, also a committer on RFC 005)

Summary

  • 0 mechanical issues to fix
  • 1 alignment point for human review (RFC 005 reconciliation + optional experimental-API caveat)
  • 0 hard RFC conflicts (RFC 010 noted as non-conflicting context)

Overall a clean, accurate, well-scoped docs PR. The only discussion item is that it surfaces an RFC-005-pending experimental API as a first-class tutorial — worth a maintainer note, not blocking.

Open in Web View Automation 

Sent by Cursor Automation: Pre-review

The full recipe lives in TRL. The moving pieces:

1. Each rollout runs the agent inside an OpenEnv session created by
`OpenCodeSessionFactory` from

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ALIGNMENT FLAG (Tier 2, non-blocking) — RFC 005 (Agentic Harness Integration, In Review).

This page documents the shipped openenv.core.harness runtime: OpenCodeSessionFactoryResourceSessionrun_white_box/run_black_boxverify(). That module's own docstring notes it lives "outside the stable openenv.core package surface while RFC 005 is still under review," and the shipped design has diverged from RFC 005's proposed HarnessConfig + HarnessAdapter (start/stop/inject_tools/send_message) + HarnessEnvironment(MCPEnvironment) per-turn-step() abstraction.

Not introduced by this PR (it documents already-merged code), but worth: (a) reconciling RFC 005 with the shipped ResourceSession design, and (b) optionally adding a one-line "experimental API" caveat here — the page already flags TRL's AsyncGRPOTrainer as experimental, but not the OpenEnv side. cc @Darktex (RFC 005 author), @sergiopaniego.

turn's token ids and logprobs to a trace.
2. When the agent stops, TRL's `HarnessRolloutWorker` reads the trace, rebuilds
the per-turn training rows from the recorded ids, and scores the final
workspace with the session's `verify()` method (a held-out verifier the

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well-aligned with the rewards-in-environment invariant: reward comes from the session's held-out verify(), and openenv.core.harness enforces it — VerifyResult.env_reward "must forward reward already produced inside the environment ... must not synthesize a new reward in the orchestration layer" and _resolve_env_reward raises if verify returns a mismatched reward. The agent also sees no orchestration tools (OpenCodeSession.list_tools() returns []). Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size: small Small pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants