Skip to content

fix(agents): keep the typed cause of a failed custom agent run - #5740

Merged
AdamRajfer merged 14 commits into
mainfrom
arajfer/typed-agent-faults
Nov 6, 2026
Merged

AdamRajfer merged 14 commits into
mainfrom
arajfer/typed-agent-faults

Conversation

@AdamRajfer

@AdamRajfer AdamRajfer commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Behaviour. A rollout that fails inside a custom agent kept no typed cause. When a resources server's verify raised (a grader rate limit, a judge error) and the agent let the HTTP error escape, or when a custom agent's own policy call timed out, the saved row ended as a bare agent_run_error with failure_kind null, neither masked nor final, never retried, and the generated answer was lost with the 500. Only SimpleAgent typed these paths. Two more gaps surfaced on the same runs: a benchmark whose data preparation fails deterministically was retried by the job chain, and finish_reason was never recorded for chat-backed Responses calls, so a truncated answer could not be told from a completed one.

Change.

  • The collector types a failed agent run from the outermost non-routing kind on the reply's failure chain, so any agent whose raw /verify or policy failure escapes still yields a typed row (verifier_error, judge_failed, model_policy_response_timeout, ...), SimpleAgent included.
  • CritPt and SciCode verify through verify_with_transport_retry and return the saved answer as a masked row with the verifier error on the cause chain, so recovery regrades instead of regenerating (shared masked_verify_failure helper, the pattern GDP.pdf used inline).
  • A confirmed policy timeout is typed at the base agent.responses boundary; policy_timeout_failure moved to agent_outcome.py and is shared.
  • GDP.pdf no longer turns a failed policy call into a scored zero: only the limits it recognises (size, context window, image count) stay a model zero, a confirmed policy timeout leaves as the shared typed policy-timeout failure, and any other failed call (5xx, 429, 401/403, transport) leaves with its typed model failure, so the row is masked and retried within its budget.
  • A data-preparation failure stops the job chain with a typed reason instead of being retried.
  • Chat-backed Responses models (vllm_model, inference_provider, vllm_model_with_compaction) record the chat finish_reason in the call's execution facts; truncated calls keep max_output_tokens.
  • The OpenAI-compatible model server forwards upstream 401/403/429 with their status and a bounded body instead of a bare 500 (propagate_upstream_http_status_codes, default {401, 403, 429}; empty set restores the old behaviour), so judge and policy failure reasons name the real cause.

Checked. Unit suites plus simple_agent, critpt, scicode, the model servers and gdp_pdf: 20626 passed, 50 skipped; the 11 failures also fail on the base commit (harbor run-summary, locked-env, benchmark listing, opensandbox help, ci_environment). New tests cover the raw-verify typing for a minimal agent, for a judge failure and for SimpleAgent, the typed policy timeout, the preparation stop, the finish reasons, and the upstream status propagation. ruff clean.

Not covered. No live rollout. Out-of-process harness agents (CLI or sandbox clients) still report policy timeouts as the harness sees them; agents that keep a raw raise_for_status on verify get a typed row but still lose the answer, so recovery regenerates for them until they adopt the masked path.

Revert. Revert the branch; nothing else depends on it.

CritPt and SciCode raised the resources server's /verify failure out of /run,
so the HTTP boundary dropped the generated answer and the row ended as an
untyped agent_run_error. Both now use the verify retry helper GDP.pdf already
uses and return the answer as a masked zero typed with the agent route
failure, whose causes keep the verifier error. The masking moves into one
helper shared by the three agents.

Signed-off-by: Adam Rajfer <[email protected]>
A policy request that timed out on every attempt was typed only inside Simple
Agent. For any other agent the responses route reported a generic route
failure, and Collection saved a failed /run as a bare agent_run_error even
when its reply named the cause. The responses route now raises the typed
policy-timeout failure from a confirmed timeout, shared with Simple Agent, and
Collection types the row with the first non-routing kind on the failure chain
of the reply.

Signed-off-by: Adam Rajfer <[email protected]>
The vLLM model turns a chat completion into a Response, which carries a stop
reason only when generation was cut short. Model-call records of completed
calls therefore had no finish reason. The adapter now notes the chat finish
reason with the call's execution facts, and the record uses it after the
reasons the payload itself reports.

Signed-off-by: Adam Rajfer <[email protected]>
Pins that Collection types the row of a failed /run from the resources
server's failure chain for an agent that lets raise_for_status escape on
/verify, for verifier_error and judge_failed, and for Simple Agent's own
verify call.

Signed-off-by: Adam Rajfer <[email protected]>
A preparer that fails in its own code or environment (a missing module, say)
exited the driver with a traceback and status 1, so the chain queued a
follow-up that failed the same way. The failure is now a typed stop,
environment_prepare_failed: the CLI exits 76 with an EVAL STOPPED message and
records the kind, and the next segment's guard ends the chain with the remedy,
as it does for rejected credentials.

Signed-off-by: Adam Rajfer <[email protected]>
…onses model

The inference provider and the context-compaction vLLM model convert a chat
completion into a Response like the vLLM model does, and their model-call
records of completed calls also had no finish reason. All three now note it
through one helper, so a completed call records stop or tool_calls and a
truncated one keeps max_output_tokens.

Signed-off-by: Adam Rajfer <[email protected]>
… call

The OpenAI-compatible model server answered every provider error it had not
been told to forward with a bare 500, so a judge behind it reported
"500 Internal Server Error" when the provider had rejected the credential.
It now forwards 401, 403 and 429 with the provider's body by default (an empty
propagate_upstream_http_status_codes restores the old behaviour), and a failed
judge call puts the reply's bounded body in its failure reason. Failure kinds
are unchanged.

Signed-off-by: Adam Rajfer <[email protected]>
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Signed-off-by: Adam Rajfer <[email protected]>

# Conflicts:
#	nemo_gym/orchestration/executors/resume_script.py
GDP.pdf scored every model-side HTTP error that was not an input limit as a
terminal zero and skipped verification, and swallowed any other exception the
same way, so a server fault, a rate limit or a timeout became the model's
result and was never retried. Only the limits the agent recognises (size,
context window, image count) stay a scored zero. A confirmed policy response
timeout now leaves as the shared typed policy-timeout failure, and any other
failed call leaves with its typed model failure, so the agent boundary masks
the row and Collection retries it within its budget.

Signed-off-by: Adam Rajfer <[email protected]>

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

Review findings rechecked against f0834cd6c99ec24ba1b628fd1ca7b22b32728f15 after the PR updates. The original independent passes covered 389deb1c6, with a separate GDP.pdf follow-up through 0ca59b120; the additional changes since then have not received a fresh dual review.

I request changes for the masked-verification recovery gap, parallel-preparation hang, and trajectory-export compatibility regression. The temporary-preparation policy and custom-agent judge-routing comments are narrower, nonblocking follow-ups.

Additional nonblocking improvements:

  • Exercise GDP.pdf's production timeout shape: the real _create_episode already converts a confirmed timeout into NgFailureEvent, whereas the new test replaces it with a raw ClientResponseError. Restoring the removed broad catch could pass the test while zeroing real timeouts again. Use the already-typed error or run the real helper with HTTP stubbed, and cover one non-HTTP failure.
  • Update GDP.pdf's README: unexpected errors no longer score zero; with the default route_failures_to_sidecar=false, a failed /run stops collection. Also update the OpenAI model reference's documented propagation default from [] to {401,403,429}.
  • Preserve the cause traceback for unexpected in-process preparation errors; the new clean exit can otherwise leave only a message such as KeyError: 'foo' with no script location.

Validation: focused Python 3.13.14 checks of extracted production code confirmed the worker-handoff failure and the recovery/export selection decisions. The GDP follow-up passed syntax and installed-Ruff checks. Full repository suites and live model rollouts were not run during this review; representative live smoke evidence remains needed for the agent behavior changes.

Review provenance: Codex and Claude Opus 5.5 reviewed independently. Claude's specialist reports were returned, but the original team execution audit remains incomplete after a sandbox startup failure; that session was stopped. The separate foreground GDP follow-up completed execution verification. The comments above reflect Codex's final source/evidence checks, not a claim of a fully verified team run.

except ConfigError:
raise
except Exception as exc:
raise PreparationFailedError(prepare_module_path, "prepare", f"{type(exc).__name__}: {exc}") from exc

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.

[P2, nonblocking policy follow-up] Distinguish temporary preparation failures from permanent defects

This catches a temporary dataset-download TimeoutError/connection failure as well as deterministic preparation bugs; the isolated wrapper similarly treats every nonzero exit, including signal exits, as permanent. On a continuation segment with prepare: configured, saved recovery state and retry budget available, a temporary network failure now records environment_prepare_failed and stops the chain where it could previously spend a bounded infrastructure retry. The first segment could already stop without a rollout manifest, so this concern is specifically about continuation jobs.

Could transport/infrastructure failures retain bounded recovery, or could the new manual-retry policy be made explicit? The statement that another attempt cannot succeed is not established for these cases. A reduced check confirms that a TimeoutError gets the new terminal marker; the scheduler consequence was source-traced, not exercised on Slurm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that a transient download failure should not stop a continuation segment. I'll handle it in a follow-up rather than here, so this PR does not change the retry policy: classify transport failures in preparation as retryable and keep the terminal stop for deterministic script errors.

event = report.events.get(current)
if event is None:
return None
if event.failure_kind not in _ROUTING_FAILURE_KINDS:

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.

[P2, nonblocking custom-agent follow-up] Distinguish judge failures with and without a saved answer

If a custom /run fails with judge_failed as its first non-routing cause, this promotion makes the saved sidecar class judge_failed, although an HTTP request failure has no response. has_unclassified_execution_failure then immediately blocks agent reruns because it assumes judge-only recovery owns the row. That recovery has no answer to grade; binding it can also abort payload preparation for other legitimate judge failures in the same pass.

An exact-function reduced check confirms that the same event chain is not blocked as agent_run_error but is blocked after this promotion. Stock judge_failsafe normally returns a saved-answer HTTP-200 result, so this is a narrower custom-agent contract issue; the new [judge_failed] test nevertheless endorses this failure shape.

Please retain the typed diagnostic while making recovery routing depend on whether an answer was actually saved, and cover both shapes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, a request failure has no answer to grade. I'll keep that out of this PR and fix it in a follow-up by promoting to judge_failed only when the row kept a saved answer, with a test for both shapes.

…orced tool calls exportable

A custom agent's /verify reply with a server error or rate limit is typed judge_failed, so recovery grades
the saved answer again with /verify only; the CritPt and SciCode verifiers report themselves stateless so
that replay is admitted. PreparationFailedError survives pickling across a preparation worker, so a failing
parallel preparation exits 76 instead of hanging. ATIF export accepts the stop finish reason of a named or
forced tool call on a Responses call and still rejects truncation.

Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough pass. The three blocking items are fixed in 105110c (masked verify recovery, picklable preparation errors, forced tool call export), each with a regression test, and the two nonblocking ones are answered in their threads as follow-ups. Could you take another look?

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

Focused follow-up at 105110c865c16c1de7750e4bc8dad7a2a6881ca0.

The preparation-worker serialization and forced-tool trajectory-export fixes are verified; I am resolving those two original threads. The saved-answer recovery finding remains open: its new implementation exposes two benchmark-specific problems described in the new inline comments (SciCode loses its generated solutions and can settle as zero; CritPt cannot grade a failed subset without a full batch).

The two earlier nonblocking follow-ups remain deferred, as acknowledged in their replies.

Validation: focused Python 3.13.14 checks used the updated exception and a real two-process Pool, the updated export validation block, the actual regrading request-builder/SciCode verify method, and the actual CritPt verify/batch-wait methods. Helpers and other preconditions were controlled where dependencies were unavailable. This was a Codex follow-up, not a fresh dual review. Full suites, live model runs, sandbox execution, and real AA grading were not run.

Comment thread resources_servers/scicode/app.py Resolved
Comment thread resources_servers/critpt/app.py Resolved
…single-row replay

A regrade payload now carries the accumulated solutions and usage accounting a masked SciCode row saved, so
the verifier grades every sub-step instead of the last one. CritPt grades only full batches, so one saved
answer cannot be graded alone: its server no longer declares STATELESS and its agent keeps the
agent_route_failed kind for a failed verify call instead of claiming single-row recovery.

Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

Both new items are addressed in 41ae84e: SciCode regrades now carry the saved solutions, and CritPt is taken out of single-row replay instead of declaring it. Could you take another look?

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

Approved the reviewed code at 41ae84e8491b5995a592686ba00a3e83c1c156d7 after the follow-up fixes.

The worker-serialization and tool-call export regressions are addressed. SciCode recovery now preserves its generated solutions and step accounting. CritPt correctly opts out of unsupported single-row replay; batch/cache recovery remains an explicit limitation.

Latest-head CI shows successful core tests/combined coverage, server suite, sandbox tests, lint and DCO, with no failed or pending checks observed. My own verification used focused checks of the changed production code, including the real worker boundary and the corrected SciCode payload path; I did not independently rerun full suites or live model rollouts. The PR still reports no live rollout, so representative model validation remains an author-side pre-merge requirement.

The temporary-preparation retry policy and custom-agent judge-routing items remain acknowledged nonblocking follow-ups. The PR description should also reflect CritPt's conservative replay scope. This approval does not treat those follow-ups as implemented or attest that the earlier Claude team execution audit completed.

@AdamRajfer
AdamRajfer added this pull request to the merge queue Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit c240c91 Nov 6, 2026
107 of 110 checks passed
@AdamRajfer
AdamRajfer deleted the arajfer/typed-agent-faults branch November 6, 2026 20:55
@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Nov 7, 2026

This branch was previously deployed

1 inactive deployment
public — 41ae84e8 Deployed Nov 6, 2026 by copy-pr-bot[bot] via release / finalize / notify #10722
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 bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants