Skip to content

fix(eval): count a judge request the verifier retried as a recovered grading attempt - #6080

Merged
AdamRajfer merged 5 commits into
NVIDIA-NeMo:mainfrom
AdamRajfer:arajfer/verifier-retried-judge-coverage
Nov 16, 2026
Merged

AdamRajfer merged 5 commits into
NVIDIA-NeMo:mainfrom
AdamRajfer:arajfer/verifier-retried-judge-coverage

Conversation

@AdamRajfer

@AdamRajfer AdamRajfer commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

The evaluation-health gate reported a complete, healthy run as UNVERIFIED when the benchmark's verifier retried a failed judge request itself. The verifier then owns two model calls, the failed one and the completed reply the grading depends on, and _observed_trial_operations rejected any owned call that was not a dependency, so one such trial removed grading coverage for the whole run. An owned call the grading does not depend on now counts as a recovered grading attempt when it is wholly recorded: one failed operation of the judge model, one event naming that operation and attempt, unique ids, and a start before the completed reply; anything less still leaves the trial unobserved, and scores do not change. New tests accept a recorded retry, also of a later pass and without timestamps, and reject unrecorded, later, other-model, miscounted and id-colliding retries. Rollouts: N/A, this is gate accounting over saved rows, checked on a real complete run with retried judge requests.

…grading attempt

A verifier that retries a failed judge request itself, as a second call to the judge model server, owns two
model calls for one grading: the failed one and the completed reply the grading operation depends on. The coverage
join required every owned call to be a dependency, so one such trial left its whole run without coverage. A complete
run with every rollout healthy was then UNVERIFIED with only "known failures are a lower bound".

An owned call that the grading does not depend on now counts as a recovered grading attempt when it is wholly
recorded: one failed operation of the judge model with its single model-request event, ids unique in the run, started
before the completed reply. It joins the recovered-attempt counters like a retry inside one operation. Anything less
recorded still leaves the trial unobserved.

Signed-off-by: Adam Rajfer <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 12, 2026 19:17
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

SHIP WITH CARE

I found four RISK findings: incomplete failed-attempt records and duplicate IDs can establish coverage, while the timestamp handling rejects valid multi-dependency grading records.

I inspected both changed files and traced the model-operation producer, collector projection, ownership joins, recovery counters, and evaluation-health gate. This was a static review; I didn't execute tests.

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

Comment thread nemo_gym/orchestration/recovery.py Outdated
op_id, attempt_id = operation.get("operation_id"), operation.get("final_attempt_id")
status = event.get("http_status") if isinstance(event, dict) else None
if (
operation.get("outcome") != "failed"

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.

RISK — Validate the failed operation's attempt counters before calling it wholly recorded.

Starting with the new _verifier_retried_judge() fixture, change the failed operation's http_attempts to 2, leaving its single event unchanged. This helper still accepts it and reports one recovered attempt, although another attempt is unrecorded. Neither the later failure-accounting check nor the run-counter comparison rejects that omission, so incomplete evidence can establish exact grading coverage. The neighboring judge-recovery validator checks these counters.

Could you add these conditions to this rejection branch?

or type(operation.get("http_attempts")) is not int
or operation["http_attempts"] != 1
or type(operation.get("transport_failures")) is not int
or operation["transport_failures"] != int(status is None)

For this deliberately single-event case, retain both valid shapes: one failed HTTP attempt has (http_attempts, transport_failures) == (1, 0); one terminal transport failure has (1, 1) and no HTTP status. The producer counts the terminal transport failure inside the current retry-loop entry, so blindly requiring http_attempts + transport_failures == 1 would break that case. Please verify the suggested guard before adopting it.

Proposed checks, not executed: the two-attempt/one-event mutation, missing counters, and inconsistent transport counts must return uncovered with no published recovery counters. The existing HTTP-500 positive case must retain all four counters equal to 1; a single recorded terminal transport failure with matching attempt/event IDs must do the same.

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.

Confirmed, this was real: a failed operation whose http_attempts said 2 but whose single event was recorded was accepted, so an unrecorded attempt could still establish exact grading coverage.

Fixed in be2b762. failed_judge_attempt now requires int counters with http_attempts == 1 and transport_failures == int(status is None), which keeps both valid single-event shapes, (1, 0) for one failed HTTP attempt and (1, 1) for one terminal transport failure with no status. I checked the producer (openai_client.py: tries is incremented before the request and the terminal transport failure is counted in that same entry), so I did not use http_attempts + transport_failures == 1.

Tests in test_llm_judge_trial_coverage.py: two attempts, zero attempts, bool/None/string counters, a missing counter, and inconsistent transport counts in both directions return uncovered with no published counters; the HTTP-500 case keeps all four counters at 1; a single terminal transport failure with matching ids is covered with all four at 1. The negative cases fail on the previous head.

Comment thread nemo_gym/orchestration/recovery.py Outdated
return False
for failed, key, event, op_id, attempt_id in failed_attempts:
# A judge request the verifier retried is a recovered grading attempt, joined once like any other.
populations[0].add(failed["model_call_id"])

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.

RISK — Recheck failed-attempt IDs when registering them.

In the new _verifier_retried_judge() fixture, set the failed operation's and event's operation_id to "judge-op", the completed dependency's operation ID. The helper checks uniqueness before completed_once registers that dependency. This loop then adds the duplicate without checking, so coverage remains True despite contradictory failed/completed observations for one operation. Two failed calls validated in the same batch can likewise share operation, attempt, or event IDs.

Could you insert this guard before the additions?

if (
    failed["model_call_id"] in populations[0]
    or op_id in populations[2]
    or attempt_id in populations[4]
    or key in recovered_events
):
    return False

At this point the completed dependencies and preceding failed calls have been registered. Keep the earlier helper checks too. This restores uniqueness for these grading records without rejecting distinct, fully recorded retries. Please verify the suggested code before adopting it.

Proposed checks, not executed: reject the failed/completed operation-ID collision above, a shared final-attempt ID, and two failed calls sharing an operation, attempt, or event ID. Two failed calls with distinct IDs must remain covered with all four counters equal to 2; the existing single-retry case must retain 1. Preserve the duplicate-ID rejections in test_recovered_judge_missing_or_foreign_facts_cannot_accept.

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.

Confirmed, this was real: the failed call was only checked for uniqueness before completed_once registered the dependencies, and this loop then added it without rechecking. A failed operation reusing the completed dependency's operation or attempt id stayed covered, and two failed calls could share ids.

Fixed in be2b762. Before registering each failed call the loop now rejects a model-call, operation, attempt or event id that is already in the populations (completed dependencies and earlier failed calls), and the earlier helper checks stay. Distinct fully recorded retries are still accepted.

Tests: failed/completed operation-id collision, failed/completed attempt-id collision, and two failed calls sharing an operation, attempt or event id return uncovered; two failed calls with distinct ids are covered with all four counters at 2, and the single-retry case keeps 1. The collision tests fail on the previous head; the existing duplicate-id rejections in test_recovered_judge_missing_or_foreign_facts_cannot_accept are untouched.

Comment thread nemo_gym/orchestration/recovery.py Outdated
if len(owned) - len(retried) != len(judge_calls):
return False
calls = [call for call in calls if not any(call is judge for judge in judge_calls)]
final_started = min(call.get("started_at", math.inf) for call in judge_calls)

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.

RISK — Don't require timestamps when there is no retry to order.

A grading with two completed judge dependencies, no retries, and started_at=None on both calls now returns uncovered: min(None, None) raises TypeError, which the outer handler converts to False. The base accepted this record. Missing timestamps are supported: TrajectoryModelCall.started_at is optional, and the collector emits None when they're unavailable. One such trial removes coverage for the run despite needing no retry chronology proof.

Could you make timestamp processing conditional on retried? A minimal correction for this regression is:

final_started = (
    min(call.get("started_at", math.inf) for call in judge_calls)
    if retried
    else math.inf
)

The invariant is that ordinary completed dependencies retain their existing acceptance rules; chronology is required only for failed calls newly admitted as retries. Please verify the suggestion before adopting it.

Proposed regression, not executed: extend the two-dependency case in test_chat_judge_completion_uses_the_observed_chat_finish_reason with both timestamps explicitly None, and then with only one unavailable. Both must remain covered. Preserve acceptance of the recorded earlier retry and rejection of the later retry.

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.

Confirmed, this was real: min(call.get("started_at", math.inf) ...) raised TypeError when started_at was present as None, the outer handler turned it into "uncovered", and a grading with no retries lost coverage that the base accepted.

Fixed in be2b762. The global final_started is gone; timestamps are now read only inside the loop over retried calls, so a grading with nothing retried needs none, and a dependency without a finite timestamp is simply not a candidate for ordering a retry.

Test test_completed_judge_dependencies_need_no_timestamps_when_nothing_was_retried covers two completed dependencies with both timestamps None, only the first, and only the second; all stay covered. The last two cases fail on the previous head. Acceptance of the earlier recorded retry and rejection of the later one are unchanged.

Comment thread nemo_gym/orchestration/recovery.py Outdated
hit[0] is seen for seen in [*judge_calls, *(c for c, *_ in failed_attempts)]
):
return False
found = failed_judge_attempt(hit[0], judge_ref, final_started)

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.

RISK — Match a retry to a later compatible dependency, not the earliest dependency of the whole grading.

For a two-pass grading, let the first judge call complete after starting at 5, the second pass fail at 10, and its successful retry start at 20. Both successful replies are grading dependencies. The new branch compares the failed call with min(5, 20), so it rejects the fully recorded retry of the second pass. This is a normal supported shape: the equivalence verifier's swap/rescue passes all become dependencies, and each call_judge can retry independently. This leaves a multi-pass case unverified rather than covering it through the recovery added here.

Could you remove the global final_started/judge_ref assignments and replace this single helper call with a search for a later completed dependency of the same model? Using the existing helper preserves its same-model and ordering guards:

found = None
for judge in judge_calls:
    started = judge.get("started_at")
    if type(started) not in (int, float) or not math.isfinite(started):
        continue
    found = failed_judge_attempt(
        hit[0], judge["response_metadata"]["model_ref"], started
    )
    if found is not None:
        break

Keep the following if found is None: return False. Unlike simply changing min to max, this doesn't borrow a later timestamp from another model. It also avoids inspecting timestamps when no failed call needs joining. Please verify the suggested change before adopting it.

Proposed checks, not executed: add an earlier successful dependency at 5 to the new fixture's failed-at-10/successful-at-20 case; coverage must be True with all four retry counters equal to 1. A failed call after every same-model dependency must remain uncovered, even if a different model has a later dependency. Preserve the single-dependency positive case and the existing unrecorded/later/other-model rejections.

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.

Confirmed, this was real: comparing a failed call with the earliest dependency of the whole grading rejected a fully recorded retry of a later pass whenever another pass had completed earlier.

Fixed in be2b762, with the shape you proposed: the retry is matched by searching the completed dependencies for a later one of the same judge model (using failed_judge_attempt, so its same-model and ordering guards still apply), and only dependencies with a finite timestamp are considered.

Tests: an earlier successful dependency at 5 beside a failed call at 10 and its successful retry at 20 is covered with all four counters at 1 (fails on the previous head); a failed call after every same-model dependency stays uncovered even when a different model has a later dependency; the single-dependency positive case and the existing unrecorded/later/other-model rejections are unchanged.

…uniquely joined

- check the failed operation's attempt counters (one attempt; the transport count matches the single event)
- recheck its ids against the completed dependencies and earlier retries when joining it
- read timestamps only when a retry has to be ordered, so gradings without retries need none
- match each retry to a later completed dependency of the same judge model, not the earliest of the grading

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

Copy link
Copy Markdown
Contributor Author

/ok to test be2b762

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 13, 2026
@iguehring-nvidia

Copy link
Copy Markdown
Contributor

/review

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

SHIP

I verified all four prior findings are fixed. The counter guards reject incomplete attempt records while keeping both valid single-event shapes. The registration guard rejects IDs already used by completed dependencies or preceding failed calls.

The retry loop leaves timestamps unused when nothing was retried and searches for a later dependency of the same model. The regression assertions cover the earlier failures and valid neighboring cases.

I compared the changes since the previous review and traced the affected producer, collector, and health-reporting paths. I found no remaining eligible issues within this follow-up scope. This was a static review; I did not execute tests.

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

The verifier owns it but the grading does not depend on it. It is a recovered grading attempt only when it is
wholly recorded: one failed operation of the judge model whose single model-request event names that operation
and attempt, ids unique in the run, and it started before the completed reply that the grading rests on.
"""

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.

Could we give this function a human-written doc string? I don't understand a word of it ;)

Comment thread nemo_gym/orchestration/recovery.py Outdated
or event.get("operation") != "model_request"
or event.get("failure_kind") != "model_request_error"
or event.get("cause_id") is not None
or not (status is None or (type(status) is int and 400 <= status <= 599))

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.

I don't know the details of what should be happening here, but this looks like an anti-pattern.

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.

This comment is targeting the whole block of "or"s

Comment thread nemo_gym/orchestration/recovery.py Outdated
for call in calls
if not any(call is judge for judge in judge_calls)
and not any(call is failed[0] for failed in failed_attempts)
]

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.

this patch looks a bit like spaghetti. Can we implement it in a way such that it is readable code that documents itself?

Comment thread nemo_gym/orchestration/recovery.py Outdated
failed["model_call_id"] in populations[0]
or op_id in populations[2]
or attempt_id in populations[4]
or key in recovered_events

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.

Same comment as above.

…ument them

Split the long condition chains of failed_judge_attempt into small named checks, give it a plain description, and move the retried-call join and the id registration into their own functions. No change in what is accepted or rejected.

Signed-off-by: Adam Rajfer <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 16, 2026 09:16
@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Nov 16, 2026
@iguehring-nvidia

Copy link
Copy Markdown
Contributor
  1. Thanks for the refactor!

  2. Not really part of this PR (but in some sense it is): I took a look at https://github.com/NVIDIA-NeMo/Gym/blob/51cd8c18c456a08a38eb01282b3ccd989df2daaa/nemo_gym/orchestration/recovery.py which is 7K LOC with high cyclic complexity, magic numbers, strings, and blocks like below

        # The health counter's own test of an answered call: a success status and no failure recorded on it.
        if (
            not isinstance(events, dict)
            or not events
            or not isinstance(operations, list)
            or type(status) is not int
            or not 200 <= status < 400
            or meta.get("error_category")
            or meta.get("response_status") in ("failed", "error", "cancelled")
        ):
            continue
        for operation in operations:
            op_id = operation.get("operation_id") if isinstance(operation, dict) else None
            if not nonempty(op_id) or operation.get("outcome") != "completed" or op_id in seen:
                continue
            owned = {
                key: event
                for key, event in events.items()
                if isinstance(event, dict) and event.get("operation_id") == op_id
            }
            tries, transport = operation.get("http_attempts"), operation.get("transport_failures")
            answer = operation.get("final_attempt_id")
            ids = {event.get("attempt_id") for event in owned.values()}
            if (
                not owned
                or type(tries) is not int
                or type(transport) is not int
                or tries < 1
                or transport < 0
                or len(owned) != tries - 1 + transport
                or sum(event.get("http_status") is None for event in owned.values()) != transport
                or not nonempty(answer)
                or answer in ids
                or len(ids) != len(owned)
                or operation.get("failure_id") is not None
                or any(
                    key != event.get("event_id")
                    or not nonempty(event.get("attempt_id"))
                    or event.get("boundary") != "model"
                    or event.get("operation") != "model_request"
                    or event.get("failure_kind") != MODEL_REQUEST_ERROR
                    or event.get("cause_id") is not None
                    or not (
                        event.get("http_status") is None
                        or (type(event["http_status"]) is int and 400 <= event["http_status"] <= 599)
                    )
                    or (
                        key in saved
                        and (
                            not isinstance(saved[key], dict)
                            or any(saved[key].get(name) != value for name, value in event.items())
                        )
                    )
                    for key, event in owned.items()
                )
            ):
                continue
            seen.add(op_id)
            found.append((op_id, owned))

I am wondering if we are able to maintain and understand the recovery logic mid- to long-term? I am also wondering if this will cause problems down the line: If we need to hunt down discrepancies between scores, I guess it will be almost impossible to understand the role retries have played?

…verage

Follow-up to the review of the retried-judge coverage. Only the lines this PR
adds change: the HTTP error range and the status strings become named
constants, the remaining chains of conditions become small named checks
(the exact attempt count, an id registered twice), and the docstrings say what
each function checks and why. Behavior and tests are unchanged.

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

Copy link
Copy Markdown
Contributor

Regarding the comment I left earlier: I would propose a discussion among the Gym maintainers to align whether these kind of agent-written and non-human-maintainable modules are direction we want to head to or not.

@giuliolovisotto

giuliolovisotto commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Regarding the comment I left earlier: I would propose a discussion among the Gym maintainers to align whether these kind of agent-written and non-human-maintainable modules are direction we want to head to or not.

I agree that this recovery module is completely unreadable atm and hardcodes choices in these 10-conditional IFs that one can't wrap their head around ;)

Whether agents or not - we have made an attempt to put together some conventions about failure handling (and recovery), I hope to bring it to main soon with this #6227.

My hope is that humans can at least agree on those conventions and have a shared expectation of behavior.

…in the retried-judge coverage

The coverage check redefined the model boundary and the model_request_error kind that nemo_gym.core already names (FailureBoundary.MODEL, MODEL_REQUEST_ERROR). Use those and drop the two duplicate constants. Behavior is unchanged.

Signed-off-by: Adam Rajfer <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working area:orchestration Job submission, deployment, services, and lifecycle management labels Nov 16, 2026
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

🤖 Adam’s AI assistant

@iguehring-nvidia @giuliolovisotto Thanks for the careful read.

I went over the code this PR adds once more and tightened it, touching only those lines. The functions now have short docstrings that say what they check and why, the long chains of or are split into small named checks (one for the exact attempt count, one for ids already used, one for "this call, operation, attempt or event was already registered"), and the HTTP error range and the status strings are named constants instead of bare numbers and literals. Behavior is unchanged, and the unit tests pass.

On your second point, you're right, and I don't want to pretend this PR fixes it. recovery.py is far too large, and its checks lean on literals that should have names. Splitting it up is a bigger change than I'd fold into a bug fix, so I'd rather do it separately: break recovery.py into smaller modules, and add one record per row that says how many retries it had and why. That record is what would let us explain a score that moved because of retries. I'll propose that as a separate follow-up.

And yes to the maintainer discussion. I'd base the recovery.py split on the conventions Giulio is bringing in with #6227, so the modules follow the failure boundaries and we agree on the structure before I write it.

@AdamRajfer

AdamRajfer commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@iguehring-nvidia @giuliolovisotto I believe agents are helping us here rather than introducing friction. I have tested that this stack actually does improve our failure handling setup. Running e2e tests is a part of my work.

Correct, I was following the RFC strictly and spent significant amount of time to ensure quality of my work for failure handling. If you have concerns regarding this work, let's raise it to @bernardwin and @ananthsub and keep me in CC. As owner of this file, I hold responsibility for the code and for any potential future bugs.

@iguehring-nvidia

Copy link
Copy Markdown
Contributor

To unblock fixing this issue, I am approving this PR subject to this being the starting point of a discussion whether we would like to have these kind of modules in Gym or not. Additional fixes to this PR will not change the overall appearance of this module so it needs to be discussed more holistically.

@AdamRajfer
AdamRajfer added this pull request to the merge queue Nov 16, 2026
@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/43909994933

Merged via the queue into NVIDIA-NeMo:main with commit a349aa6 Nov 16, 2026
64 checks passed
@AdamRajfer
AdamRajfer deleted the arajfer/verifier-retried-judge-coverage branch November 16, 2026 16:53
prokotg added a commit that referenced this pull request Nov 17, 2026
Ports main's changes to the files this PR moved:
- orchestration/recovery.py (#6210, #6080, #6223): 3 symbols changed and 6 added, into the eval/recovery
  modules; NO_ELIGIBLE_RETRY_REASON moves to eval/recovery/markers.py because the evidence reader now
  uses it.
- executors/slurm.py (#6210, #6223, #6215): the 12 hunks, into executors/slurm/chain.py, judge_job.py and
  reader.py.
- tests that import the old module paths (the otel, resubmit and recovery tests added since).

Signed-off-by: Tomasz Grzegorzek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:orchestration Job submission, deployment, services, and lifecycle management bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants