Skip to content

feat(harbor): turn_sessions, resume the agent across a task's steps (M34 follow-up) - #4998

Merged
adil-a merged 2 commits into
adasif/harbor-m34-step-featuresfrom
adasif/harbor-m34-turn-sessions
Oct 28, 2026
Merged

adil-a merged 2 commits into
adasif/harbor-m34-step-featuresfrom
adasif/harbor-m34-turn-sessions

Conversation

@adil-a

@adil-a adil-a commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Felipe's gap 5 / Adil's item 8 from the Harbor runtime review: resume across steps, Harbor's --resume-trajectory, at the run level. New Harbor environment server setting turn_sessions: fresh | continue (default fresh, Harbor's resume_trajectory = false), set per run as a Hydra override, never in task.toml, exactly where Harbor keeps it (a job or trial AgentConfig field).

Under continue a [[steps]] task's first turn seeds one multi-turn continuation session (the agent-session contract's resume_harness_session mode) and every later turn is the next activation of it, named in the x-ng-agent-activation header, so the agent keeps its conversation across steps. Each step keeps its own instruction and [steps.agent].timeout_sec, is verified on its own between activations, and stops the episode as in fresh mode. The session is closed once after the last turn (or the early stop), before that step's verifier, and its observations and cumulative trajectory become the episode's ng_agent_observations and ng_trajectory; a failure that ends the episode on an intermediate step closes the session first and carries the same evidence. The result reports turn_sessions.

Default fresh runs are not untouched: a multi-step task whose agent ran on more than one step now leaves the episode-level ng_trajectory and ng_agent_observations empty, while each step's own record stays on its turn (turns[].trajectory, turns[].agent_observations), one per step as Harbor keeps one steps/<name>/agent/ per step. A single fresh session still fills the episode-level slots, and continue fills them with the whole session's record. The tradeoff (several per-step records versus one merged episode record) is tracked in #5063.

The run is refused before any sandbox when the harness cannot continue a session, as Harbor's MultiStepTrial._validate_resume_support fails resume_trajectory fast for an agent without SUPPORTS_RESUME: a new base-agent route GET /v1/agent_sessions/capabilities declares the task-tool context and the continuation capabilities a seed would confirm, without seeding; the environment server asks it once per process. An agent server built before the route (404) is treated as declaring none. Only opencode_agent declares continuation today; Codex and Claude Code adapters are follow-ups (Harbor's resume-capable agents: Claude Code, Codex, Gemini CLI, Copilot CLI, Aider, Goose, Cortex Code).

Commits:

  1. feat(agent): declare session capabilities without seeding — AgentSessionCapabilitiesResponse and the GET route on SimpleResponsesAPIAgent, test in test_agent_sessions.py.
  2. feat(harbor): turn_sessions, one continued harness session across a task's steps — the env server (_open_agent_session / _activate_agent_session / _close_agent_session / _route_failed_response split out of _agent_turn, the continue path in _run_turns, the pre-flight), result field, fake-client support, seven multi-turn tests, README and the Fern multi-step page ("Resuming the agent across steps").

Harbor parity check (Harbor 0.22.0 trial/multi_step.py, trial/trial.py, agents/installed/base.py)

Harbor under resume_trajectory This server under turn_sessions: continue
Job/trial AgentConfig.resume_trajectory, CLI --resume-trajectory; never task.toml Server config turn_sessions, Hydra override per run; never task.toml; test_server_config_holds_only_deployment_settings keeps it a deployment setting
_validate_resume_support: refuse before any environment spend when not agent.SUPPORTS_RESUME; no-op when len(steps) <= 1 _require_turn_continuation before _seed (no sandbox created); skipped for one step; tests created == []
_step_resumes(index): step 1 runs fresh, steps ≥ 2 call agent.resume on the same native session Step 1 seeds the continuation session, steps ≥ 2 are activations 2..n of it (activation_headers() == ["1","2","3"])
Each step keeps its own instruction and _step_agent_timeout_sec Each activation sends the step's instruction with its agent_timeout_sec metadata (harness reads it per activation)
_prepare_step resets shared verifier dirs before every step; _reset_agent_logs_for_step(resume=True) keeps the agent dir (session state) _prepare_turn unchanged: /tests, /logs/verifier and the server's own ATIF export cleared; the harness's session state is its own and untouched
Step verifier runs after each step; min_reward, missing reward, step exception stop the trial; roll-up multi_step_reward_strategy Unchanged; an early stop closes the session before the result (test_an_early_stop_closes_the_continued_session_before_the_result)
Per-step [steps.agent].user still applied around a resumed agent (relaunched as that user) Refused up front: a live harness session runs as the user it was seeded with (documented divergence, conservative)
Resumed agent process has exited between steps and is relaunched with the next instruction The continued harness's process has exited between steps too: an activation returns to Gym only once the process it launched has stopped (OpenCode's awaits SandboxSession._finish()). What the session retains across every step's verifier but the last's is its conversation state on disk in the sandbox and the borrowed connection the next activation reuses, both let go at close. Task-owned background services (an ENTRYPOINT, a Compose service, a process a turn left behind) are not stopped between steps in either mode (documented)
_archive_step_outputs(preserve_agent=True) copies rather than moves the agent dir between resumed steps Bookkeeping of Harbor's trial directory; no equivalent needed (observations and trajectory arrive once at close)
user_agent (ACP bridge) refused for multi-step trials Not in scope (left open per Adil)

Validation

Run on the login node from a git-archive copy (-n 2, the stack's rebase venv with Harbor 0.22.0):

  • environment_servers/harbor/tests + responses_api_agents/harbor_oracle_agent/tests + tests/unit_tests/test_agent_sessions.py (-k "not partial_eval and not buildah and not validate_ and not real_image and not test_verifier_filesystem"; the filesystem tests need a writable /tmp, which this node's sandbox denies): 563 passed.
  • responses_api_agents/opencode_agent/tests (the one adapter with continuation; the base route is a pure addition): 527 passed, 16 skipped. Codex, Pi and Hermes suites collect cleanly (370 / 346 / 178).
  • ruff check / ruff format --check: clean.
  • New tests: test_the_capabilities_route_declares_continuation_without_seeding (base agent); in test_multi_turn.py: one session asked for continuation and seeded with the first step's budget, activations 1,2,3 with each step's instruction and budget, one close after the last turn, every step graded between activations, the session's evidence on the result and none on the turns, capabilities asked once before any sandbox; refusal before any sandbox for a harness declaring none and for an agent server without the route; single-step task and fresh mode untouched; early stop closes the session; steps switching the agent user refused; a classified failure of a continued turn closes the session for its evidence then ends the episode ungraded.
  • No live run yet: a real continue rollout needs OpenCode on OpenSandbox and the compute node (the login node is not for that); planned on the next job alongside the Harbor-side comparison (harbor run --resume-trajectory with Claude Code on the same two-step task).

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 23, 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 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ef299ec

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 23, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 23, 2026 16:55
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

@adil-a

adil-a commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 167a7a0

@adil-a

adil-a commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9bacce4

@adil-a

adil-a commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c883d3d

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 69cd360

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f8a5b9c

ffrujeri
ffrujeri previously approved these changes Oct 26, 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.

LGTM, thanks.

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 92aa104

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 479f4ee

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4945269

ffrujeri
ffrujeri previously approved these changes Oct 26, 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.

LGTM.

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b6e39ae

@adil-a

adil-a commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9439797

@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 fixing the final-step close ordering. I reproduced two remaining cases on 9439797b1: a constant-user task is rejected under continue, and an intermediate verifier failure loses evidence that cleanup subsequently retrieves. The inline comments describe both; the test and documentation suggestions are nonblocking.

One small PR-description clarification: default fresh runs with multiple sessions now leave episode-level ng_trajectory and ng_agent_observations empty, while retaining per-step records. #5063 explains the intentional tradeoff, but the current “fresh mode untouched” wording should call out the impact on consumers of those episode-level fields.

Validation here used local fixtures; a live continued rollout remains untested.

Comment thread environment_servers/harbor/app.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1f33365

@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f690c35

@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a32c826

ffrujeri
ffrujeri previously approved these changes Oct 27, 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.

LGTM.

yuhezhang-ai
yuhezhang-ai previously approved these changes Oct 27, 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.

LGTM, thanks for addressing the constant-user and intermediate-verifier evidence issues, and strengthening the tests and documentation. The focused regression checks pass. End-to-end RL testing on main, with any resulting fixes in separate PRs, remains the agreed follow-up.

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

@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cb737a3

yuhezhang-ai
yuhezhang-ai previously approved these changes Oct 27, 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.

LGTM. Rechecked against the current stack base: both PR commits are unchanged by the rebase, the earlier correctness fixes remain in place, and all 15 focused regression checks pass on this head. End-to-end RL testing on main, with any resulting fixes in separate PRs, remains the agreed follow-up.

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

@adil-a

adil-a commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 57e3b7d

adil-a and others added 2 commits October 27, 2026 22:04
GET /v1/agent_sessions/capabilities on SimpleResponsesAPIAgent returns what
a seed would confirm (the task-tool context and the multi-turn continuation
this adapter supports) without seeding anything. An environment server reads
it to refuse a run before provisioning: a multi-step task whose turns must
continue one harness session needs continuation, as Harbor's multi-step
trial refuses resume_trajectory for an agent without SUPPORTS_RESUME before
any environment spend. One-activation adapters and agents without sessions
answer with continuation null.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…ask's steps

Harbor's --resume-trajectory (a job or trial AgentConfig field, never
task.toml) makes each step after the first resume the agent's native session.
The server's equivalent is turn_sessions on the Harbor environment server,
fresh (default, one session per step) or continue, set per run as a Hydra
override.

Under continue the first turn seeds one multi-turn continuation session
(resume_harness_session) and every later turn is the next activation of it,
named in the x-ng-agent-activation header, so the agent keeps its
conversation across steps. Each step keeps its own instruction and
[steps.agent].timeout_sec, is verified on its own between activations, and
stops the episode as in fresh mode; the previous turn's grading files are
still cleared before each turn. The session is closed once after the last
turn (or the early stop) and its observations and cumulative trajectory are
the episode's ng_agent_observations and ng_trajectory; per-turn results carry
none. A classified failure of a continued turn closes the session for its
evidence, then ends the episode by the outcome policy. The result reports
turn_sessions.

Refused before any sandbox, as Harbor's _validate_resume_support refuses
before any environment spend: the agent server's capabilities are asked once
per process (GET /v1/agent_sessions/capabilities; a 404 from an older agent
server counts as none) and a harness without continuation fails the run at
stage seed, terminally, naming the setting. A task whose steps switch the
agent user is refused too, since the live session runs as the user it was
seeded with. A single-step task is unaffected (Harbor's flag is a no-op below
two steps). Documented divergence: the harness session stays alive in the
sandbox while each step's verifier runs, where Harbor's resumed agent has
exited between steps.

_agent_turn is split into _open_agent_session, _activate_agent_session,
_close_agent_session and _route_failed_response, which the fresh path and
the continued path share. Only opencode_agent declares continuation today;
Codex and Claude Code adapters are follow-ups.

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

adil-a commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0007bcc

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

LGTM. Rechecked the latest head against the current stack base: both PR commits are unchanged by the rebase, the earlier fixes remain intact, and all 15 focused regressions pass on this head. End-to-end RL testing on main, with any resulting fixes in separate PRs, remains the agreed follow-up.

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

This branch was previously deployed

1 inactive deployment
public — 0007bcce Deployed Oct 28, 2026 by copy-pr-bot[bot] via release / finalize / notify #7749
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers 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.

5 participants