Repository navigation
Conversation
|
/claude review |
|
SHIP — solid, well-tested reliability fix. One NOTE inline; nothing blocking. The core change is correct:
No async-HTTP, |
|
/ok to test bbc003e |
bbc003e to
c132548
Compare
c132548 to
439bd44
Compare
439bd44 to
cb2074f
Compare
|
@sdevare-nv can you please review this? |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE — three RISK defects and one RISK validation gap.
RISK — Required real-rollout evidence is missing
The supplied PR description and discussion contain no representative model rollout evidence. This changes episode completion and sample masking in a wrapper used for training and SWE-bench evaluation. The added tests use synthetic processes or mocked responses; they don't validate the real harness-to-verifier path. AGENTS.md requires representative real rollouts for behavior-changing agent work. The review rubric also requires before/after reward evidence for fixed-evaluation reward changes.
Correction: Record the commands, model, task IDs, revisions and rollout artifact references in the PR description. Inspect the extracted patch, trajectory, verifier result and returned failure fields. For fixed SWE-bench evaluation, include a matched base/head comparison with rollout count, aggregate reward, mask count and explanations for changed outcomes. Training-only validation doesn't require a full reward profile, but still requires representative model rollouts.
Preservation and acceptance: Show that a rescued completed episode receives the same patch grade as its cleanly exiting counterpart; an ordinary wrong patch remains reward 0 and unmasked; and a confirmed infrastructure failure carries the expected failure kind and is masked. Retain the documented resolved-only masking of iteration/context-limit errors. These are proposed checks, not executed results. The gap leaves the real integration and intended score changes unvalidated; it isn't evidence of a runtime failure.
I reviewed both changed files and traced the affected subprocess, output-copy, metrics and response paths. The historical timeout/OOM taxonomy concern is fixed in the current source. This was a static review; I didn't execute tests or rollouts. The external harness checkout isn't mounted, so I couldn't independently verify its completion-marker emission order or its failure-origin signals.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| complete_pred_files.append(pred_file) | ||
| except (OSError, orjson.JSONDecodeError): | ||
| continue | ||
| if complete_pred_files: |
There was a problem hiding this comment.
RISK — Validate the prediction that will actually be returned before killing its writer.
Failure / blast radius: With two matching outputs, let an older prediction be complete and the newest prediction still be partial. This branch accepts the older file and kills the container, but the later selection returns the newest file regardless of completeness. The consumer then fails to parse it. Before this rescue path, the writer could finish before selection. Multiple matching outputs are explicitly supported by the existing selection contract.
Correction: Select the newest candidate before validating it, wait for that candidate, and retain its path for the return. The invariant is that the rescued prediction returned to the caller is the same newest prediction validated before termination. Initialize rescued_pred_file: Optional[str] = None, then replace the readiness block through its successful break with:
pred_files = glob.glob(command.expected_file_pattern, recursive=True)
if pred_files:
pred_file = max(pred_files, key=os.path.getmtime)
try:
orjson.loads(Path(pred_file).read_text().strip())
except (OSError, UnicodeDecodeError, orjson.JSONDecodeError):
pass
else:
await self._terminate_lingering_process(active_command)
terminated_after_completion = True
rescued_pred_file = pred_file
breakAfter the existing watchdog/nonzero-exit guards, return rescued_pred_file when it isn't None, before re-globbing. Leave ordinary completion and eval-mode selection unchanged. This suggestion wasn't executed; verify it before adopting it.
Preservation / acceptance: Add a proposed regression with an older complete prediction and a newer partial prediction that finishes after several polls. Expect no early kill, then return and successfully parse the newer prediction. With two complete files, still return the newest. Retain the "output2.json" in result assertion in the existing multiple-file test, and retain the complete, delayed and missing-output rescue cases, including their process-termination assertions.
There was a problem hiding this comment.
Fixed. The newest output file is the one checked before the kill, and that same file is returned. The newer_unfinished case covers it: an older complete output beside a newer unfinished one, and the container stays alive until the newer one is complete.
| try: | ||
| orjson.loads(Path(pred_file).read_text().strip()) | ||
| complete_pred_files.append(pred_file) | ||
| except (OSError, orjson.JSONDecodeError): |
There was a problem hiding this comment.
RISK — Let incomplete UTF-8 writes use the output grace window.
Failure / blast radius: The new polling read decodes the file before parsing JSON. If a write currently ends inside a multibyte character—for example b'{"patch":"\xe2\x82'—Path.read_text() raises UnicodeDecodeError, which this handler doesn't catch. Instead of waiting for the writer, _finish_container_command exits, closes the log and cancels the watchdog without terminating the agent. The caller's error path kills only the eval command. This affects partial prediction writes containing non-ASCII text; the added delayed-write case starts from an empty file and doesn't cover it.
Correction: Include decoding failures among transient readiness failures:
| except (OSError, orjson.JSONDecodeError): | |
| except (OSError, UnicodeDecodeError, orjson.JSONDecodeError): |
The invariant is that incomplete prediction content waits within the existing grace/deadline bounds rather than abandoning supervision. Verify the suggestion before adopting it; it wasn't executed.
Preservation / acceptance: Add a proposed case to the rescue test that writes an incomplete UTF-8 sequence, then completes valid JSON before the grace expires. Expect the output path to be returned and the process to be terminated, without an early decoding exception. Permanently invalid encoding should reach the existing incomplete-output grace failure and terminate the process. Retain the ASCII complete/late cases and bounded missing/malformed-output failure behavior.
There was a problem hiding this comment.
Fixed. A decode error counts as not ready yet. The cut_multibyte case covers it: a write cut inside a multi-byte character, completed later.
| metrics.failure_kind = PROVIDER_OOM_KILLED | ||
| metrics.failure_reason = "agent container OOM-killed by the memory watchdog" | ||
| else: | ||
| metrics.failure_kind = AGENT_RUN_ERROR |
There was a problem hiding this comment.
RISK — Establish failure origin before masking every remaining agent-command exception.
Failure / blast radius: This else assigns AGENT_RUN_ERROR whenever the command or output-copy operation raises before the timeout without watchdog OOM evidence. That proves a command failure, not an infrastructure failure. A model action can terminate its own harness—for example, an overly broad process-kill command, which the OpenHands prompt explicitly warns against. Its nonzero exit takes this branch, and the new non-null kind makes _inner_responses mask it. A model-caused failure therefore disappears from training and score calculations instead of remaining a valid zero-reward outcome. The base error path didn't mask these generic failures.
Correction / preservation: Separate evidenced infrastructure failures from policy-caused command/extraction failures in process_single_datapoint. Keep AGENT_RUN_ERROR as a diagnostic if useful, but carry an explicit infrastructure-mask decision and make _inner_responses honor it rather than treating every generic named error as mask-worthy. Preserve the specific timeout/OOM classification and masking branches. The invariant is that a generic exception or nonzero exit alone doesn't invalidate a policy outcome. The external driver isn't mounted, so the exact attribution signal needs confirmation; I can't provide a safe complete patch for that contract.
Acceptance — proposed, not executed: Add a worker-to-response regression for a below-timeout, non-OOM run whose tool terminates its driver: expect reward 0.0 and mask_sample=False. A separately identified infrastructure command failure should remain masked. Retain the worker test's timeout → AGENT_TIMEOUT, watchdog OOM → PROVIDER_OOM_KILLED, and OOM → agent_error_kind="oom" assertions, and check their final responses remain masked. A generic RuntimeError("boom") alone shouldn't establish infrastructure origin. Ordinary wrong patches must also remain unmasked zero-reward samples.
There was a problem hiding this comment.
I've changed this, but not to an unmasked 0 since that defeats the purpose of the PR.
A failed agent command is provider_unavailable only when nothing the model chose had run: no model call was recorded and the request had no replay prefix. Otherwise it is swe_agents:agent_command_failed, which claims neither side, as swe_agents:eval_timeout does.
Both are masked, because nothing was graded: the eval container is killed and resolved is filled in as false. Main masks an agent timeout and an agent OOM for the same reason, and a model action can cause those too.
|
@tdene main now names and masks these failures in |
Co-Authored-By: Jorge Albericio <[email protected]> Signed-off-by: Teodor-Dumitru Ene <[email protected]>
Co-Authored-By: Jorge Albericio <[email protected]> Signed-off-by: Teodor-Dumitru Ene <[email protected]>
944b9d9 to
50ebd66
Compare
The rebase is done, the SWEBenchMetrics failure fields are gone, and the rescue has both fixes you asked for. One part of the masking stays, and can't be dropped: an agent command that kills the harness (nothing is graded, but the reward used to still be 0 instead of masked). It's now masked the same way that a timeout or OOM is. Meanwhile a run that stopped at its context limit (it was graded, the reward should be 0) is not masked; |
|
Rollout evidence (
|
|
I pushed one more commit. When the agent hits its turn limit or its context limit, the patch it left behind is still graded. After this latest commit that grade always counts, whether the patch passes or fails. Before this commit, on this PR, (see table above), only the failing patches counted. A passing patch from a run that hit a limit was still masked. So these runs could lower the score but never raise it. Now both count. The "Iteration limit for agent, passing patch" now gives reward 1. The row is still labelled I'm making this change because in a real SWE RL run it is actually very impactful; iteration limits happen often, and the model is learning better if we allow these successes. |
|
/review reset=true |
Signed-off-by: Teodor-Dumitru Ene <[email protected]>
a95260f to
7469df3
Compare
|
/review reset=true |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE: one RISK remains in generic agent-command failure masking.
I reviewed all six changed files and the connected subprocess, prediction-copy, grading, response and score-consumer paths. The rescue fixes and the symmetric treatment of measured iteration/context-limit rewards held up in focused probes.
Prior findings
comment:4505628082is fixed: rescue validates the newest prediction and returns that same path. A probe confirmed that an older complete output does not terminate a newer unfinished writer.comment:4505628088is fixed: incomplete UTF-8 waits within the grace window. Permanently invalid output reaches a bounded failure and terminates the process.comment:4505628095is still present. The new diagnostic distinguishes post-action command failures, but they are still masked without establishing their origin. See the inline finding.- The broad evidence gap in
review:5817264929is addressed by the author's reported scripted integration runs and real-model OpenHands comparisons in the discussion. The later comment documents the intentional change to count passing limit-terminated patches. I did not independently reproduce those model runs.
The previous review commit 944b9d9c1b14034b3274c08cd018d4fe66a5fabc was not reachable in the admitted sources, so I checked its published findings against the current source rather than comparing commits.
Validation
I relied on this head's successful Lint check, Unit tests / Test and Unit tests / Changed server tests. The changed-server log records 208 AnySWE tests passed and 258 SWE tests passed. I did not rerun those green suites. Build Gym container was skipped. Environment Server compliance (non-blocking) failed with A1/A2 diagnostics about the existing agent run() and missing session interfaces; its publication explicitly says those findings do not block the change.
Local probes ran in 766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:228a16b96df8f925220a7edbff2d7d22317c78fb, the default-branch CI image selected because this head's build was skipped. Imports were rebound to the admitted source; unused gprof2dot rendering was stubbed. The probes exercised rescue, delayed and invalid output, split markers, timeout/OOM precedence, clean-versus-rescued patch handoff, both agents' limit rewards and failure-field propagation. Those controls passed. A base/head subprocess probe reproduced the masking regression below, and my score-consumer probe confirmed that the masked zero is excluded. These used scripted processes and fake sandbox/grader responses, not live OpenHands, Apptainer or model rollouts.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| if metrics.agent_command_failed and not model_acted: | ||
| return PROVIDER_UNAVAILABLE, "The agent command failed before the model acted", True | ||
| if metrics.agent_command_failed: | ||
| return AGENT_COMMAND_FAILED, "The agent command failed after the model acted, and left no output", True |
There was a problem hiding this comment.
RISK: Keep model-caused harness exits as unmasked failures.
Could this branch require evidence of an infrastructure failure before returning mask_sample=True? model_acted currently changes only the diagnostic: both command-failure branches mask the result. The worker's broad exception handler sets agent_command_failed for command and output-copy failures without establishing their origin. A model action can kill its own driver, a hazard the process-management prompt already warns about.
I reproduced this through the worker and public response assembly using a local scripted driver that records a completion, then executes a shell action terminating itself below timeout, without OOM:
base: reward=0.0 mask_sample=false
head: reward=0.0 mask_sample=true failure_kind=swe_agents:agent_command_failed
Commands: /workspace/review-probes/env/venv/bin/python -B /workspace/review-probes/masking-contract-1/probe.py and probe_base.py in the same directory. These substitute local processes for Apptainer and stub dispatch, not real model inference. The score consumer excludes every masked row, so a policy-caused failure disappears from evaluation and training rather than counting as zero. Renaming the diagnostic has not fixed prior finding comment:4505628095.
Correction: Keep the diagnostic, but carry an explicit origin-based mask decision from the worker. Until attribution is available, do not newly mask generic post-action command/copy failures solely because no grade was produced. Preserve confirmed provider-failure masks, existing timeout/OOM handling and the new counting of measured limit-terminated grades. The invariant is that a nonzero exit or absent grade alone does not invalidate a policy outcome.
Acceptance: Add worker-to-response regressions distinguishing a recorded tool action that kills its driver, expecting unmasked reward 0.0, from an attributed provider failure, expecting a masked result. Retain timeout/OOM precedence and resolved/unresolved limit-reward coverage.
There was a problem hiding this comment.
It is intentional that this PR wants these exits to be masked, see my earlier comment here: #2410 (comment)
You say "Preserve confirmed provider-failure masks, existing timeout/OOM handling and the new counting of measured limit-terminated grades." Why does this not fall under the same criterion?
There was a problem hiding this comment.
On the question above: yes, this falls under the same rule. Gym's shared policy scores an agent failure as 0 only when the model is shown to cause it. A failed agent response whose failure kind has no rule is fail, so it is neither verified nor scored (AgentOutcomePolicyConfig.default_action in nemo_gym/agents/agent_outcome.py), and the agent stage defaults to fail as well (nemo_gym/core/outcome_policy.py). The only default count_as_zero is a confirmed OOM in the agent's own sandbox. A command failure after the model acted can come from the model or from the harness, and nothing here tells the two apart, so masking it under its own failure kind matches that rule.
The model_acted split keeps provider_unavailable for failures before the first model call, and masked rows still count as trial failures in the eval health gate (_TRIAL_FAILURE_STATES in nemo_gym/eval/recovery/gate.py), so they are not hidden. What remains is where the rule lives: here it is hard-coded in the agent server, not in the environment server's configurable outcome policy, which the migration issue requested above would cover.
@athitten, if you agree, this thread can be resolved.
ffrujeri
left a comment
There was a problem hiding this comment.
Thanks for the fixes and the rollout evidence. The rescue now checks the newest output, waits on a cut multi-byte write, and stops the container on every path, and each case has a test. Two reward rules change, and the description does not name them: a failed agent command after the model acted is now masked, and a run that reached its turn or context limit now counts, resolved or not. Could the description state both, with their effect on SWE-bench scores and the validation from your comments?
| return AGENT_COMMAND_FAILED, "The agent command failed after the model acted, and left no output", True | ||
| if metrics.agent_error_kind == "max_iteration": | ||
| return AGENT_LIMIT, "The agent reached its maximum number of iterations" | ||
| return AGENT_LIMIT, "The agent reached its maximum number of iterations", False |
There was a problem hiding this comment.
This reverses #2817, which masked every limit run, so SWE-bench scores change for both agents. It matches the shared environment server default, where agent_limit is verified and its reward counts, so the change looks right. @sdevare-nv, since #2817 is yours, do you agree with this change?
|
@tdene this PR adds more episode and reward logic to the This fix does not need to wait for that move. Could you open a tracking issue to move both agents onto agent sessions, with SWE-bench verification in a resources server, and link it in the description? The new reward rules here (the masked command failure and the limit-run change) would then become the environment server's outcome policy, which each run can configure. #6440 (off Ray) and #5015 (shared sandbox layer) cover parts of that move. cc @athitten |
Very fair! My bad, this PR has been open for too long. I myself have stopped using |
This PR contains two fixes.
For the first, the harness will commonly be left running despite the model having finished the episode. This usually happens due to lingering commands. Currently this leads to a long timeout and failure. Rescuing these episodes from the harness allows them to complete early and retrieve rewards for what would otherwise be marked as a failure.
For the second, infra failures are now tagged so that the training backend can choose to mask out their gradients instead of training with them as 0 reward.