Skip to content

feat(tier3): save RAGAS goal-accuracy requests and replies in judge_attempts.json - #429

Merged
rng1995 merged 8 commits into
mainfrom
naren/port-tier3-ragas-judge-exchange-evidence
Nov 12, 2026
Merged

rng1995 merged 8 commits into
mainfrom
naren/port-tier3-ragas-judge-exchange-evidence

Conversation

@rng1995

@rng1995 rng1995 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When the RAGAS goal scorer judges goal_accuracy, judge_attempts.json now holds each request RAGAS sent and the judge's reply, not only the final score.

  • The AsyncOpenAI client handed to RAGAS now uses openai.DefaultAsyncHttpxClient with an httpx response hook (_save_ragas_exchange). The SDK's default timeout, connection limits and redirect setting stay the same, and closing the client still closes its HTTP client.
  • Each response is saved through _record_judge_attempt as a goal_accuracy attempt with method ragas and the model named in the request body, or the selected judge model when the body cannot be read:
    • replied, with the role-labelled request messages as the prompt and the judge's reply. The reply is the message text, or the tool-call arguments when RAGAS asked for a tool call.
    • error, with HTTP <status>: <body> as the problem, or the reply was not received (<error type>) when the body could not be read. The read error is raised again, so the SDK retries as before.
  • The existing last ragas entry is unchanged: accepted with the score, or error with the reason the prompt judge ran instead.
  • --max-judge-calls still counts one judge call per RAGAS score. runner._budget_usage skips the ragas entries that carry a prompt, so the requests RAGAS sends itself and the SDK's transport retries are not counted, as feat(tier3): add run budget limits with admission control and partial results #404's docs say. The last ragas entry has no prompt and stays the one counted call.
  • Prompts, replies and problems go through _redact_judge_evidence and are shortened, like the other judge evidence. The error body is not cut before redaction, so a credential cannot be split at the cut.
  • Evidence failures never change a score. A parsing failure in the hook, or an SDK without DefaultAsyncHttpxClient, logs Could not save RAGAS judge evidence: <error type>. A write failure is logged by _record_judge_attempt as Could not save judge evidence: <error type>, as for the other judges. In both cases RAGAS scores as before.
  • The evidence code re-raises the judge deadline alarm (TimeoutError) instead of logging it as an evidence failure. In a real request the SDK then treats it as a connection error and retries; the RAGAS time budget (asyncio.wait_for) still bounds the run, as on main.
  • Docs: the "Saved judge evidence" bullet in docs/tier3-live-evaluation.mdx lists the replied status and the RAGAS entries, and says the request entries do not count toward --max-judge-calls. CHANGELOG entry under Unreleased > Added.

Known gap: a request that fails before any response arrives, such as a refused connection, saves no entry of its own. If RAGAS then fails, the outcome entry records why; an attempt that a retry recovers leaves no trace. The docs say so.

Why

#303 saved every prompt judge attempt to judge_attempts.json, but for RAGAS it recorded only the outcome, with no prompt or reply. RAGAS builds its own prompts and parses its own replies, so they were not saved anywhere. A goal_accuracy score from RAGAS could not be audited like the other judge scores, and when RAGAS failed or returned a non-binary score, the reply behind that failure was lost. On main, a stubbed RAGAS run with one judge request saves only the accepted outcome entry (score 1.0), with no prompt or reply.

RAGAS runs only with the openai provider on the canonical endpoint and a judge that is not a GPT-5 or GPT-6 reasoning model.

Kept from public

  • judge_goal_accuracy and its fallback to the prompt judge are unchanged, including the binary-score check and the outcome entry.
  • _judge_goal_accuracy_ragas keeps its canonical-endpoint gate, its time budget and its cleanup: cancelling pending tasks, the bounded client close, and the close-failure warning.
  • _record_judge_attempt, _redact_judge_evidence and judge_attempts.json are used as they are. No new status logic was needed: _record_judge_attempt already takes status.
  • feat(tier3): add run budget limits with admission control and partial results #404's judge-call count is kept: salvage entries still do not count, and a RAGAS score or failure still counts once.
  • The hook runs in the verifier's own event loop. Its tasks copy the caller's context, so the hook sees the judge evidence list that main() sets. Judges run outside the verifier still save nothing.

Tests

  • New tests/tier3/test_ragas_judge_evidence.py (19 tests). The RAGAS modules are fakes, but their requests go through the real OpenAI SDK and httpx client, and a stub of the transport behind openai.DefaultAsyncHttpxClient answers them. The stub fails the test before any request if that client is not an httpx.AsyncClient. An autouse fixture refuses DNS lookups and connections beyond loopback and fails the test if one was tried, so a request the stub misses cannot reach the provider. The fixture also clears HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY in both spellings and sets NO_PROXY=*, so a proxy in the developer's shell or system settings does not change the results.
    • a request and its reply are saved as replied, before the accepted outcome. A key-shaped string in the prompt and the configured API key in the reply are both masked.
    • the reply behind a non-binary score is saved before the error outcome, and the prompt judge then runs
    • a 503 and a reply cut off mid-body are saved as error with their prompt and a redacted problem, and the retried request is then saved as replied. runner._budget_usage counts the three entries as 1 judge call (2 cases)
    • a configured key that straddles the 2000th character of a 503 body is masked whole, and the shortened problem ends with the mask and the rest of the body
    • an unreadable request body is saved as the prompt, with the selected judge model
    • every request message is read (also list content), with tool-call arguments as the reply and raw text for an unparseable body
    • a failing request parser, or a failing HTTP client setup, logs one Could not save RAGAS judge evidence warning and leaves the RAGAS score unchanged (2 cases)
    • a failed judge_attempts.json write logs Could not save judge evidence: PermissionError once per entry, no RAGAS warning, and leaves the score unchanged
    • _record_ragas_exchange and _ragas_evidence_http_client re-raise the judge deadline TimeoutError and log nothing (2 cases). This pins the helpers only, not the request flow.
    • a full main() run saves the RAGAS request between the accuracy attempt and the RAGAS outcome, and runner._budget_usage counts 2 judge calls, as on main
    • with HTTPS_PROXY or a SOCKS ALL_PROXY set, RAGAS still reaches only the stub and saves both entries (2 cases)
    • the stub fails before any request when the SDK's default async client is not an httpx client
    • an unstubbed request, a lookup or a connection beyond loopback is refused, and the guard names api.openai.com with no proxy, an HTTPS proxy or a SOCKS proxy set (3 cases)
  • New test in tests/tier3/test_run_budget.py: _budget_usage counts an llm attempt and a RAGAS outcome as 2 judge calls and skips the two ragas request entries, one error and one replied.
  • The existing RAGAS tests in tests/tier3/test_judge_failure_artifacts.py use a fake openai without DefaultAsyncHttpxClient, so they now log the evidence warning and score as before. That file is unchanged from main, which now holds fix(tier3): report missing tools as environment problems, not skill defects #379's edits to it.
  • Fail-before:
    • With eval.py from main at d717f22cf and this PR's tests, the 15 tests that exercise the evidence code fail (the 2 proxy-stub tests among them), and the SDK check and the 3 network-guard tests pass.
    • Each of these changes to eval.py fails exactly one test: no TimeoutError re-raise in _record_ragas_exchange, or in _ragas_evidence_http_client; the error body cut to 2000 characters before redaction; no fallback model for an unreadable request.
    • Without the proxy clearing and trust_env=False, the guard test with an HTTPS or a SOCKS proxy fails, and so does the SOCKS stub test when socksio is not installed. HTTPS_PROXY=http://proxy.example:3128 pytest tests/tier3/test_ragas_judge_evidence.py failed 1 of the earlier 12 tests, and ALL_PROXY=socks5://proxy.example:1080 failed 9; with this PR both give 19 passed.
    • With the earlier stub that patched only httpx.AsyncHTTPTransport, the SDK check test fails (DID NOT RAISE).
    • With runner.py from main at d717f22cf, the new budget test and the 3 budget checks in the new module fail: judge_calls is 4 instead of 2 in the budget test, 3 instead of 2 for the main() run, and 3 instead of 1 after a 503 or a cut-off reply.
  • tests/tier3 plus tests/test_accuracy_arithmetic.py, test_character_facts.py, test_harbor_metrics_truth.py, test_harbor_runtime_skill_isolation.py, test_harbor_scaffold_transactions.py, test_harbor_task_toml_retry_env.py, test_llm_judge.py, test_retry.py, test_tier3_public_runtime.py, test_transport_rules.py and test_verifier_error_redaction.py (pytest -n 4): 11509 passed, 5 skipped.
  • The new module plus tests/tier3/test_judge_contracts.py, tests/tier3/test_judge_failure_artifacts.py, tests/test_ci_workflows.py and the docs and CHANGELOG readers (test_accuracy_arithmetic.py, test_tier3_public_runtime.py, test_harbor_claude_refusal_fallback.py, test_oss_packaging.py, test_benchmark_rollout_docs.py, test_ci_change_classifier.py, tests/ci/test_image_build.py, tests/tier3/test_private_loose_source.py): 843 passed.
  • Merged with main at d717f22cf. CHANGELOG.md conflicted with docs: simplify repository CI onboarding #443's entry under Unreleased > Added; both entries are kept, this one after docs: simplify repository CI onboarding #443's. eval.py and the docs page merged cleanly, but feat(tier3): add run budget limits with admission control and partial results #404's judge-call budget needed a follow-up commit: it counted each saved RAGAS request as a judge call, so runner._budget_usage now skips those entries.
  • 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 5 commits November 7, 2026 21:41
…vidence

The RAGAS goal scorer builds its own prompts and parses its own replies,
so judge_attempts.json held only its final score. The AsyncOpenAI client
handed to RAGAS now uses the SDK's default async HTTP client with a
response hook that saves each request and the judge's reply, or the HTTP
error, as a redacted goal_accuracy attempt with method "ragas" and status
"replied" or "error". Evidence failures are only logged and never change
a score; the judge deadline alarm still passes through.

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]>
The provider stub patched only httpx.AsyncHTTPTransport. An OpenAI SDK
whose default async client is built on another HTTP stack would skip the
stub and send the tests' requests to the real provider with the fake key.

- The stub now patches the transport class of the SDK's own
  DefaultAsyncHttpxClient, and fails the test before any request when that
  client is not an httpx.AsyncClient.
- An autouse fixture refuses DNS lookups and connections beyond loopback
  and fails the test if one was tried.
- The tests that ignored the stub's request count now check it.
- A failed judge_attempts.json write is logged by _record_judge_attempt
  ("Could not save judge evidence"), not as a RAGAS evidence failure; a
  new test pins that.
- The deadline test is renamed: it pins only that _record_ragas_exchange
  re-raises TimeoutError. In a real request the SDK treats the re-raised
  error as a connection error and retries; the RAGAS time budget
  (asyncio.wait_for) still bounds the run. The earlier commit message
  said more than that.

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

The network-guard test failed when the shell set HTTPS_PROXY: the unstubbed
client looked up the proxy host, not api.openai.com. With ALL_PROXY set to a
SOCKS proxy and no socksio, every stubbed test errored because the clients
could not be built.

- no_network clears HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY in both
  spellings and sets NO_PROXY=*, so the verifier's client ignores env and
  system proxies.
- The stub's class probe and the guard test's client use trust_env=False.
- The guard test also runs with an HTTPS and a SOCKS proxy set, and a new
  test runs RAGAS through the stub with each proxy set.

New cases pin behavior no test covered:
- _ragas_evidence_http_client re-raises a TimeoutError from the client
  constructor and logs nothing.
- A configured key that straddles the 2000th character of an error body is
  masked whole.
- An unreadable request body names the selected judge model.

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]>
@rng1995
rng1995 marked this pull request as ready for review November 9, 2026 19:50
rng1995 and others added 3 commits November 10, 2026 14:57
Bring the branch up to main at d717f22.

Conflicts:
- CHANGELOG.md: under Unreleased > Added, main added the CI onboarding
  entry (#443) and this branch added the RAGAS judge evidence entry, both
  after the OpenClaw manifest entry. Both are kept, main's entry first and
  this branch's entry after it.

src/skillevaluator/tier3/harbor/templates/eval.py and
docs/tier3-live-evaluation.mdx merged without conflicts. Main's split of
_record_judge_attempt into _write_judge_attempts keeps the signature the
RAGAS evidence hook uses.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The RAGAS evidence entries saved each HTTP request RAGAS makes as its own
`ragas` entry in judge_attempts.json. The --max-judge-calls counter added
by #404 counts every non-salvage entry, so one RAGAS score counted as two
judge calls, and an SDK retry after a 503 as three. That contradicts the
documented budget, which leaves out transport retries and requests RAGAS
makes internally.

_budget_usage now skips `ragas` entries that carry a prompt. The entry
without a prompt, which holds RAGAS's score or failure, stays the single
counted call, as on main.

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

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.

Reviewed the full production diff, callers, report/runner contracts and affected regression coverage; no actionable findings. Existing CI on reviewed head 13e0ff2: 20 successful checks, 2 skipped; no failed or pending checks. Fresh merge-tree verification against current main ce52a09 succeeds without conflicts. No code changes or local test rerun were needed.

@rng1995
rng1995 merged commit 335628d into main Nov 12, 2026
22 checks passed
@rng1995
rng1995 deleted the naren/port-tier3-ragas-judge-exchange-evidence branch November 12, 2026 19:56
rng1995 added a commit that referenced this pull request Nov 12, 2026
Brings in main through b38b71b (#416, #417, #420, #422, #423, #428,
#429, #467). Merged without conflicts; CHANGELOG, docs, decoys.py and
eval_core/checks.py auto-merged with both sides' edits in separate hunks.

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