Skip to content

fix(harbor): preserve verifier completion and image startup - #5240

Closed
init-nikhil wants to merge 3 commits into
mainfrom
init-nikhil/multi-harness-training-controls
Closed

init-nikhil wants to merge 3 commits into
mainfrom
init-nikhil/multi-harness-training-controls

Conversation

@init-nikhil

@init-nikhil init-nikhil commented Oct 29, 2026 •

Copy link
Copy Markdown
Member
  • Distinguishes incomplete Harbor verification from a genuine reward of 0. Adds optional retries in a fresh verifier sandbox, reusing the same collected agent files.
  • Fixes startup for images with bare-shell entrypoints and preserves task-instruction line endings.
  • Existing behavior stays unchanged unless the completion check is enabled. Reported validation: 729 affected tests and all-files pre-commit passed on the combined stack tree. Current-head runtime validation and CI remain pending.

Depends on #5112.

@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 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.

@init-nikhil
init-nikhil added this pull request to stack #5241 October 29, 2026 00:36
@init-nikhil

Copy link
Copy Markdown
Member Author

Validation checkpoint for ffa05ec4787e5a0c4e09bd1112f33517a387a9a2 (draft; real-model and learning validation still in progress).

Local checks:

  • pre-commit run --all-files: passed, with no remaining tracked changes.
  • Core terminal-attribution, rollout-correlation, and Messages API tests: 176 passed.
  • OpenCode sandbox-session tests: 178 passed.
  • Claude/pi focused sandbox, Messages wire, output-budget, and compatibility tests passed; both recipes admit the eight-task workload.
  • NOOA suite: 384 passed, 8 skipped.
  • Integrated Hermes suite: 342 passed, 6 skipped, on two runs. An earlier worktree-only cleanup fixture timeout was isolated to an intermittently slow fake shell command; production cleanup was unchanged.
  • All six commits have DCO sign-off; git diff --check passed.

Real-model checks use the original N4 SFT7000 model on HSG, with global sampling overrides unset. Each case asks the agent to write a nonce file and report its directory, then independently checks the file, runs the real SWE verifier, repeats verification to test replay, and audits exact-run cleanup. These checks are infrastructure correctness evidence, not benchmark scores.

Harness Temperature Result Captured calls Trainable generated tokens
OpenCode 1 pass 4 457
OpenCode 0 pass 3 395
Claude Code 1 pass 4 491
pi 1 pass 3 375
pi 0 pass 3 213

Every passing case checked top-p 1, an 8192-token harness ceiling against a 16384-token request, disabled compaction/pruning, successful verifier replay, and zero remaining owned sandboxes. Claude/pi T1 used source feec52304; OpenCode T1 used dccfac4df; OpenCode T0 used this head. The intervening commits do not modify the earlier tested Claude/pi paths.

Known remaining gates:

  • Claude T0 completed the task and verifier but was correctly masked because an auxiliary session-title request left a dangling capture intent. A focused runtime fix and rerun are pending; the capture safeguard remains enabled.
  • Hermes and NOOA real-model checks, including NOOA child-terminal attribution, and per-harness learning/contribution checks remain pending.
  • This PR does not establish historical training parity or mixed-harness improvement. The separate running eight-task historical comparison is pinned to the base PR and unchanged.

The metadata-terminal fallback is cherry-picked from the core commit in #5180, with a separate NOOA adaptation to avoid overriding a child-authored terminal answer. No colleague review is requested while these gates remain open.

@init-nikhil

Copy link
Copy Markdown
Member Author

Claude capture follow-up for head 4c346ec21b424233c4f69a22fc08589a8208ebac:

When automatic compaction is disabled, the CLI now receives an explicit session name. This suppresses its background title-generation model request, which previously could outlive the capture proxy and correctly mask an otherwise successful rollout. Capture safeguards remain enabled.

Both real-model reruns passed on original N4 SFT7000 with source 3799ae44887601e66fb517383ba098be0cd9406f (this head plus the five-source adapters in #5242):

Temperature Calls Captured and delivered generated tokens Capture chains Title requests
0 3 358 1 0
1 3 624 1 0

Each case verified top-p 1, the 8192-token harness ceiling against a 16384-token request, disabled compaction, actual file write/read and directory tools, explicit response-ID terminal attribution, real verifier execution, identical verifier replay, and zero remaining owned sandboxes. These are correctness checks, not benchmark scores or learning-parity results.

Validation: 62 focused Claude tests passed; pre-commit run --all-files passed on the integrated stack, and the title-fix commit has DCO sign-off. Hermes/NOOA live checks and learning validation remain in progress. No colleague review requested.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work labels Oct 29, 2026
@init-nikhil
init-nikhil force-pushed the init-nikhil/multi-harness-training-controls branch from 4c346ec to de347eb Compare November 7, 2026 23:47
@copy-pr-bot

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

@init-nikhil init-nikhil changed the title feat(agent): enforce shared harness training controls feat(harbor): preserve SWE completion and retry semantics Nov 7, 2026
@init-nikhil
init-nikhil force-pushed the init-nikhil/multi-harness-training-controls branch from 15abccc to d227a9b Compare November 11, 2026 04:35
@init-nikhil
init-nikhil removed this pull request from stack #5241 November 11, 2026 04:38
@init-nikhil init-nikhil changed the title feat(harbor): preserve SWE completion and retry semantics fix(harbor): preserve verifier completion and image startup Nov 11, 2026
@init-nikhil
init-nikhil added this pull request to stack #5993 November 11, 2026 04:38
@init-nikhil
init-nikhil removed this pull request from stack #5993 November 11, 2026 05:05
@init-nikhil
init-nikhil added this pull request to stack #5994 November 11, 2026 05:06
@init-nikhil

Copy link
Copy Markdown
Member Author

DESCRIPTION FOR AGENTS

Codex-generated description; not a completed review or human approval.

Starting head: d227a9bff8f666c5283b429f4aa1eabfd4f59e2f
Parent: #5112 at 1c13335e745cccdd4f8c10a59e11a4294255dc04

verifier_completion_key optionally requires a reward-file metric equal to 1 before accepting a score. Missing or invalid rewards, incomplete execution, and missing completion flags become masked outcomes. Exclude the completion metric from reward calculation. With no configured key, preserve existing missing-reward semantics.

inconclusive_verification_retries defaults to zero. Separate verification can retry masked outcomes in fresh sandboxes using the same captured artifacts. Retain per-attempt outcomes and logs, include retries in timeout allowances, and preserve cleanup ownership when stopping fails. Shared-sandbox verification is not retried.

Bare-shell entrypoints receive a command string through -c; script entrypoints retain their arguments. Instruction loading preserves CRLF and bare-CR line endings after the existing canary removal.

Tests cover measured zero versus incomplete verification, retry bounds, artifact reuse, cleanup failures, completion-metric exclusion, real shell execution, and line endings. Verify the reported 729-test/pre-commit evidence and obtain current-head runtime evidence. Historical comments describe earlier, broader implementations.

Process after #5112. Review this layer against its updated immediate parent, and record all evidence against the final remote head.

@init-nikhil
init-nikhil force-pushed the init-nikhil/multi-harness-training-controls branch from d227a9b to 2a1cfad Compare November 12, 2026 10:43
@init-nikhil
init-nikhil marked this pull request as ready for review November 12, 2026 17:38

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

HOLD

A failed verifier attempt can supply a later retry's reward through downloaded diagnostic files, producing a false completed score. The inline findings also cover bare-CR instruction loss, a deterministically failing endpoint assertion, missing multi-turn completion status, and configuration documentation.

RISK — Supply current-head model/sandbox smoke evidence

The PR description explicitly leaves current-head runtime validation pending. The historical rollout comments concern earlier heads and don't establish that the changed completion/retry path works with a real provider. The reported 729 tests and pre-commit checks don't replace the representative model rollout required by AGENTS.md.

Please attach representative model/sandbox rollout evidence for the final head, inspecting the agent's output and verifier behavior. Exercise the separate-verifier retry path with the completion key enabled: an incomplete first attempt followed by a completed measured zero should return reward 0, mask_sample=False, and evaluation_completed=True, with distinct verifier sandboxes, identical captured artifacts, retained attempt logs, and confirmed cleanup. Also retain a control with the completion key unset: a missing reward remains a measured zero rather than becoming masked. Record the configuration, model/provider, source revision, results, and artifact locations. These are acceptance checks to perform, not results established by this review.

I inspected all eight changed files and their directly affected scoring, lifecycle, deadline, loading, and endpoint paths. All three delegated inspections terminated; I independently covered the retry/lifecycle topic because its detailed report wasn't available. This was a static review: I couldn't execute tests, pre-commit, runtime rollouts, or CI. Suggested code needs verification before adoption.

Note: formal approval is not available for this request, so this review is posted as a comment only.


Inline comments (escaped v1):

  • environment_servers/harbor/verifier.py line 685: BLOCKER — Reserve retry logs outside the previous attempt's downloaded output

    With one retry enabled, let the first verifier write an incomplete root reward and a diagnostic retry-1/reward.json containing {"reward":1,"evaluation_completed":1}. The optional log download extracts that subdirectory into the first attempt's host logs. This branch then reuses it with exist_ok=True. If the fresh second verifier exits normally without writing a reward, collection leaves the existing reward file untouched and parses the first attempt's diagnostic as the second attempt's result. The episode incorrectly returns reward 1, unmasked and completed. A diagnostic regular file named retry-1 instead makes mkdir() raise and loses the graded result.

    Each attempt's reward directory must be fresh and outside every previous attempt's extraction root. Both production callers already reserve the initial directory, and attempt records carry each directory explicitly, so replace these two lines with:

                    attempt_logs = logs_dir if attempt == 0 else self._reserve_logs_dir()
    

    This preserves the initial artifact staging directory and archive reuse while giving each retry an independently reserved directory.

    Proposed regression: extend the existing fake-verifier setup with the nested diagnostic above, followed by a verifier with no reward. Expect both attempts masked, final reward 0 and completion false—not the planted success. Repeat with a regular diagnostic file named retry-1; verification must still return a bounded masked result. Retain the existing completed-zero/no-retry assertions and artifact-reuse and cleanup assertions. Source reasoning only; I haven't executed these checks.

  • nemo_gym/data/tasks/harbor/task.py line 388: RISK — Preserve canary stripping for bare-CR instructions

    Reading bytes preserves CRs, but splitting only on LF stops recognizing bare-CR line boundaries. For example, b"# HARBOR-CANARY marker\r\rDo the thing.\r" becomes one string. _CANARY_LINE matches the entire heading-prefixed string, so read_instruction() returns an empty prompt. An HTML canary with the same separators instead remains in the prompt. Previously, text-mode newline conversion removed only the canary and separating blank line. This affects both single-step loading and step loading.

    Recognize LF, CRLF, and bare CR without translating retained terminators. Replace this read with:

    with path.open(encoding="utf-8", newline="") as stream:
        lines = stream.readlines()

    Keep the existing removal loops and change the final return to return "".join(lines).

    Proposed acceptance: heading and HTML bare-CR canaries followed by \r\rDo the thing.\r must return "Do the thing.\r"; multiple leading canaries must still disappear. Retain all existing instruction assertions, including mixed CRLF/CR preservation and leading blank lines when no canary exists. The suggested correction is source-reasoned, not executed.

  • environment_servers/harbor/tests/test_app.py line 298: RISK — Assert terminal attribution where Harbor serializes it

    The new terminal_id="served-response" case supplies the ID under the agent response's metadata, but these assertions read the episode result's top level. Harbor constructs the result with response=agent_response; neither its result model nor the parent contract promotes that metadata field. Consequently, the added case compares None with "served-response" and fails despite a successful endpoint response.

    Unless a separate top-level API is intended, replace these assertions with:

            metadata = payload["result"]["response"].get("metadata") or {}
            assert metadata.get("terminal_response_id") == terminal_id
            assert ("terminal_response_id" in metadata) is (terminal_id is not None)
    

    Acceptance: both parameter values return HTTP 200 and reward 1; the supplied ID survives under result.response.metadata, while the absent case doesn't manufacture one. Retain the episode-identity, sandbox-handle exclusion, and cleanup assertions. I haven't executed this test.

  • environment_servers/harbor/app.py line 488: RISK — Propagate completion status through the multi-turn roll-up

    Enable verifier_completion_key="evaluation_completed" for two steps. If their verifiers write {"reward":1,"evaluation_completed":1} and {"reward":0,"evaluation_completed":0}, the second turn correctly reports completion false and masks the episode, but this roll-up omits the completion field. The episode constructor leaves the new top-level field at None, so serialization removes it. Fully completed multi-turn episodes also omit True. The mask still protects the scalar score; callers lose the configured completion-status contract.

    Propagate status in roll_up_turns() or _run_turns(): completion-gated episodes must report false for an incomplete verifier and true when every executed verification completed. Preserve absence for legacy turns whose status is None; don't derive their completion solely from not mask_sample. Keep the existing measured treatment of later step-preparation failures. Their completion-status meaning needs an explicit decision, so a blanket replacement patch would be premature.

    Proposed checks, for both mean and final: the incomplete second turn yields top-level completion false, mask true, and reward 0. Two completed turns, including a measured zero, yield top-level completion true with unchanged rewards/components. With the gate disabled, retain absent status and the existing missing-reward scoring and preparation-failure assertions. These checks weren't executed.

  • environment_servers/harbor/app.py line 383: NOTE — Suggest documenting the opt-in completion and retry contract

    These switches change whether missing/invalid rewards and timeouts count as measured zeros, but the configuration table lists neither option, and the verifier guide states the measured-zero rule without this exception. Users can't discover the required reward shape or scoring effect there.

    Add a minimal configuration example for verifier_completion_key and inconclusive_verification_retries, their defaults, and {"reward":0,"evaluation_completed":1} as a completed measured zero. Explain completion-metric exclusion, masking, fresh separate-sandbox retries using captured artifacts, and the lack of shared-sandbox retries. Keep the existing reward-file and timeout rules as the default when the completion key is unset.

    Acceptance is a documentation inspection: both keys and their limits appear in the configuration guide, and the verifier guide distinguishes completed zero, incomplete verification, and disabled-contract behavior. No documentation build was executed.

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

@zyzhou5
zyzhou5 self-requested a review November 12, 2026 18:43

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

Pls update the pr description and also the harbor doc for the new settings (verifier_completion_key, inconclusive_verification_retries).

Also during my own test, harbor path requires reproducing the resources server's seed-time init (removing the hidden tests, creating the git baseline commit, the anti-cheat scrub, and setting the git identity) so it is comparable to gym resource server path. Is this sth we want to include here?

# Optional reward.json metric that must equal 1 before a score is usable. A missing
# metric/reward or verifier timeout is inconclusive when this contract is enabled.
# Unset preserves Harbor's measured-zero behavior for missing/invalid rewards.
verifier_completion_key: str | None = Field(default=None, min_length=1)

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.

Should we turn on/off completion check per dataset instead of at server level so that it can work appropriately no matter whether evaluation_completed is there in test.sh?

extras["verifier_logs_dir"],
)
completion_key = self.config.verifier_completion_key
if completion_key is not None and (

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.

With the completion check on, any kill at the time limit excludes the attempt, even if the grader had already finished and written evaluation_completed: 1. Could we treat it as a timeout only when no completed result was written?

"verifier_logs_dir": str(attempt_logs.resolve()),
}
)
if not outcome.get("mask_sample", False):

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.

Retries currently rerun every excluded attempt, including timeouts and missing/invalid result files, which a fresh sandbox won't fix. Could we retry only sandbox/provider failures, as upstream Harbor do?

# The episode key stays reserved until the episode's final cleanup, which releases it without
# stopping the agent side again.
await session.stop_agent_side()
self._write_cleanup_receipt(logs_dir, "agent", session.sandbox)

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.

Nit: this receipt is only written after stop_agent_side() succeeds, so it always reports a confirmed teardown; a failed stop leaves no receipt.

if _verifier_gets_overlay(task, separate):
budget += task.config.environment.build_timeout_sec
retry_budget += task.config.environment.build_timeout_sec
budget += self.config.inconclusive_verification_retries * retry_budget

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.

Nit: retries grow the task budget here, but a single-step episode's overall deadline stays at the default (L878-L879), so with long grading times a retry can run past it and fail the episode. Not sure if this is a problem we need to fix or just document.

"""Retry an inconclusive verdict without recapturing the stopped agent's artifacts."""
attempts: list[dict[str, Any]] = []
try:
for attempt in range(self.config.inconclusive_verification_retries + 1):

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.

Nit: retries now reach the "previous turn's verifier sandbox could not be stopped" message (L760) for single-step tasks too, where it means the previous attempt.

@github-actions github-actions Bot added the sla:author-overdue Author response is over the one-business-day SLA label Nov 16, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the blocked Work cannot move forward until an external dependency is cleared label Nov 16, 2026
Base automatically changed from init-nikhil/shared-opencode-training to main November 17, 2026 18:05
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 blocked Work cannot move forward until an external dependency is cleared feature New capabilities, enhancements, or enablement work sla:author-overdue Author response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants