Skip to content

feat(terminus-2): run Terminus 2 in task sandboxes through agent sessions - #5650

Merged
yaoyu-33 merged 19 commits into
mainfrom
yuya/terminus-2-agent-sessions
Nov 16, 2026
Merged

yaoyu-33 merged 19 commits into
mainfrom
yuya/terminus-2-agent-sessions

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds agent sessions to terminus_2_agent, running Harbor's Terminus 2 loop inside the task sandbox through SandboxSession. Seed prepares the runtime; a supervised activation drives local tmux and calls Gym's Model Server; close collects observations before verification. No separate issue is needed for this focused adapter integration.

  • Seed borrows a direct sandbox or creates an owned one with TTL and lifecycle metadata. It first checks for Bash and script (an image without either gets a final 422 before any install), then uploads a reusable, version-constrained private Python runtime and prepares tmux before activation. Runtime installation needs no sandbox package-index access; installing missing tmux can still require root and network.
  • Model calls retain the rollout URL and x-session-id. Input/instructions and supported sampling reach Terminus; unsupported representations are refused before activation. The wall-time budget starts after the concurrency slot is acquired. Terminal control and session close survive a task moving or removing its workdir.
  • The runner saves completed turns on termination. Responses distinguish completion, graded limits/stops, model errors and harness failures. Only the supervisor's receipt makes a SIGTERM a wall_time timeout; a SIGTERM a task command sends (pkill python3) ends the run as terminated. Usage is reported only when every model call had a usage record, in both execution modes; otherwise it stays unknown. Close reports invocation/model references, conversation, command batches, summarization, sandbox outcome and cleanup evidence.
  • Services in the detached tmux terminal remain available for verification; the sandbox owner is responsible for final sandbox shutdown.

Compatibility and limits

Shared lifecycle change: SandboxSession's stop, expiry probe and session-file removal now run from / when the session directory is absolute (control_cwd in nemo_gym/agents/utils/supervisor_client.py), instead of in the task workdir. These commands only touch session files, and Docker refuses exec -w into a directory the task moved, so every sandboxed adapter's close was affected. Relative session directories and the harness launch keep the workdir.

The host Responses entrypoint remains available; host /run is preserved through entrypoint: legacy_app.py. They keep main's handling of request max_output_tokens: it becomes max_tokens on every model call, which anyterminal_terminus_2 rows rely on. Agent sessions reject a non-null request max_output_tokens with HTTP 422 before binding the activation, because a session's request covers the whole episode and Terminus cannot bound it across model calls; session task rows should drop the field and set a per-call cap on the Model Server. model_info.max_output_tokens remains model metadata, not a budget.

terminus_2_sandboxed_agent and benchmark declarations remain unchanged. Capability is Evaluation: multi-command result pairing still depends on #3520, and per-command timing is unavailable. Task commands share the runner's user and can alter result files; training is unqualified. No full TB2.1 evaluation or supported pairing is claimed.

The host path now prepends request instructions to the instruction, as agent sessions do; main ignored them. reasoning_effort and max_thinking_tokens must stay null: Harbor applies them only to the LiteLLM client it builds itself, so the agent now refuses to start with either set.

Validation

  • Final source: c844be16c, with current main merged in; commits have DCO sign-off.
  • Last round (bot review RISKs): Terminus adapter suite plus tests/unit_tests/agents/test_sandbox_session.py and test_sandbox_supervisor_client.py: 318 passed on the Linux workstation. The new moved-workdir close tests (finished and active run, real local provider) and the no-bash refusal assertions fail on the previous sources. Because the cwd change is shared, these sandboxed adapter suites were rerun and pass: codex 548, pi 378, openclaw 522, opencode 404 (1 workstation-only failure: sh exit code for an exec-format error), claude_code 208, cline 197, copilot 144, droid 144, openhands 131, goose 44, kimi_code 31. hermes and stirrup were not run (their runtimes are not installed in that venv).
  • Real Docker on the workstation, with no model: an alpine:3.20 image (no bash) is refused with a 422 before any runtime directory or harness file is written. A borrowed debian:bookworm-slim sandbox whose task runs mv /app /app.bak closes cleanly for a finished run and for an active one (stop confirmed, rc 143, partial output collected). Session files are removed, /app is not recreated, and the sandbox stays up. With the previous cwd, the same runs fail with Could not remove ... session files and launch outcome is unknown; cannot confirm termination.
  • Linux component suite plus the core tests this PR touches (tests/unit_tests/tooling/test_agent_environment_*, environment/test_session_harness_benchmark_profiles.py, test_session_contract_repo.py): 294 passed on the Linux workstation. After the host max_output_tokens change, the adapter suite again passed (194); the two host tests for it fail on the previous code.
  • The 13 tests added in the last review round fail against the previous sources and pass on the fixed ones.
  • pre-commit run --files <changed paths> passed; uv lock --check (uv 0.13.7) passed for responses_api_agents/terminus_2_agent.
  • Real-model rollout (earlier round, runtime unchanged since): one Reasoning Gym example, NIM nvidia/nemotron-3.5-super-vl-120b-a12b, agent-owned Docker debian:bookworm-slim, temperature 0, top_p 1, Model Server max_tokens 4096, thinking disabled, 180-second activation budget. Response completed, reward 0.0, unmasked, no failure outcome; verifier output inspected; all task process groups and containers removed. This one-row smoke checks runtime and verification behavior, not benchmark qualification. The last round changed result grading and usage reporting only, so no new rollout was run.
  • Harness conformance probes do not apply: Terminus 2 has no function-calling shell tool.

CI repair validation (2026-11-14)

  • Merged current main, including the upstream CrewAI timeout-test fix that caused the failed server shard.
  • Moved the unchanged host /run relay to legacy_app.py; the default session adapter inherits the Environment Server entrypoint. Existing host /run configurations must set entrypoint: legacy_app.py. Added a regression assertion for the default entrypoint and retained legacy refusal and request-forwarding tests.
  • Linux workstation, Python 3.13.14: python -m pytest responses_api_agents/terminus_2_agent/tests -q -o addopts='': 195 passed.
  • python -m scripts.environment_server_compliance.inspection responses_api_agents/terminus_2_agent --output findings.json: no findings.
  • pre-commit run --all-files (pre-commit 4.2.0): passed after formatter fixes. No harness loop or verifier behavior changed; the existing real-model smoke above remains applicable. No additional model rollout for this entrypoint extraction.
  • Shared regression validation: python -m pytest tests/unit_tests/agents/test_sandbox_session.py tests/unit_tests/agents/test_sandbox_supervisor_client.py tests/unit_tests/environment/test_session_harness_benchmark_profiles.py tests/unit_tests/tooling/test_agent_environment_default_configs.py tests/unit_tests/tooling/test_agent_environment_session_templates.py -q -o addopts='': 226 passed.

…ions

terminus_2_agent now serves agent sessions. At seed it borrows the task
sandbox the Resources Server lends, or starts one from sandbox_provider,
installs a private Python runtime with the pinned Harbor through
SandboxPythonRuntime (reused when it passes its import check), stages the
runner and checks that tmux runs. Each activation runs Terminus 2 inside
the sandbox under SandboxSession's process supervisor, and close returns
the invocation, its model calls, the command batches with their terminal
output, summarizations and the sandbox outcome.

The host path, /v1/responses without a session and /run, keeps working
for AnyTerminal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33 yaoyu-33 added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior labels Nov 5, 2026
@copy-pr-bot

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

@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3791915

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

yaoyu-33 and others added 2 commits November 5, 2026 10:44
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Review fixes for the Terminus 2 agent-session adapter:

- A rollout stop during seed, or one that ends the runner before it saves
  a result, is reported as an empty wall_time run with ng_rollout_stop
  instead of failing the activation (which was retried).
- The run's budget starts once the run has a concurrency slot, so a
  provider transport timeout after a long queue stays a failure.
- Terminus's own tmux commands run from / when a task command removes
  or moves the workdir, instead of ending the run as a harness error.
- Request instructions join Terminus's instruction; tools, tool_choice
  and parallel_tool_calls stay out of its model calls; a field the
  converter cannot represent is refused with 422 before the activation
  starts.
- An owned sandbox carries the provider's default metadata and session
  labels, gets its workdir created at setup, and its default TTL
  reserves both setup steps.
- A runner result that does not validate becomes an
  observation_capture_failed gap instead of failing the activation or
  close.
- Setup refuses an image without bash.
- Add configs/profiles/benchmark.yaml, like the other session harnesses,
  and register it with the shared profile tests.
- README: capability level Evaluation until #3520 lands, supported
  pairings, request-field rules, terminal lifetime, scoped absolute IP,
  limits, and the relation to terminus_2_sandboxed_agent.
- Tests: the real SandboxSession lifecycle over an in-memory sandbox
  (stops, close during a run, activation after close), /run refusals,
  runner max_turns, moved workdir, background process and imports
  without nemo_gym, and a regression test for each fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d3e7115

yaoyu-33 and others added 2 commits November 5, 2026 14:02
- timeout, model_timeout_sec and command_timeout_sec must be positive and
  finite: the run timeout sets the supervisor's deadline and an owned
  sandbox's TTL.
- After the runner removes its SIGTERM handler, it ignores the signal, so a
  stop that arrives once Terminus has returned no longer kills the runner
  before it writes its result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 32ef036

yaoyu-33 and others added 2 commits November 12, 2026 18:13
- A SIGTERM without the supervisor's deadline receipt (a task's `pkill python3`) ends the run as `terminated`,
  not as a `wall_time` timeout.
- A deadline that ends the runner before it saves anything is an empty `wall_time` run, as a rollout stop already
  was, instead of an activation error.
- The runner saves its result while it still handles SIGTERM, so a late signal cannot end it unsaved.
- A reply Harbor cannot parse no longer clears a pending completion claim, matching Harbor's own handshake.
- Usage is unknown when the result carries no usage count, and on the host path when any call lacked usage;
  reasoning tokens are never a measured zero.
- `reasoning_effort` and `max_thinking_tokens` are refused at startup: Harbor applies them only to its own client.
- Update the HLE profile test and README for main's grant-free judge Environment Servers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 53cda02

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 13, 2026 02:19
Only agent sessions refuse request max_output_tokens: a session's request
covers the whole episode, which Terminus cannot bound across model calls.
The host /v1/responses and /run paths again send it as each model call's
max_tokens, as on main, so anyterminal_terminus_2 rows that carry
max_output_tokens keep working.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 22951c7

@weijiac0619

Copy link
Copy Markdown
Contributor

The two RISKs from the bot review still apply at 22951c7. Close runs with cwd=workdir, so it fails after a task moves its workdir, and the bash/script probe runs after the runtime install, so a no-bash image gets a setup error instead of a 422. Could you address both, or reply on the threads if you think they’re out of scope for this PR?

yaoyu-33 and others added 2 commits November 13, 2026 22:24
…ge first

Session lifecycle commands (stop, expiry probe, session-file removal) only
address files under an absolute session directory, so they now run from "/"
instead of the task workdir. A task that moves or deletes its workdir (Docker
then refuses `exec -w`) no longer turns a finished run into a cleanup failure
or leaves an active run's stop unconfirmed. Relative session directories still
resolve against the workdir; the harness launch keeps the workdir.

Terminus 2 now probes for bash, script and tmux before the runtime installer,
which itself runs bash, so an image without bash gets a final 422 instead of an
installer RuntimeError. A probe with a provider error is not a missing tool.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

Thanks for flagging these. Both RISKs are fixed in c844be1:

  1. Close after the task moves its workdir. SandboxSession's stop, expiry-marker probe and session-file removal now run from / when the session directory is absolute (control_cwd in supervisor_client.py). The harness launch and relative session directories still use the workdir. Since this helper is shared, the same close failure is also fixed for the other sandboxed adapters. Their suites pass on the workstation; the PR body lists them. On real Docker, a borrowed sandbox that runs mv /app /app.bak now closes cleanly for both a finished and an active run, and /app is not recreated. With the previous cwd the same runs fail as the review describes.
  2. No-bash image gets a 422. The bash/script/tmux probe now runs before runtime.is_installed()/install(). Only an rc-3 probe with no provider error counts as a refusal, and the tmux install still happens after the runtime and harness uploads. On real Docker, alpine:3.20 is refused with missing bash before any runtime or harness file is written.

New regression tests: moved-workdir close (finished and active, local provider), stop/removal with a missing workdir, and "no install or upload before the refusal". All of them fail on the previous sources.

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test c844be1

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test dd76fa4

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test a956c8e

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit 25c5d31 Nov 16, 2026
80 checks passed
@yaoyu-33
yaoyu-33 deleted the yuya/terminus-2-agent-sessions branch November 16, 2026 06:10
lafrancef added a commit that referenced this pull request Nov 16, 2026
Terminus 2 now tracks unknown cache reads per call (#5650); keep that and
leave a missing total_cached_tokens unknown instead of defaulting it to 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
weijiac0619 added a commit that referenced this pull request Nov 17, 2026
terminal_bench_2_1/terminus_2 now lends each task sandbox to
terminus_2_agent, Harbor's Terminus 2 at the Harbor commit it pins, which
serves agent sessions since #5650; the terminus_2_legacy_agent recipe keeps
terminus_2_sandboxed_agent on the relay. The README lists how the two
harnesses' defaults differ, and a test checks that a model server can read
each preset harness's header without loading the harness's app.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>
RyaliNvidia pushed a commit to RyaliNvidia/Gym that referenced this pull request Nov 17, 2026
…the Harbor environment server and keep the relay recipes as *_legacy_agent (NVIDIA-NeMo#6181)

* feat(terminal_bench_2_1): run the Terminus 2 and OpenCode presets on the Harbor environment server

terminal_bench_2_1/terminus_2 and terminal_bench_2_1/opencode ran on the
legacy_agent /run relay of the terminal_bench_2_1 resources server. They now
name `harbor_target: terminal_bench_2_1` and run the 89 pinned Harbor task
folders through the Harbor environment server with agent sessions:
terminus_2_sandboxed_agent's episode sessions (its /run route is the
deprecated part) and opencode_agent in place of opencode_sandboxed_agent.
Both keep eight rollouts per task.

The previous recipes stay unchanged as terminus_2_legacy_agent and
opencode_legacy_agent (lifecycle deprecated). The Super 3.5 bundle and
inkling_small, which compose the resources server's servers, now include
terminus_2_legacy_agent.yaml. The resources server's README marks it
legacy; the benchmark README gets a Harbor "Run" section and the
differences between the two paths. Docs that show agent composition and
instance renaming use opencode_legacy_agent, and the tests that exercise
the relay recipes follow them to their new names.

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

* Document TB2.1 Harbor scoring, repairs and command mapping

The benchmark README now says how the Harbor presets score an episode, which
tasks the resources server repairs at run time and what each does when run as
published, how the two paths differ (sandbox size, time budgets, the OpenCode
adapters' defaults), and which Harbor setting replaces each resources-server
key or command. The preset test imports from the public API.

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

* Correct the OpenCode adapter differences in the TB2.1 README

On TB2.1 both adapters keep OpenCode subagents enabled (the relay loads
opencode_sandboxed_agent.yaml, which denies only webfetch, websearch and
skill), and both bound the whole run at 10,800 seconds; the sandboxed
adapter also caps each model call at one hour.

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

* Load the Terminus 2 agent app on first use

A model server imports each harness package that uses it to read the
assistant-message header, in the model server's own environment. The
terminus_2_agent package imported its app, which needs Harbor, so any run
of terminus_2_agent against a model server without Harbor (vllm_model, for
one) stopped at startup with "No module named 'harbor'". The package now
exports the app's classes lazily, as stirrup_agent does.

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

* Run the TB2.1 terminus_2 preset with terminus_2_agent

terminal_bench_2_1/terminus_2 now lends each task sandbox to
terminus_2_agent, Harbor's Terminus 2 at the Harbor commit it pins, which
serves agent sessions since NVIDIA-NeMo#5650; the terminus_2_legacy_agent recipe keeps
terminus_2_sandboxed_agent on the relay. The README lists how the two
harnesses' defaults differ, and a test checks that a model server can read
each preset harness's header without loading the harness's app.

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

* Compose the agent-selector example onto the TB2.1 relay recipe

terminal_bench_2_1/opencode now runs on the Harbor environment server,
where --agent-type swaps the harness instead of composing it onto the
benchmark's agent; the composition case uses opencode_legacy_agent, as the
docs do.

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

* Record Terminus 2's feedback on an unparsed reply as a user turn

When Terminus cannot parse a reply it runs no command and sends parse-error
feedback as the step's observation. The response gave that observation a
function_call_output with a made-up call_id that no function call opened,
so the Harbor environment server could not export the transcript to ATIF
("function result ... matches no pending call") and masked the sample: 5
of 39 Terminal-Bench 2.1 rollouts in a 20-task run. A result with no call
to answer is now the next user turn, which ATIF attaches as that step's
observation.

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

---------

Signed-off-by: weijia chen <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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 feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants