Skip to content

feat(terminus-2): episode sessions on the environment server's sandbox (M7) - #3729

Merged
adil-a merged 1 commit into
mainfrom
adasif/harbor-m7-terminus-sessions
Oct 21, 2026
Merged

adil-a merged 1 commit into
mainfrom
adasif/harbor-m7-terminus-sessions

Conversation

@adil-a

@adil-a adil-a commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

M7 of the Harbor tasks RFC (GitLab MR 340, MR 354): terminus_2_sandboxed_agent runs on the sandbox the harbor environment server seeds. Stacked on #3706 (M6).

  • Episode sessions. seed_agent_session connects to the environment server's sandbox over SandboxAccess (provider config ref plus descriptor) and close_agent_session disconnects without stopping it. resources_server is optional: only the legacy /run path needs it. The existing owned-sandbox /run path keeps its flow. Model calls carry the episode's rollout id.
  • Well-formed history ids. Replayed history items get msg_/rs_ ids. OpenAI-compatible Responses backends reject an empty id, which failed every Terminus turn after the first.
  • One worker. Sessions are process-local, so the agent refuses to seed a session when num_workers is not 1 (a 422, so the environment server records a terminal seed failure instead of retrying), and the generated run config pins it to 1. With 4 workers, 50 of 89 episodes were dropped with 404 unknown session.
  • CLI. gym eval run --agent NAME refuses ambiguous short names. terminus_2 and hermes each match two harnesses, so the full folder name is needed. _sandboxed_agent is accepted as a suffix. The README and the error text now show --agent hermes_agent.
  • Task tools. The seed response declares supports_task_tool_context (default false). The Harbor environment server refuses a task that declares [[environment.mcp_servers]] or skills_dir to a harness that did not declare support, as a terminal stage: agent failure, instead of scoring a silent zero.
  • Harness trajectory. AgentCloseSessionResponse.trajectory carries the harness's own turns. The Harbor and generic single agent turn environment servers forward it on the result (ng_trajectory) and on failures (SingleAgentTurnFailure.trajectory), so saved rows keep decision history and command-batch counts instead of rebuilding turns from every captured model call.

Review fixes (2026-10-04)

  • Infrastructure failures are masked. A model endpoint that never answers (connection errors, exhausted retries, 5xx or 401/403/408/425/429 after retries) raises a 502. A sandbox that cannot run a command, or a cancelled run, raises a 503. The environment server records those episodes as masked failures instead of verifying an unmasked zero. Completed runs, step-limit runs and timeouts are still verified. The response metadata carries terminus2_outcome, terminus2_completed and the error type.
  • Task timeout. The row's [agent].timeout_sec bounds the run when it is shorter than the configured sandbox_timeout. Non-numeric values are ignored with a warning.
  • Legacy /run. On an infrastructure failure the owned-sandbox path stops its sandbox and re-raises the 5xx.

Validation

  • pytest responses_api_agents/terminus_2_sandboxed_agent/tests runs in the server venv; CI's server suite passes at 14e4586.
  • pytest environment_servers/harbor/tests environment_servers/single_agent_turn/tests responses_api_agents/harbor_oracle_agent/tests tests/unit_tests/test_agent_sessions.py tests/unit_tests/test_cli_main.py tests/unit_tests/test_global_config.py tests/unit_tests/test_harbor_tasks.py tests/unit_tests/test_harbor_validation.py tests/unit_tests/test_rollout_collection.py tests/unit_tests/test_add_legacy_agent_environment_servers.py: 1423 passed at 14e4586 (reviewer rerun).
  • ruff check and ruff format --check clean on the changed files at the rebased head. pre-commit run --files <changed files> was clean before the rebase.

Rollouts

Exercised by the TB2.1 parity run in the M8 PR of this stack: 88 of 89 tasks completed through this agent on x86 OpenSandbox, 72 passed, against 70 of 89 on the existing terminal_bench_2_1 server. See that PR for the tables. Those runs predate the move to the environment server, the infrastructure-failure fix and the trajectory forwarding above.

Compatibility and benchmark impact

The benchmarks/terminal_bench_2_1 configs are unchanged. The legacy /run path changes only on infrastructure failures, where it now stops its sandbox and returns a 5xx instead of a verified zero. The id change affects only replayed history items. --agent hermes and --agent terminus_2 now need the full folder name.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Sep 28, 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.

@adil-a
adil-a added this pull request to stack #3678 September 28, 2026 17:56
@adil-a adil-a changed the title adasif/harbor m7 terminus sessions feat(terminus-2): episode sessions on the resources server sandbox (M7) Sep 28, 2026
@adil-a
adil-a force-pushed the adasif/harbor-m7-terminus-sessions branch from f085217 to 53b9079 Compare September 28, 2026 19:35
@adil-a
adil-a removed this pull request from stack #3678 September 28, 2026 19:35
@adil-a
adil-a added this pull request to stack #3733 September 28, 2026 19:36
@adil-a
adil-a force-pushed the adasif/harbor-m7-terminus-sessions branch 2 times, most recently from 4cb0110 to 856ecb5 Compare September 28, 2026 23:53
@adil-a
adil-a force-pushed the adasif/harbor-m7-terminus-sessions branch from 856ecb5 to b2d3e93 Compare September 30, 2026 03:48
@adil-a
adil-a removed this pull request from stack #3733 September 30, 2026 03:50
@adil-a
adil-a added this pull request to stack #3806 September 30, 2026 03:51
@adil-a
adil-a removed this pull request from stack #3806 September 30, 2026 04:12
@adil-a
adil-a added this pull request to stack #3808 September 30, 2026 04:12
@adil-a
adil-a force-pushed the adasif/harbor-m7-terminus-sessions branch from b2d3e93 to 8650709 Compare October 4, 2026 23:19
@adil-a
adil-a force-pushed the adasif/harbor-m7-terminus-sessions branch from 8650709 to 32282f0 Compare October 9, 2026 20:08
@adil-a
adil-a force-pushed the adasif/harbor-m7-terminus-sessions branch from 32282f0 to f53cfde Compare October 9, 2026 20:20

@yuhezhang-ai yuhezhang-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.

Thanks for the session integration. I found three additional error-handling gaps and one nonblocking diagnostic issue, detailed below.

@adil-a
adil-a removed this pull request from stack #3808 October 14, 2026 00:54
@adil-a
adil-a added this pull request to stack #4583 October 14, 2026 00:55
@adil-a
adil-a force-pushed the adasif/harbor-m7-terminus-sessions branch 2 times, most recently from f5d2d44 to e22da26 Compare October 14, 2026 01:33
@adil-a
adil-a force-pushed the adasif/harbor-m7-terminus-sessions branch from 5f5c6e8 to 3f0134b Compare October 20, 2026 00:20
@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3f0134b

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1a4d594

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test fa2e823

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3fd902c

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Status at the new head 3fd902c. Every thread from the 9 Oct and 15 Oct reviews has its reply inline, so one pointer each: the task MCP servers and skills refusal (supports_task_tool_context, a 422 before the turn), the close carrying the run's observations and now the harness trajectory too (AgentCloseSessionResponse.trajectory, with test_session_decisions_survive_saved_projection as the saved-output regression), the 422 for sessions with several workers, the bounded model client that raises ModelUnreachableError instead of running to the deadline, the narrowed infrastructure status set so a bare 500 is scored, structured sandbox failures as 503, completion on the last turn told apart from step_limit, the template contract restored (resources_server in the shipped YAML, null only on the generated instance), and session activation deduplicated and joined before close.

From the rebase: main's try/finally sandbox release and checkpoint helpers in base_responses_api_agent.py were kept, and the sandboxed harnesses now declare calls_model_from_sandbox on their class. Terminus 2 deliberately does not, since it calls the model from its own process, which is what your P3 on #3675 asked for.

@yuhezhang-ai

Copy link
Copy Markdown
Contributor

Thanks for the fixes. The other 11 review threads are resolved; one remaining item is detailed here: preserve decision history and command-batch counts in saved failure records, with a regression test. I reopened the existing thread for that final fix.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test debf3c6

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2d50b93

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 14e4586

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

The reopened thread is fixed at head 14e4586. SingleAgentTurnFailure now carries the trajectory, the Harbor environment server and the generic single agent turn server set it on the agent error, verification and deadline failures, and the failures sidecar row keeps it, so saved failure records preserve the decision history and command-batch counts. The regression test is in responses_api_agents/terminus_2_sandboxed_agent/tests/test_observability.py and the thread has the detail.

ffrujeri
ffrujeri previously approved these changes Oct 21, 2026

@ffrujeri ffrujeri 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.

Approving 14e4586e. All review threads are resolved, including the reopened failure-record one: the trajectory now rides on SingleAgentTurnFailure and reaches the failures sidecar. I checked the one-activation session (an identical retry joins the shielded task, a different body gets a 409, close owns cancellation), the task tool-context refusal, and the bounded model client: 429 and 503 are still waited out under max_rate_limit_wait_seconds, and only refused connections and gateway errors surface within about 10 s. Harbor, single agent turn, Oracle, sessions, CLI and rollout-collection suites pass locally (1423 passed); the Terminus 2 suite passes in CI's server shards. Title and body updated to the environment-server layout.

yuhezhang-ai
yuhezhang-ai previously approved these changes Oct 21, 2026

@yuhezhang-ai yuhezhang-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.

Approving 14e4586e as part of the Harbor stack. The existing review requests are addressed, including failure-record trajectory support here and Harbor's forwarding in #4663, included through #4664.

Rechecked 65 focused repository tests and 3 independent failure-projection probes; all passed. The probes preserved the original decision references and nonzero command-batch counts. Model and sandbox operations were faked; no fresh real-model rollout was run in this review.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 256239b

ffrujeri
ffrujeri previously approved these changes Oct 21, 2026

@ffrujeri ffrujeri 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.

Re-approving 256239b2 after the restack. The only patch change against the approved 14e4586e is the test_harbor_tasks.py adjustment for #3675's absolute_ip_server_types. Stack tests pass locally; CI was still running at approval time.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7c1f173

…x (M7)

M7 of the Harbor tasks RFC. `terminus_2_sandboxed_agent` gains episode sessions that borrow
the environment server's sandbox over `SandboxAccess` and disconnect on close, alongside the
existing owned-sandbox path. Model calls carry the episode's rollout id. Infrastructure
outcomes (model unreachable, sandbox lost, cancellation) fail the request with a 5xx so the
episode is recorded as a masked failure instead of an unmasked zero; timeouts and step limits
are still verified. The task's `[agent].timeout_sec` from the row metadata bounds the run
when it is shorter than the configured budget. Replayed history items get well-formed ids.

Session state is process-local: the generated Harbor run config pins the harness to one
worker and the agent refuses to seed a session otherwise. The agent serves sessions through
the base hooks (main's session contract).

The harness's `resources_server` reference is now optional, as it already is for Hermes and
mini-SWE: only the legacy `/run` route seeds and verifies through a resources server, and it
answers 422 without one. Episode sessions get their sandbox from the environment server.

`gym eval run --agent NAME` refuses ambiguous short names: `hermes` and `terminus_2` each
match two harnesses, so the caller picks the full name.

Squashed from the previous branch and re-applied onto the environment server.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9b5e539

@ffrujeri ffrujeri 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.

Re-approving 9b5e5392 after the restack onto main. Against 256239b2, the patch only drops the num_workers=1 422 change, which #3905 made moot on main by removing that restriction; the rest is context from main.

@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/39680939231

This branch was previously deployed

1 inactive deployment
public — 9b5e5392 Deployed Oct 21, 2026 by copy-pr-bot[bot] via release / finalize / notify #6384
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 complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer QA_verified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants