Skip to content

fix(agents): stage activation files inside the close fence - #5862

Merged
ananthsub merged 4 commits into
mainfrom
ananthsub/opencode-session-staging
Nov 9, 2026
Merged

ananthsub merged 4 commits into
mainfrom
ananthsub/opencode-session-staging

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What changed

OpenCode, Pi and Codex now upload the files an activation needs inside stage_activation, which runs inside SandboxSession.execute. Before this change each uploaded some of these files in its response path, before execute.

  • OpenCode: the required-MCP plugin, mcp-grants.json and the empty mcp-status.json.
  • Pi: models.json, settings.json, its extensions, gym_mcp.mjs and mcp-servers.json.
  • Codex: home/.codex/config.toml. It stays out of input.json, which holds the whole payload.

Pi and Codex pass these files to execute through a new optional files argument. OpenCode passes its grants in the payload.

The SandboxSession docstring now says that every sandbox write an activation needs belongs in stage_activation, because close cannot stop a write made before execute.

flowchart TD
  subgraph before["Before"]
    b1["Response path uploads activation files"] --> b2["SandboxSession.execute"]
    b2 --> b3["stage_activation writes prompt.txt and params.sh"] --> b4["Harness launch"]
  end
  subgraph after["After"]
    a2["SandboxSession.execute: close fences staging"] --> a3["stage_activation uploads activation files,<br/>then prompt.txt and params.sh"] --> a4["Harness launch"]
  end
  b4 ~~~ a2
Loading

Why

SandboxSession.execute registers staging so that closing a session stops it before the sandbox is released. Uploads made before execute ran outside that fence. In a single-activation session, closing during them could release a borrowed sandbox, or stop an owned one, while an upload was still writing into it. Pi's mcp-servers.json and Codex's config.toml can carry the episode's tool session token.

Continuation activations were not affected: the agent base joins a continuation activation before it closes the session.

The other harnesses that use SandboxSession need no change. OpenClaw joins an unlaunched activation before it releases the sandbox. Kilo, Hermes, Claude Code, Stirrup, Pool and BrowseComp already stage inside execute.

No issue: this came out of the review of #4922, which first moved the OpenCode uploads as part of its image staging. The image part now lives in #4922, so this PR keeps only the change main already needs.

Compatibility

No configuration or API change.

Validation

  • pytest -n 16 over the OpenCode, Pi and Codex agent tests passed, apart from tests that fail the same way without this change: the pinned Pi CLI tests need a newer Node than the local Node 20, and a check that the OpenSandbox package is installed fails because that extra is not in the local environment.
  • For each harness, new tests stall an upload, close the session, and check that the upload is cancelled before the sandbox is released and that the harness never launches. They stall each staged file: Pi's seven, Codex's configuration, and OpenCode's three MCP files in single-activation and continuation sessions.
  • These tests fail on main for single-activation sessions, where the sandbox is released first. The continuation cases already pass on main.
  • Another OpenCode test checks that a session without MCP grants stages none of the MCP files.
  • pre-commit run --files <changed files> passed.

Rollout evidence

N/A: the change moves existing uploads into the staging step. The same files are written to the same paths before the launch, which the existing tests check through the HTTP session flow.

@copy-pr-bot

copy-pr-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

OpenCode sessions uploaded the required-MCP plugin, the grant list and
the empty grant status before the session's execute. Closing a session
during those uploads could release the sandbox while they were still
running. They now upload in stage_activation, next to prompt.txt, so
close stops them before the sandbox is released. A continuation
activation's deadline still bounds them, as before.

A test checks that close cancels a stalled grant upload before the
sandbox is released.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub ananthsub changed the title fix(opencode): stage session media inside activation staging fix(opencode): stage MCP grant files inside activation staging Nov 9, 2026
@ananthsub
ananthsub force-pushed the ananthsub/opencode-session-staging branch from 2f4d2f1 to 5531cc3 Compare November 9, 2026 17:28
@ananthsub
ananthsub changed the base branch from ananthsub/opencode-session-images to main November 9, 2026 17:28
The close test stalled only mcp-grants.json, so moving the plugin or the
status upload back outside staging still passed. It now stalls each of the
three files, in single-activation and continuation sessions, and runs the
activation as a task rather than on a thread. A new test checks that a
session without MCP grants stages none of the files.

The stage_activation docstring said the activation deadline bounds
staging. Single-activation sessions have no deadline; only continuation
activations do.

Signed-off-by: Ananth Subramaniam <[email protected]>
Pi and Codex uploaded their activation files before SandboxSession.execute,
and their close releases the sandbox before it cancels the activation. A
close during those uploads could release the sandbox while one was still
writing. For Pi these are models.json, settings.json, its extensions,
gym_mcp.mjs and mcp-servers.json; for Codex, config.toml. The MCP files
carry the episode's tool session token.

Both adapters now pass these files to stage_activation, which uploads them
inside execute, so close cancels the uploads first. Codex keeps
config.toml out of input.json, which holds the whole payload.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub ananthsub changed the title fix(opencode): stage MCP grant files inside activation staging fix(agents): stage activation files inside the close fence Nov 9, 2026
The Pi close test stalled only mcp-servers.json, so moving models.json,
settings.json, gym_mcp.mjs or an extension back before execute passed.
It now stalls each staged file. The Pi and Codex tests expect the
activation to end cancelled and bound the close, as the OpenCode test
does.

Remove Pi's unused upload_json, and say in the SandboxSession docstring
that every activation write belongs in stage_activation, since close
cannot stop a write made before execute. Comments now say close cancels
and waits for staging, and that the Codex configuration can carry grant
headers rather than always does.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub marked this pull request as ready for review November 9, 2026 18:38
@ananthsub
ananthsub removed the request for review from yfw November 9, 2026 18:38
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 9, 2026 18:39
@ananthsub
ananthsub enabled auto-merge November 9, 2026 18:44

@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

I found no code defect in the staging changes after inspecting all 10 changed files and their affected close, failure, and continuation paths. One validation requirement remains.

RISK — Add representative real smoke-rollout evidence

The PR provides unit-test results but marks real rollouts N/A. This changes observable cancellation and upload-failure behavior in Codex, Pi, and OpenCode, rather than only reorganizing code. The protected AGENTS.md quality bar requires representative real-model smoke rollouts for behavior-changing agent work. The mocked sandbox tests don't provide that integration evidence.

Correction: Run and document a representative sandbox episode for each affected harness with a real model and an MCP grant. Record the configuration, provider, commands, artifact locations, and inspected agent and verifier outcomes in the PR. No runtime rewrite is requested.

Preservation and acceptance: Each episode should initialize and use the granted tool, return the expected response, reach verification, and close with cleanup confirmed. Include a two-activation OpenCode continuation to confirm the resumed session still works. Keep the existing regression assertions for cancellation before release, no launch during interrupted staging, grant-less sessions, and continuation-deadline recovery. Preserve the existing file contents and destinations, including keeping Codex's grant-bearing configuration out of input.json.

This was a static, read-only review; I did not execute tests or rollouts.

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

@ananthsub
ananthsub added this pull request to the merge queue Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@ananthsub
ananthsub merged commit 9652015 into main Nov 9, 2026
69 checks passed
@ananthsub
ananthsub deleted the ananthsub/opencode-session-staging branch November 9, 2026 19:59

This branch was previously deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants