Skip to content

fix(opencode): stop keeping each rollout's export by default - #6241

Draft
ananthsub wants to merge 44 commits into
ananthsub/verification-log-dirfrom
ananthsub/opencode-export-cleanup
Draft

ananthsub wants to merge 44 commits into
ananthsub/verification-log-dirfrom
ananthsub/opencode-export-cleanup

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

For every rollout, opencode_sandboxed_agent runs opencode export in the sandbox and downloads the result to the agent host, where responses() parses it to build the response, the usage and the length and error flags. On main, the agent downloads it to <artifacts_dir>/<session_id>/export.json and never removes the export or its folder, so a training run leaves one folder per rollout behind. When that folder is on a shared filesystem such as Lustre, each folder and file also adds load on its metadata servers.

#6230 fixes this when artifacts_dir is unset. In that case the agent downloads the export into a temporary folder from async_request_temp_dir (#6235), which is removed once the export is parsed, and also when the rollout ends early. With artifacts_dir set, the agent keeps each export as before, which is the explicit way to keep exports for debugging.

The agent's configs/benchmark.yaml, however, always set artifacts_dir, to ${oc.env:OPENCODE_ARTIFACTS_DIR,results/opencode}. That is a relative path, and it resolves against the server's own source folder, so every benchmark run kept all of its exports inside the checkout even after #6230. This PR changes that default to null. Benchmark runs then keep no exports unless OPENCODE_ARTIFACTS_DIR is set.

It also adds a test of the export's lifecycle through the real responses() path. The test runs a rollout that completes, one whose export is invalid, and one cancelled while the export downloads. Without artifacts_dir, each must download outside the source folder and leave nothing behind. With artifacts_dir, each must keep the export where it was kept before.

This follows the rule for runtime writes in #6235. The export is scratch while the same request parses it, and it becomes debug output only when the server's own folder setting, artifacts_dir, asks to keep it. The merge order is #6235, then #6230, then this PR, which targets #6230's branch. No issue was filed, because the problem and the fix are both contained in this PR and #6230.

Compatibility

  • Benchmark runs that use configs/benchmark.yaml no longer keep OpenCode exports unless OPENCODE_ARTIFACTS_DIR is set. Set it to an absolute path, because a relative path resolves against the server's source folder.
  • Without artifacts_dir, opencode_results_fpath is an empty string, as in fix(swe): keep verification logs out of the source checkout #6230. No code in Gym reads that field.
  • With artifacts_dir set, nothing changes.
  • The agent's README no longer tells users to set OPENCODE_ARTIFACTS_DIR. It now describes the variable as an optional debugging setting whose folders are never removed. PI_ARTIFACTS_DIR is still required for Pi.
  • Rewards, responses and usage do not change. Only the lifetime of the local copy of the export changes.

Validation

  • The agent's unit tests on this branch.
  • On main, the three lifecycle cases without artifacts_dir fail and the three with it pass, which shows that keeping is unchanged.
  • pre-commit run on the changed files, and DCO sign-off.
pytest responses_api_agents/opencode_sandboxed_agent/tests/

Rollout evidence

Two real rollouts of hle/opencode_legacy_agent ran on Slurm job 2048963, on oci-aga-slurm-1, node cpu-0001, partition cpu. They used Gym at 7d0239c414, this PR's head on #6230's branch. The policy model and the HLE judge were openai/openai/eccn-gpt-6-luna behind the openai_model server, and OpenCode ran in OpenSandbox. Both runs answered the first task of the prepared HLE text-only split, 668825f80a642802bdfeadfa, a multiple-choice question from the Humanities/Social Science category.

gym eval prepare --benchmark hle/opencode_legacy_agent
gym eval run --benchmark hle/opencode_legacy_agent --model-type openai_model --split benchmark \
    --limit 1 --num-repeats 1 ++use_cached_prepared_benchmarks=true \
    ++policy_model_name=openai/openai/eccn-gpt-6-luna '++absolute_ip_server_types=[responses_api_models]' \
    ++hle_opencode_agent.responses_api_agents.opencode_sandboxed_agent.preinstalled_opencode=false \
    ++hle_opencode_agent.responses_api_agents.opencode_sandboxed_agent.network_access=inherit \
    ++hle_opencode_agent.responses_api_agents.opencode_sandboxed_agent.sandbox_config.workdir=/root

The preset's offline science image is not published, so the runs used OPENCODE_SANDBOX_IMAGE=python:3.13. That image needed three overrides:

  • OpenCode 1.17.11 is installed when the sandbox starts, instead of being preinstalled.
  • network_access=inherit lets that install download OpenCode.
  • The working directory is /root, because the image has no /workspace.

None of these affects how the agent host downloads, parses or removes the export.

With OPENCODE_ARTIFACTS_DIR unset, which is the new default:

  • The agent returned a usable answer ("Answer: E. Weak Quality Addition, Confidence: 95%"), and OpenCode exited 0 with the run marked finished.
  • The export was found and parsed, and usage was populated: 5,259 input tokens and 499 output tokens.
  • The judge was called once and graded the answer wrong, so the reward is 0.0 and the row is not masked.
  • opencode_results_fpath is an empty string.
  • A check of the node's temp directory every 2 seconds saw /tmp/nemo_gym-<uid>/<process folder>/opencode-results-* from 11:24:23 to 11:24:27. It was gone by the next check, before gym eval run returned at 11:24:33, and no opencode-results-* folder was left on the node afterwards.

With OPENCODE_ARTIFACTS_DIR set to an absolute path in the run folder:

  • The rollout completed the same way: an answer, populated usage, and one judge call with reward 0.0.
  • The export was kept at <OPENCODE_ARTIFACTS_DIR>/<session id>/export.json (4,316 bytes), and opencode_results_fpath names that file.
  • No folder appeared in the node's temp directory during this run.

The job's cleanup found no sandboxes left for the run.

@copy-pr-bot

copy-pr-bot Bot commented Nov 16, 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.

@ananthsub ananthsub added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior labels Nov 16, 2026
@ananthsub
ananthsub force-pushed the ananthsub/opencode-export-cleanup branch from ef7a1d8 to e0bdc11 Compare November 16, 2026 18:45
@ananthsub ananthsub changed the title fix(opencode): remove each rollout's export once it is parsed fix(opencode): stop keeping each rollout's export by default Nov 16, 2026
@ananthsub
ananthsub force-pushed the ananthsub/verification-log-dir branch 10 times, most recently from a317ebb to 1790002 Compare November 17, 2026 15:09
@ananthsub
ananthsub force-pushed the ananthsub/opencode-export-cleanup branch 3 times, most recently from df34339 to 80b2d6f Compare November 17, 2026 16:28
@ananthsub
ananthsub marked this pull request as ready for review November 17, 2026 16:29
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 17, 2026 16:30
@ananthsub
ananthsub force-pushed the ananthsub/verification-log-dir branch from 1790002 to 521ab36 Compare November 17, 2026 16:37

@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 RISK: the changed runtime default lacks the representative real smoke-rollout evidence required by repository guidance. I found no code defect in the inspected config wiring, cleanup, or downstream response handling.

I inspected all three changed files and their directly affected paths. One parallel review report was unavailable, so I independently inspected its lifecycle-test scope. This was a static review; I did not execute tests or verify the reported test results.

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

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 17, 2026
@yaoyu-33
yaoyu-33 requested a review from athitten November 17, 2026 19:06
A server runs with its own source folder as the working directory, so a
relative default or a path built from Path.cwd() writes into the Gym
checkout, which is on a shared filesystem on clusters.

Add nemo_gym/core/runtime_files.py with one helper per kind of runtime
write. scratch_dir and async_scratch_dir create a folder for one request
or session under TMPDIR, or under the new shared_scratch_dir when
another node reads it, and remove it on exit. debug_artifact_dir
returns a new folder per unit of work under the new debug_artifacts_dir
(off by default) or a server's own setting, separated by kind, capture
key and agent instance.

Add the runtime-write-paths pre-commit hook, which fails on new
Path.cwd() and os.getcwd() calls and relative *_dir and *_root defaults
in server code, with an allowlist of existing sites that only shrinks.
Document the rule in AGENTS.md and the configuration reference.

Signed-off-by: Ananth Subramaniam <[email protected]>
Shipped server, benchmark and environment configs set folder keys that
override the Python defaults, for example the OpenCode benchmark
config's artifacts_dir of ${oc.env:OPENCODE_ARTIFACTS_DIR,results/opencode}.
The runtime-write-paths check now also flags *_dir and *_root keys in
those YAML configs whose value is relative, reading the fallback of
oc.env and oc.select interpolations and treating references to other
keys as absolute. Existing sites join the allowlist.

Signed-off-by: Ananth Subramaniam <[email protected]>
Rework the runtime file foundation after design review:

- Replace debug_artifacts_dir and debug_artifact_dir() with debug_dir
  and debug_folder(), so "artifacts" keeps its RunArtifacts meaning.
- Drop shared_scratch_dir: a request passes data to another process in
  the request, never a temporary path. scratch_dir becomes temp_folder()
  under a new temp_dir setting, resolved on each node when unset, and
  removes leftover folders of dead processes in the same PID namespace.
- Add finish_run_files() to delete a run's capture folder when a
  checkpoint controller holds its durable copy.
- Move the storage warning from config parsing to the writing process:
  temp_dir and capture folders are checked once per process on their
  own node, for shared and memory-backed filesystems.

Signed-off-by: Ananth Subramaniam <[email protected]>
Address the adversarial review of the runtime file helpers:

- Name temporary folders by host boot id as well as PID namespace and
  pid, and skip removing leftovers on filesystems other hosts share:
  every host's initial PID namespace has the same number, so a check on
  one host could delete another host's live folder.
- Remove a folder that a worker thread creates after its
  async_temp_folder task was cancelled.
- Let callers pass the parent folder, for code such as Ray tasks that
  runs without Gym's configuration.
- Replace finish_run_files with create_owned_folder and
  delete_owned_folder: deletion requires a .nemo-gym-owned marker, so a
  folder a user chose is never removed, and the marker goes last so an
  interrupted deletion can be finished.
- Percent-encode every debug folder segment, check debug roots for
  unsuitable storage, and recognize more shared filesystems.

Signed-off-by: Ananth Subramaniam <[email protected]>
…llow

The parser resolved both settings on the driver, following the driver's
symlinks before the path reached every node. Make them absolute without
resolving symlinks instead.

Signed-off-by: Ananth Subramaniam <[email protected]>
- The default temp_dir: an existing folder that others can open is made
  private again, with a warning, so a launcher's 0777 folder cannot let
  another user rename or replace this user's folders.
- Session folders now start with "session.", and remove_temp_dir removes
  only those, so a request folder or a folder a tool made beside them is
  refused.
- async_remove_temp_dir removes a session folder on the temporary folder
  threads, off the event loop.
- Process folder names end with a random part drawn once per process, so
  removing a dead process's folder never removes the folder of a new
  process that reused its pid. The same-name clearing before use goes.
- save_dir: a copy already running when its task is cancelled stops and
  removes what it copied, since the request may remove the source next.
  copy_tree takes a stop event and raises CopyStopped.
- A rollout id of "." or ".." gets a folder of its own instead of naming
  the folder above it.
- The save_dir docstring and the reference say that an invalid name or
  server_name raises ValueError.

Signed-off-by: Ananth Subramaniam <[email protected]>
…ed removal

remove_temp_dir now runs on worker threads through async_remove_temp_dir,
so it reads the process folders under the lock: another thread adding or
dropping one mid-iteration would otherwise raise instead of logging.

A new test cancels async_remove_temp_dir while its removal waits behind a
busy thread and checks that the folder is still removed.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/verification-log-dir branch 2 times, most recently from b1f50bd to 80b92b6 Compare November 18, 2026 17:26
- Process folders and process-wide folders are created with mode 700,
  like the request and session folders in them, so a configured temp_dir
  that others can open does not expose process-wide state.
- copy_tree writes into <dest>.partial and renames it to dest once
  complete, so a process killed mid-copy never leaves a kept folder that
  looks whole.
- Leftovers of dead processes are removed outside the first-use lock, so
  a large one never holds up session removals or another temp_dir's first
  use. It removes only folders of processes that are gone, so it races
  with nothing this process makes.
- async_session_temp_dir creates a session folder on the temporary folder
  threads and removes one created after its caller was cancelled; it
  shares that code with async_request_temp_dir.
- The rollout part of a kept folder's path is cut to 200 characters after
  percent-encoding, which can triple a rollout id's length past the
  filesystem's name limit.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/verification-log-dir branch from 80b92b6 to ca6870b Compare November 18, 2026 17:35
A rename onto an empty folder replaces it, so copy_tree's check for an
existing destination is what keeps a copy from taking over a folder it
did not create. The existing test used a folder that was not empty, which
the rename alone refuses.

Signed-off-by: Ananth Subramaniam <[email protected]>
Six SWE-style resources servers wrote a verification log on every /verify
call into a logs/ folder next to their own app.py: scale_swe, swe_next,
r2e_gym, swe_gym, denovo_swe and swebench_pro. In training, that folder
is inside the Gym checkout mounted from a shared filesystem, so every
verification created a folder and files there, and nothing removed them.
swebench_pro also added one folder per session.

Each of these servers now takes verification_log_dir, the setting that
swe_rebench and the swemer servers already had. It defaults to null, so
no logs are written. When it is set, logs go to
<verification_log_dir>/instance-<id>/<random>/attempt-<n>. The path is
built by one helper, resources_servers/swebench/verification_logs.py,
which the servers that already had the setting now use too.

opencode_sandboxed_agent wrote each session's OpenCode export into a
results/ folder next to its app.py when artifacts_dir was unset. It now
uses a temporary folder in that case and removes it once the export and
database snapshot are parsed, and opencode_results_fpath is empty.

Signed-off-by: Ananth Subramaniam <[email protected]>
A relative path resolves against the server's working directory, which is
its own source folder, so it would bring back writes into the checkout.

Signed-off-by: Ananth Subramaniam <[email protected]>
The swebench resources server, which grades SWE-bench Multilingual, ran
the SWE-bench harness with its default log folder. That folder is
relative to the working directory, which is the server's own source
folder. So every verify created a logs/run_evaluation/<run_id> tree in
the checkout, searched it and deleted it, and an interrupted verify
left the tree behind.

run_instance now takes the log folder as an argument. The server gives
each verify a new temporary folder and removes it in a finally block.
To keep a copy, set verification_log_dir, as for the other SWE servers.

clear_swebench_debug_logs has no effect now. It is still accepted so
existing configs load, and it logs a warning when it is set to false
without verification_log_dir. analyze_golden_patch_logs.py takes the
log folder as an argument instead of the old path.

Signed-off-by: Ananth Subramaniam <[email protected]>
The failure-only grading tests run the real run_instance. They now pass
log_root and keep the working directory empty, and a new test checks
that the test output and report land under log_root and nothing is
written to the working directory.

Signed-off-by: Ananth Subramaniam <[email protected]>
The SWE resources servers now take a per-server debug_dir in place of
verification_log_dir, and build each verification's log folder with
debug_folder from nemo_gym.core.runtime_files. When the server's own
debug_dir is unset, the global debug_dir applies under the server's
name, so one setting turns verification logs on for every server.

This renames the setting on the servers that already had it
(swe_rebench, the swemer servers and swe_internal_v1). No release has
included it, so the old name is not kept. resources_servers/swebench/
verification_logs.py is removed.

The swebench server runs the harness in async_temp_folder and keeps the
folder through keep_as when debug files are on. The opencode agent's
fallback for an unset artifacts_dir is async_temp_folder, so its parent
follows the global temp_dir.

Signed-off-by: Ananth Subramaniam <[email protected]>
Under debug_folder a report sits several levels below the verification
folder, so copying the first path segment copied the whole verification
tree for each failed sample. Copy the report's own verification folder,
and say which folder to pass.

Signed-off-by: Ananth Subramaniam <[email protected]>
…_dir

explicit save_dir call, and leaves keeping files to each server.

Each SWE server now has keep_verification_logs, off by default. Every
verification attempt writes its logs into a temporary folder on the
node, which is removed when the attempt ends. With the setting on, the
folder is copied once into
<results_dir>/<server name>/verification/<rollout>/<time>-<instance id>-attempt<n>-<random>/
after the attempt, even when it fails. So a verify never writes into the
checkout or onto shared storage while it runs.

run_keeping_logs in resources_servers/swebench/verification_logs.py does
this for all thirteen servers. The servers that report a log folder in
their verify response report the kept copy, or nothing when logs are
not kept.

Signed-off-by: Ananth Subramaniam <[email protected]>
… nemo_gym.core

swebench_pro kept its verification logs inside the attempt's timeout. When that timeout
expired, the copy ran while the task was being cancelled, so save_dir kept nothing for the
attempts whose logs matter most. The timeout now ends inside the log folder, before the copy.

The runtime file helpers are imported from nemo_gym.core's public API.

Signed-off-by: Ananth Subramaniam <[email protected]>
The harness-crash test now also runs with keep_verification_logs on and checks that
the failed verify's logs are copied once under the server's results.

Signed-off-by: Ananth Subramaniam <[email protected]>
SWE-Next sessions now read the global config at startup and stop the verifier
sandbox through the shared session base, so the log tests stub both.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/verification-log-dir branch from ca6870b to e1eafc6 Compare November 18, 2026 18:02
@ananthsub
ananthsub marked this pull request as draft November 18, 2026 18:27
The OpenCode agent's benchmark config set artifacts_dir to
results/opencode, a relative path that resolves into the server's own
source folder. With artifacts_dir set, the agent keeps every rollout's
export under <artifacts_dir>/<session_id>/, so a benchmark run left one
folder per rollout behind and never removed it.

The config now defaults artifacts_dir to null, and OPENCODE_ARTIFACTS_DIR
still keeps exports when it is set. Without artifacts_dir the export goes
to a temporary folder that is removed once it is parsed.

A test runs a rollout that completes, one whose export is invalid and one
cancelled while the export downloads. Without artifacts_dir each must
leave nothing behind; with it each must keep the export as before.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/opencode-export-cleanup branch from 80b2d6f to 7d0239c Compare November 18, 2026 18:28
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:low Autobot PR risk: low label Nov 18, 2026
@ananthsub
ananthsub marked this pull request as ready for review November 18, 2026 19:39

@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

The prior RISK about missing real-rollout evidence is addressed by the author's new rollout evidence. The documented command selects the affected legacy preset, which inherits the changed storage default. The reported unset-variable run produced a usable answer with populated usage and an unmasked judge reward of 0.0. It also recorded an empty opencode_results_fpath and removal of the temporary export. The configured-variable run kept its export. The documented image overrides do not bypass the export-storage path being validated.

I checked the six lifecycle cases and the length-stop assertions against their implementation. They still cover temporary cleanup, opt-in retention, and preservation of partial output and grading behavior.

This follow-up covered the prior finding and its preservation requirements, not a fresh whole-PR review. The previously reviewed tree at 80b2d6f137b2f0cb8de183177a85a0a1d163b11d was unavailable, so I could not compare inter-review source changes. I did not execute tests or rollouts, or independently inspect the Slurm artifacts.

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.

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 18, 2026
@ananthsub
ananthsub marked this pull request as draft November 19, 2026 17:09
@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Nov 19, 2026
@ananthsub
ananthsub force-pushed the ananthsub/verification-log-dir branch from e1eafc6 to 4226d69 Compare November 20, 2026 19:46

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 needs-review PR is ready for code review and waiting on a reviewer risk:low Autobot PR risk: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants