Skip to content

feat(tier3): add opt-in judge fallback and strict retry policies - #343

Merged
rng1995 merged 15 commits into
mainfrom
naren/port-judge-fallback-policy
Nov 5, 2026
Merged

rng1995 merged 15 commits into
mainfrom
naren/port-judge-fallback-policy

Conversation

@rng1995

@rng1995 rng1995 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add two opt-in host variables for the Tier 3 standard judges in the Harbor verifier. Both default to today's behavior (append, legacy).
  • LLM_JUDGE_FALLBACK_POLICY=replace: only the judge model and the LLM_JUDGE_FALLBACK_MODELS entries may answer. The built-in claude-opus-4-8 refusal fallback for Claude 5.5 or later judges is turned off: no fallbacks field or beta header on the native Claude API, and no second Opus 4.8 request on Bedrock.
  • LLM_JUDGE_RETRY_POLICY=strict:
    • Tries at most three models (the judge model, then the first two LLM_JUDGE_FALLBACK_MODELS entries) with at most two requests each, all inside the existing per-judge time budget. A schema downgrade or token refresh counts toward the two requests.
    • Moves on only when a model is unavailable: a retryable HTTP status, connection error or Bedrock throttling or service error that failed its one retry, a Retry-After above the maximum retry delay, or a model the provider reports as not found or not accessible. The last one moves on without a retry. It covers the errors LLM_JUDGE_FALLBACK_MODELS already falls back on, OpenAI's model_not_found, a Claude not_found_error that names the model, and Bedrock's AccessDeniedException, ResourceNotFoundException and invalid model identifier errors.
    • Ends the judge on a refusal, a TLS certificate failure, an authentication error, any other non-retryable status, or the judge deadline. It also ends the judge, even on HTTP 429, when the provider says a quota, budget, billing or credit limit was reached or a content filter, safety or security policy rejected the request. Only whole phrases (insufficient_quota, budget exceeded, credit balance, content_filter, ...) count, read from the code, type, message or detail of a JSON error body, the first 500 characters of any other body, or a Bedrock error code and message. A model id, a proxy host name or a connection error's text never ends the judge.
    • When a later model ends the judge, the reason keeps the earlier models' errors, in order.
    • Treats the first completed reply as final. It must be exactly one JSON object with only whitespace around it: no prose, Markdown fences, second object, duplicate key or NaN. An empty, invalid or truncated reply fails the judge without the format retry or behavior_check salvage, and another model is never asked to overturn it. The built-in refusal fallback and the RAGAS goal scorer (which sends its own requests) are off.
  • An unknown value of either variable stops a run with standard grading at configuration, before any trial starts, with the same message the verifier gives. custom_only runs ignore the variables. In the verifier, an unknown value still fails every standard judge before a request is sent, and keeps the RAGAS goal scorer off.
  • The two variables join LLM_JUDGE_FALLBACK_MODELS in the verifier judge controls, so they are forwarded and staged the same way: only to standard verifier jobs, never to the agent environment, runtime_env or custom_only runs, and task-authored values are rejected. run_config.json records a known value as judge.fallback_policy / judge.retry_policy.
  • A test autouse fixture clears both variables so a developer's shell setting cannot change other judge tests.
  • Docs: new "Judge fallback and retry policies" section in docs/tier3-live-evaluation.mdx, two rows in docs/environment-variables.mdx, and the forwarding note in docs/custom-graders.mdx. CHANGELOG entry under Unreleased > Added.

Why

Some teams must control exactly which models score their skills, and how many times a judge is asked. Today a Claude 5.5 judge can be answered by claude-opus-4-8 even when the operator listed other fallbacks. A judge can also be retried up to four times per model, re-asked with a rewritten prompt after an invalid reply, and scored from JSON recovered from prose or a truncated reply. A refusal or empty reply moves on to the next model. These defaults suit most runs, but they let a different model or a later request overturn a completed answer. The strict policy gives a bounded, auditable alternative that fails closed instead.

Kept from public

  • The default path is unchanged. The provider dispatch moves into _call_judge_model, and both paths share it; the legacy loop keeps its fallback rules (refusal and empty reply move on, LLM_JUDGE_FALLBACK_MODELS only on the model errors _should_try_fallback recognizes). The wider model-unavailable and stop-phrase rules apply only under strict.
  • Strict mode reuses public's transport rather than adding its own: _urlopen_with_retry, the Bedrock _converse loop, _is_retriable_http_status, _is_certificate_failure, _classify_bedrock_retry_error, _compute_bounded_retry_delay (maximum delay and judge deadline), the schema downgrade, and the per-judge budget and alarm in _call_required_judge. It only caps the requests per model and stops on the errors listed above.
  • Strict replies are decoded with public's strict hooks (_reject_duplicate_object_pairs, _reject_nonstandard_json_constant, _parse_finite_json_float) and the 128-level nesting bound. extract_json keeps its permissive behavior by default.
  • judge_model_used, judge_fallback_used and the reasoning-effort record come from public's _record_judge_call on both paths.
  • The forwarding uses public's existing judge-control sets in adapter.py (_VERIFIER_JUDGE_FALLBACK_ENV_VARS), so the existing staging, placeholder and rejection rules apply unchanged. The host check sits with the other configuration checks in _run_harbor_eval_impl and uses its error and progress reporting.
  • Per-request evidence and answering-model records are not part of this change; they belong to the open judge evidence and model provenance work.

Tests

  • New tests/tier3/test_judge_policies.py (85 tests):
    • fallback policy: a refused Claude 5.5 judge on Bedrock is answered by the LLM_JUDGE_FALLBACK_MODELS entry under replace and by claude-opus-4-8 under append; either policy drops the Anthropic server-side fallback and the Bedrock Opus 4.8 retry; the defaults (also " APPEND ", Legacy) keep them
    • strict availability: capacity retried once then the next model, with judge_model_used and judge_fallback_used; at most three models, two requests each; 408/429/5xx, connection errors and Bedrock throttling move on after one retry; a Retry-After above the maximum delay moves on, one past the deadline ends the judge; a schema downgrade counts as a request
    • strict missing models: OpenAI model_not_found and "does not exist", a Claude not_found_error for the model, key_model_access_denied, and Bedrock AccessDeniedException, ResourceNotFoundException and an invalid model identifier move on without a retry; another not_found_error and another Bedrock ValidationException end the judge
    • strict stops: certificate failure, 400/401/403/409/501, quota, budget, credit, billing, content-filter and safety errors end the judge without a retry, also from a JSON body with only a detail field or none of the usual fields; a stop phrase late in a long error page, a model id with "safety" in it, and a proxy host with "security" in it do not; the reason keeps the earlier models' errors (HTTP and Bedrock)
    • strict replies: refusals and an empty reply are final; prose, fences, two objects, duplicate keys, NaN and invalid payloads fail without a second request; a whole object with surrounding whitespace keeps its verdict; behavior_check neither retries nor salvages; goal_accuracy skips RAGAS; candidates share the judge deadline; legacy extract_json stays permissive, and the legacy loop keeps its model error rules
    • invalid values: either variable sends no request, fails the judge and keeps RAGAS off; the run stops at configuration before staging or trials; a custom_only run ignores them; run_config.json does not record them
    • forwarding: task verifier.env staging, the host provider environment and the verifier job layer (not custom_only), run_config.json recording, and rejection from skill runtime_env
  • Extended tests/test_harbor_runner_environment.py so the two names are forwarded from the host for each provider, and tests/test_harbor_runtime_skill_isolation.py so they are rejected as task/step judge controls and accepted as exact operator-staged placeholders.
  • Fail-before: with src/ (including the verifier template) from main and this PR's tests, test_judge_policies.py has 61 failed and 24 passed. The 24 pin behavior this PR keeps:
    • the default path: legacy retries and refusal fallback, the Anthropic server-side fallback (2), the append case of the Bedrock refusal test, permissive extract_json, and the legacy model error rules
    • strict cases where the outcome matches main for that input: 400/401/403/409/501 end the judge (5), certificate failure, key_model_access_denied, another not_found_error, another Bedrock ValidationException, a model id with "safety" in it, the shared deadline, a Retry-After past the deadline, and a whole-object verdict (2)
    • host recording: unset and unknown values not recorded (3), and custom_only ignoring them
  • Full suite on the branch (pytest -n 8 tests): 21941 passed, 55 skipped, 19 failed. None of the failures is in code this PR touches:
    • 13 test_generated_custom_only_script_* in tests/tier3/test_judge_failure_artifacts.py also fail on main on this machine (the generated script stops with "unsupported operand type(s) for |"), and the 2 test_sidecar_retains_* in tests/test_harbor_secure_docker_environment.py are known local-only failures on main
    • 4 timing tests under full-suite load (test_local_callback_receives_complete_line_before_process_exit, test_bedrock_model_probe_classifies_malformed_local_sso_token_as_fatal[None-TypeError], test_slow_drip_request_line_and_headers_obey_an_absolute_deadline, test_bounded_harbor_process_timeout_preserves_redacted_diagnostic_tail) pass when rerun on the branch
  • ruff check and ruff format --check are clean on the changed Python files, and scripts/check_oss_boundary.py passed.

🤖 Generated with Claude Code

rng1995 and others added 2 commits November 5, 2026 00:56
LLM_JUDGE_FALLBACK_POLICY=replace lets only the judge model and the
LLM_JUDGE_FALLBACK_MODELS entries answer a standard judge, without the
built-in claude-opus-4-8 refusal fallback.

LLM_JUDGE_RETRY_POLICY=strict tries at most three models with two
requests each inside the per-judge time budget. It moves on only when a
model is unavailable, ends the judge on a refusal or a quota, budget,
billing, content-filter, safety or security error, and scores only a
first completed reply that is exactly one JSON object, with no format
retry, salvage or RAGAS request.

An unknown value fails the standard judges before any request. Both
variables are forwarded and staged like LLM_JUDGE_FALLBACK_MODELS, and
run_config.json records a set value. The defaults keep today's behavior.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add a "Judge fallback and retry policies" section to the live evaluation
guide, rows for LLM_JUDGE_FALLBACK_POLICY and LLM_JUDGE_RETRY_POLICY in
the environment variable reference, the forwarding note in the custom
graders guide, and a CHANGELOG entry under Unreleased > Added.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated review: 7 findings (0 P1, 2 P2, 5 P3); 6 posted inline.

Findings outside the diff or about the description:

  • prs/W70.md:32: P2: The PR text still has unfilled placeholders: 'TESTS_NEW tests' (line 32), 'FAIL_BEFORE' (line 40) and 'FULL_SUITE' (line 41). If this file is posted as the body of #343, it publishes template tokens instead of the test counts that the Tests section is supposed to state exactly.

Suggested fix: Fill in the measured values. tests/tier3/test_judge_policies.py has 59 tests. Fail-before (origin/main src, branch tests, scratch copy with the template swapped too): 41 failed, 18 passed. Full suite: rerun it and report the count, naming the local-only failures that also fail on origin/main (see 'checked'). The PR text file is at a local scratch script (line 32 is TESTS_NEW).

Comment thread docs/tier3-live-evaluation.mdx Resolved
Comment thread tests/tier3/test_judge_policies.py Resolved
rng1995 and others added 6 commits November 5, 2026 10:12
An unknown LLM_JUDGE_FALLBACK_POLICY value failed every standard judge
before a request, except goal_accuracy on the OpenAI provider: the RAGAS
scorer checked only the retry policy and sent its own request. RAGAS now
stays off unless both policy values are known, so the prompt judge
reports the configuration error instead.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The strict policy ended a judge whenever the error text contained a bare
word such as safety, security, credit or budget anywhere, so an echoed
model id (vendor/content-safety-judge) or a proxy host name in a
connection error ended the judge instead of moving on.

Stop reasons are now whole phrases (insufficient_quota, budget exceeded,
credit balance, content_filter, blocked by a safety system, ...) matched
only against what the provider said: the code, type and message of a
JSON error body, the start of any other body, or a Bedrock error code
and message. Connection errors never count.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The strict policy docs say a model the provider reports as not found,
invalid or not accessible to the key moves on without a retry, but only
the phrases the legacy fallback list recognizes did. OpenAI's real 404
(code model_not_found, "The model `x` does not exist ..."), a Claude
not_found_error about the model, and Bedrock's AccessDeniedException,
ResourceNotFoundException and invalid model identifier ValidationException
all ended the judge.

Under the strict policy these now move on to the next listed model
without a retry. The legacy policy keeps its existing model error rules.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a later candidate ended a strict judge, only its own error was
reported, so "primary 503 twice, then backup 401" read as an auth
problem with the backup alone. The terminal error now lists every
model's error in order, as the exhausted-fallback error already did.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A typo such as LLM_JUDGE_RETRY_POLICY=strcit was recorded in
run_config.json as judge.retry_policy, as if it were applied, and the
run spent the whole agent trial budget before every standard judge
failed in the verifier.

A run with standard grading now stops at configuration with the same
message the verifier gives, and run_config.json records only a known
value. custom_only runs, which never forward the policies, ignore them.
The verifier keeps its fail-closed check.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The two replace tests checked _fallback_models, which the policy does not
change, so they passed without it. Replace them with an end-to-end check:
a refused Claude 5.5 judge on Bedrock is answered by the
LLM_JUDGE_FALLBACK_MODELS entry under replace, and by the built-in
claude-opus-4-8 fallback under the default append.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rng1995
rng1995 marked this pull request as ready for review November 5, 2026 18:29
rng1995 and others added 6 commits November 5, 2026 10:49
src/skillevaluator/tier3/harbor/templates/eval.py: main rewrote
_call_validated_json_judge to take metric and salvage keywords, record
every attempt in judge_attempts.json, and send the named problem back in
the retry, and behavior_check now goes through it. The merge keeps main's
signature, body and docstring, adds the PR's sentence on the strict
policy, and moves the PR's strict early return onto main's problem value.
It returns after the first recorded attempt, before the retry and the
salvage, with the message "Judge response was unparseable or invalid:
<problem>; LLM_JUDGE_RETRY_POLICY=strict sends no retry". The default
legacy policy keeps main's retry, salvage and error text unchanged.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The strict stop check read only the code, type and message fields of a
JSON error body, so a body without them, such as {"detail": "Budget has
been exceeded"}, was not checked at all. Read a detail field too, and
fall back to the body excerpt when a JSON body has none of these fields.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
No conflicts. main's Claude Code refusal-fallback switch (#337) adds one
evaluator-managed runtime variable in harbor/adapter.py, apart from this
PR's judge policy variables, and the CHANGELOG and docs entries sit side by
side.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the main merges made on the PR branch on GitHub; no conflicts.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts: CHANGELOG.md (kept main's new Added entry, then this PR's).

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rng1995
rng1995 enabled auto-merge (squash) November 5, 2026 21:38
@rng1995
rng1995 merged commit 8a851c6 into main Nov 5, 2026
22 checks passed
@rng1995
rng1995 deleted the naren/port-judge-fallback-policy branch November 5, 2026 22:24
@rng1995

rng1995 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Post-merge review: 1 finding(s) (P3). Follow-up PR: #359.

🤖 Generated with Claude Code

@rng1995 rng1995 mentioned this pull request Nov 6, 2026
7 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant