Skip to content

fix(tier3): score goal_accuracy with RAGAS for eligible OpenAI judges - #286

Merged
rng1995 merged 16 commits into
mainfrom
naren/port-ragas-fallback-warning
Nov 5, 2026
Merged

rng1995 merged 16 commits into
mainfrom
naren/port-ragas-fallback-warning

Conversation

@rng1995

@rng1995 rng1995 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Call the RAGAS 0.4 collections AgentGoalAccuracyWithReference metric the way its API expects, metric.ascore(user_input=..., reference=...), instead of passing a SingleTurnSample. Drop the unused SingleTurnSample import from the verifier and from the image's verifier import check.
  • After scoring, cancel any work that a judge deadline left pending, then close the scorer's AsyncOpenAI client within a short bound. If closing fails, only the exception type is logged, and the failure never hides the score or the scorer's own error.
  • Record the RAGAS judge model the same way the prompt judges do. A RAGAS-scored goal_accuracy then carries judge_model_used, judge_reasoning_effort and judge_fallback_used, and lift's mixed-judge check can see it.
  • When RAGAS fails and the prompt judge takes over, the verifier now logs a warning with the redacted, bounded error. Before, it logged an info line with the raw exception text.
  • Docs (docs/tier3-live-evaluation.mdx, RAGAS goal scorer) and a CHANGELOG Fixed entry.

Why

The RAGAS path in goal_accuracy runs for the openai provider on https://api.openai.com/v1 with a judge that is not a GPT-5 or GPT-6 reasoning model. The docs say this setup uses the RAGAS scorer. In practice the scorer never ran. The verifier pins ragas~=0.4.0, and that version's collections metric takes keyword arguments. Building a SingleTurnSample from a message list fails pydantic validation, and the positional call would fail anyway because reference is missing. Both failures happened before any request was sent. The broad except then switched to the prompt judge and logged one info line, so every eligible trial quietly reported "method": "custom". The existing unit-test stub (ascore(self, _sample)) accepted the wrong call shape, which hid the bug.

I checked this against the real ragas==0.4.3 package with a mocked OpenAI transport:

  • On main, the scorer failed with a SingleTurnSample validation error and sent no requests. It fell back to the custom judge, and the client was never closed.
  • With this change, it sent the two expected chat-completions requests and returned "method": "ragas" with judge_model_used: gpt-4.1. The client was closed.

User-visible change: trials with eligible judges now report goal_accuracy from RAGAS ("method": "ragas"), so their scores and lift can differ from earlier runs. Default judges (GPT-5 and GPT-6) skip RAGAS and are unaffected.

Kept from public

  • The gate in _ragas_goal_accuracy_enabled stays as is: OpenAI only, canonical endpoint only, no reasoning models, and off when SKILL_EVAL_JUDGE_CHARACTER_FACTS selects the prompt goal judge. RAGAS is never used as a fallback for the agent's key, and a custom base URL is never sent to RAGAS.
  • The time limit is unchanged. The scorer still runs under asyncio.wait_for with the remaining per-judge time, and the SIGALRM deadline in _call_required_judge still applies. No separate RAGAS budget or SDK retry policy is added.
  • Fallback behavior is unchanged. A RAGAS failure, or a non-finite RAGAS score, falls back to the prompt judge as before. That judge has its own structured-output, retry and validation handling.
  • The prompt judge keeps its 16384-token structured-judge budget, and the existing judge HTTP retry logic is not touched.

Tests

  • New test_ragas_goal_scorer_uses_the_collections_keyword_contract drives judge_goal_accuracy through _call_required_judge using the real eligibility checks (SKILL_EVAL_LLM_PROVIDER=openai, LLM_JUDGE_MODEL=gpt-4.1, SKILL_EVAL_JUDGE_CHARACTER_FACTS unset). Its fake metric has the RAGAS 0.4 ascore(user_input, reference) signature, and its fake SingleTurnSample raises an error if used. The test asserts:
    • the score comes from RAGAS, not the custom judge
    • the RAGAS fields and judge-model fields are recorded
    • the client uses the canonical base URL and is closed once
  • New test_ragas_goal_scorer_failure_warns_and_closes_its_client, run with close succeeding and with close failing, checks:
    • the client is closed before the prompt judge runs
    • a warning is logged that starts with the error type
    • the API key is redacted from all warnings
    • a close failure is logged by type only
  • The existing test_ragas_goal_judge_obeys_the_required_judge_time_budget now uses the same keyword-only fake and the real eligibility checks.
  • On unmodified main, all four RAGAS tests fail. On this branch they pass.
  • pytest tests/tier3 tests/test_llm_judge.py tests/test_tier3_public_runtime.py tests/test_harbor_runtime_skill_isolation.py tests/test_character_facts.py tests/test_harbor_adapter_safety.py tests/test_verifier_error_redaction.py tests/test_oss_packaging.py tests/test_benchmark_rollout_docs.py tests/test_ci_change_classifier.py tests/test_accuracy_arithmetic.py: 7319 passed, 2 skipped. The one failure, test_fifo_dataset_is_rejected_without_blocking, was a 5-second subprocess timeout under parallel load. That test does not exercise this change, and it passes when rerun on its own.
  • ruff check and ruff format --check pass on all changed Python files.
  • The OSS boundary check passes.

🤖 Generated with Claude Code

The verifier's RAGAS goal scorer passed a SingleTurnSample to the RAGAS
0.4 collections AgentGoalAccuracyWithReference metric, which takes the
conversation messages and the reference as keyword arguments. The call
failed before any request was sent, so every trial that should use RAGAS
(the openai provider on the canonical endpoint with a non-reasoning
judge such as gpt-4.1) silently fell back to the custom prompt judge,
with only an info-level log line. The documented scorer never ran.

Call metric.ascore(user_input=..., reference=...) and drop the unused
SingleTurnSample import from the verifier and its image import smoke
check. After scoring, cancel any work a judge deadline left pending and
close the AsyncOpenAI client within a short bound; a close failure is
logged by type only and never hides the score or the scorer's error.
Record the RAGAS judge model like the prompt judges do, so
goal_accuracy keeps judge_model_used, judge_reasoning_effort and
judge_fallback_used for lift's mixed-judge check. When RAGAS fails and
the prompt judge takes over, log a warning with the redacted error.

Trials with eligible judges now report goal_accuracy with method
"ragas" instead of "custom". Default GPT-5 and GPT-6 judges skip RAGAS
and are unaffected.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build the metric inside the try block so a failure in llm_factory or the
metric constructor still closes the AsyncOpenAI client before the custom
goal judge runs.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[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.

Verified the new call shape against the real ragas 0.4.3 AgentGoalAccuracyWithReference.ascore(user_input, reference) signature (it reaches the network layer with keyword arguments), and the provenance recording and docs/CHANGELOG are consistent. ruff is clean and tests/tier3 passes locally. One P3, fixed in 222ec15.

Reviewed with Claude Code.

rng1995 and others added 2 commits November 2, 2026 10:50
Conflicted files: CHANGELOG.md

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

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

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The keyword call into the RAGAS collections metric, the cleanup in the finally block and the provenance recording all look right, and I checked them against _call_required_judge and the lift mixed-judge check that consume them. Two non-blocking points: lift still cannot tell a RAGAS score from a prompt-judge score that used the same model, and the deadline test does not assert the new cleanup.

rng1995 and others added 7 commits November 2, 2026 19:48
Conflicted: docs/tier3-live-evaluation.mdx.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A case scored by RAGAS in one arm and by the prompt judge in the other used
the same judge model on both sides, so lift paired the two scores. The
collector now tags a RAGAS-scored judge model as "<model> (ragas)" when it
compares arms, so these cases are left out of the goal_accuracy lift and
counted in judge_mixed_cases like a model fallback.

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

The time-budget test only checked the error status and score, so it would
still pass if the cleanup only closed the event loop. It now runs once with
the scorer's own timeout and once with the judge deadline alarm stopping the
loop mid-score, and asserts that the cut-off scoring work is cancelled and
the OpenAI client is closed exactly once.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the CHANGELOG.md conflict: keep main's new Unreleased entry and
put this PR's entry after it.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Name the eligible judges by what the code checks (an OpenAI judge outside
the GPT-5 and GPT-6 families) rather than by gpt-4.1, which OpenAI is
retiring from its API.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the CHANGELOG.md conflict: keep main's Ctrl+C entry (#291) and
add this PR's RAGAS scorer entry after it.

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]>

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up on the current head. Both earlier points are fixed. _reward_judge_models now tags a RAGAS-scored judge model as <model> (ragas), so a RAGAS score never pairs with a prompt-judge score from the same model, and the multi-step path collects its step models through the same function. The deadline test now asserts that pending work is cancelled and the client is closed once. The CHANGELOG wording change reads fine. Nothing further from me.

rng1995 and others added 5 commits November 5, 2026 22:24
Resolve the CHANGELOG.md conflict: keep main's SkillSpector partial-scan
entry (#294) and add this PR's RAGAS scorer entry after it.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts with #303's judge contract:

- judge_goal_accuracy: keep this PR's redacted warning when RAGAS falls
  back, plus main's judge_attempts.json records for the failed and the
  accepted RAGAS attempt.
- _judge_goal_accuracy_ragas: keep main's binary-score check (which also
  rejects NaN) in place of the finite check, plus this PR's judge-model
  provenance and _record_judge_call.
- docs/tier3-live-evaluation.mdx: describe both the non-binary fallback
  and the warning and method fields.

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]>
Combine binary-score validation and judge-attempt evidence with the RAGAS collections API fix and judge provenance. Bound cancellation and client cleanup, preserve scorer outcomes, and consume late task failures without logging credentials.

Signed-off-by: Narendran Raghavan <[email protected]>
@rng1995
rng1995 enabled auto-merge (squash) November 5, 2026 17:26
@rng1995
rng1995 merged commit db5cc9c into main Nov 5, 2026
22 checks passed
@rng1995
rng1995 deleted the naren/port-ragas-fallback-warning branch November 5, 2026 17:58
@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.

2 participants