Skip to content

fix(eval): let the email judge run on the subscription credential - #3490

Merged
kovtcharov-amd merged 8 commits into
mainfrom
fix/email-eval-judge-credential
Sep 25, 2026
Merged

kovtcharov-amd merged 8 commits into
mainfrom
fix/email-eval-judge-credential

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

The Email Agent Eval has been red on main and on every open PR for weeks, dying ~25 minutes into each run. It is not measuring anything: the Anthropic account behind the ANTHROPIC_API_KEY secret is out of credit, and that key was the only credential the three judge-scored email evals could use. This routes them onto the Claude Code subscription token that every other Claude workflow here already prefers, and makes the preflight prove the credential works instead of merely existing — so a dead credential costs 10 seconds rather than 25 minutes of the single serial Lemonade slot.

A subscription token can't authenticate a direct Messages API call, so it is driven through claude -p (the transport gaia.eval.runner already uses); the API key keeps the SDK path. Neither present is still a loud failure, never a skip.

Test plan

  • Dispatch this workflow on the branch; the preflight should pass in ~10s and the drafting/action-item/briefing evals should score rather than die
  • Point the preflight at a bogus token and confirm it fails with an actionable message, before Lemonade starts
  • pytest tests/unit/test_eval_judge_client.py hub/agents/email/python/tests/ — 41 passing
  • Dispatch email_scorecard_refresh.yml as a subset run (it gets the same transport and never commits)

Notes for the reviewer

🔍 Technical details

Two failure modes the old preflight could not catch. It asserted the env var was non-empty, which an out-of-credit key satisfies — hence weeks of red. It now sends one trivial prompt down the real transport. Separately, claude -p exits 0 on an API error and prints the error as its result (verified: a bogus model returns is_error: true, subtype: "success", exit 0), so --output-format text would have handed the judge "API Error: 400 ..." as a verdict. The transport reads --output-format json and raises on is_error.

Judge comparability. Committed baselines and SCORECARD.md were scored by the SDK judge. The CLI judge runs with Claude Code's agent prompt replaced, tools denied, MCP servers off, --setting-sources "" and an empty cwd — measured, that cuts the injected context from ~31K tokens to ~200, so it sees the rubric and little else. Worth an A/B before trusting a refreshed scorecard.

Latency. Measured 12.6 / 13.3 / 13.7s per call on a 31KB prompt with the production argv. 51 judge calls ≈ 11 min against a 90-min budget — and the refresh workflow's own header records the SDK drafting judge alone taking 21 min, so this is likely faster.

Not fixed here, stated plainly. If the judge answers but every reply is unparseable, drafting and action-item record per-case errors, their gate comes back skipped, and the step still exits 0. Only briefing fails on that. The workflow header claimed otherwise; it now says what the code does. Closing it means changing those scripts' exit semantics and the committed tests that pin them — its own change.

Scope note. get_completion also stopped making a count_tokens round-trip on every call just to write a debug line. It was the frame the 400 surfaced in, and it doubled judge API calls.

Relationship to #3403. That PR fixes the same class of failure for test_eval_agent_gemma_consolidation.yml and explicitly leaves the email evals out of scope ("they will keep failing until the account is funded"). This is the email half; the two do not overlap.

Ovtcharov added 2 commits September 4, 2026 18:31
… the repo

Nine design and reference docs were sitting untracked in the working copy,
so the decisions they record were invisible to everyone else — including the
skill-bound task execution design that the async-task and multi-slot-broker
work is meant to build against.

Alongside them sat a 45MB mailbox corpus, agent-run captures, and internal
analysis, none of which were gitignored. `git add -A` would have committed a
mailbox to a public repo. The ignore block that already quarantines private
working reports now covers those classes too, and its pointer to where that
material lives is corrected — the path it named has not existed for some time.
The Email Agent Eval has failed on every branch for weeks, ~25 minutes into
each run. The Anthropic account behind the ANTHROPIC_API_KEY repo secret is out
of credit, and that key was the only credential the three judge-scored email
evals could use.

Every other Claude workflow in this repo already prefers CLAUDE_CODE_OAUTH_TOKEN.
A subscription token cannot authenticate a direct Messages API call, so
gaia.eval.judge_client drives it through `claude -p` instead and keeps the SDK
path for the API key. Neither credential present is still a loud failure.

Two things the old preflight could not catch, now covered:

- It asserted the variable was non-empty, which an out-of-credit key satisfies.
  It now sends one trivial prompt down the real transport, so a dead credential
  costs 10 seconds instead of 25 minutes of the serial Lemonade slot.
- `claude -p` exits 0 on an API error and prints the error as its result, so
  --output-format text would have handed the judge "API Error: 400 ..." as a
  verdict. The transport reads --output-format json and raises on is_error.

The judge runs with Claude Code's agent prompt replaced, tools denied, MCP
servers off, settings sources cleared and an empty cwd, so a CLI verdict is
scored from the rubric alone — as close to the SDK judge as the transport gets.

Also drops the count_tokens round-trip that get_completion made on every call
just to write a debug line; it was the frame the 400 surfaced in.
@github-actions github-actions Bot added documentation Documentation changes devops DevOps/infrastructure changes eval Evaluation framework changes tests Test changes performance Performance-critical changes agent::email Email agent changes sidecar Agent sidecar contract / harness labels Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
hub/agents/email/npm ✅ ALLOW experimental experimental, community 2 medium, 1 info code.suppression, supply.undeclared_dependency
hub/skills/coding ✅ ALLOW community experimental, community 4 info permission.unused
hub/skills/transcribe-meeting ✅ ALLOW community experimental, community none —

✅ All audited skills cleared the tier they claim.

Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the skill-audit-reports artifact from this run. Offending source text is withheld from CI everywhere — reproduce it locally with gaia skill audit <dir> --show-snippets.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This unblocks the Email Agent Eval, which has been red on every branch for weeks because the only judge credential it accepted belonged to an out-of-credit account. The evals can now run on the Claude Code subscription token, and the preflight proves the credential actually works before the run claims 25 minutes of the single Lemonade slot. The transport work itself is careful and well tested — the one thing to fix before merge is a documentation claim that contradicts the code.

Worth fixing:

  • Five places say the subscription token is preferred and that the code picks it. The code prefers the API key. The preference actually lives in the workflow YAML, which blanks the key when the token is set — so CI does the right thing, but anyone with both credentials set on their own machine quietly runs the judge on the billed API key while every doc tells them otherwise. Either reword the docs or flip the code so the two agree.
  • A new plan doc tells readers to start Lemonade with a command that no longer exists. Current Lemonade installs removed that CLI, and the project rule is to describe how the server starts rather than name a binary the host may not have.

Worth knowing (not blocking): the committed baselines and SCORECARD.md were scored by the old transport, and the scorecard-refresh workflow can now commit numbers produced by the new one. The PR description already calls for an A/B first — worth making that a precondition on the next refresh dispatch rather than a note, since that workflow commits its result.

Real-world evidence

The evidence bundle is present and substantial, and it supports the verdict: the change is exercised on the surfaces this lane can reach, and the before→after is real rather than asserted.

Same environment, subscription token present and no API key — before the change the gate refused to run at all:

[BRIEF-EVAL] ERROR: ANTHROPIC_API_KEY is not set on this runner — the Claude judge cannot score briefings. ...
exit=1

After, the credential is accepted and the run proceeds until it hits the boundary this runner genuinely can't cross (no Lemonade, no gaia_agent_email installed):

[BRIEF-EVAL] manifest: .../briefing_gate_thresholds.json
[BRIEF-EVAL] enforce=False approval_min=0.7 recall_min=0.8 hallucination_free_min=0.95
RuntimeError: The briefing eval needs the email agent. ... install it from source instead: ...
exit=1

The exact CI credential shape was checked, not assumed — the workflow blanks the key to an empty string rather than unsetting it, and that still selects the CLI transport:

$ env ANTHROPIC_API_KEY= CLAUDE_CODE_OAUTH_TOKEN=dummy-not-a-real-token ...
judge_credential_present -> True
selected transport      -> ClaudeCliClient

And every flag in the outgoing call was verified against the installed CLI's own --help rather than a mock, which is the check this class of change usually skips:

$ claude --version
2.1.218 (Claude Code)
  OK  -p            OK  --model               OK  --output-format
  OK  --system-prompt   OK  --setting-sources     OK  --strict-mcp-config
  OK  --mcp-config      OK  --disallowed-tools    OK  --no-session-persistence

Deferred, and stated in the bundle rather than glossed: no live probe against the real secret (the evidence lane doesn't run credential flows), and no end-to-end judged eval — that needs Lemonade and is pending the strix-halo lane. Screenshot evidence is correctly N/A; this PR touches no UI surface. So the claim "the evals will now score green in CI" rests on the workflow's own preflight on a legitimate run, not on anything proven here — that's the right place for it, but it is the one thing the dispatch in the test plan still has to confirm.

🔍 Technical details

🟡 Docs claim a credential preference the code doesn't implement

make_judge_client returns the SDK client whenever ANTHROPIC_API_KEY is non-empty (src/gaia/eval/judge_client.py:233), so the API key wins when both are set. The preference is implemented by the workflow expression secrets.CLAUDE_CODE_OAUTH_TOKEN == '' && secrets.ANTHROPIC_API_KEY || '' — the established house pattern (claude.yml:1071, claude-run.yml:269), so the YAML is right. The prose is what's wrong, and it says the opposite in five places:

  • .github/workflows/release_agent_email.yml:52-56 — "the subscription token is preferred and the key is the fallback (the choice lives in gaia.eval.judge_client)"
  • .github/workflows/test_email_agent_eval.yml:45-48 — "the selection lives in src/gaia/eval/judge_client.py, not here"
  • .github/workflows/test_email_agent_eval.yml:218-222 — the workflow_call secret descriptions, where ANTHROPIC_API_KEY is documented as "used only when CLAUDE_CODE_OAUTH_TOKEN is unset". That is a caller-facing contract and it is false for a caller that passes both explicitly.
  • hub/agents/email/python/packaging/eval_drafting_report.py:17,25
  • hub/agents/email/npm/EVALUATION.md:89

Two ways out. Reword to "the workflows prefer the subscription token by blanking the key; judge_client uses whichever it is handed, key first" — or flip the code, which makes every doc true as written and lets the workflows drop the blanking expression:

    if oauth_token:
        return ClaudeCliClient(model=model)
    if api_key:
        from gaia.eval.claude import ClaudeClient

        return ClaudeClient(model=model)
    raise ValueError(MISSING_CREDENTIAL_ERROR)

(That flip also needs test_api_key_wins_when_both_are_set in tests/unit/test_eval_judge_client.py:104 inverted.) Either is fine; the current split is not, per CLAUDE.md's rule that a behavior described in N docs must be correct in N docs.

🟡 lemonade-server serve in a new plan doc

docs/plans/email-eval-node-frontend.mdx:130 instructs the reader to run it. CLAUDE.md is explicit that Lemonade 10.7/10.8 removed that CLI and that no portable substitute exists — point at gaia init or describe_start_hint() (src/gaia/llm/lemonade_launcher.py) instead of naming a binary.

# Terminal 1 — Lemonade must already be running (canonical discovery port 13305,
# NOT 8000). `gaia init` is the one path that starts it; there is no portable
# `lemonade-server` command — see describe_start_hint() in lemonade_launcher.py.

🟢 The presence-only guard still burns generation when the CLI is missing

judge_credential_present() passes with an OAuth token set and no claude on PATH; the actionable RuntimeError from ClaudeCliClient.__init__ only fires at make_claude_judge(), which runs after generate_drafts (eval_drafting_report.py:85). In CI the new preflight covers this, but a local run pays the full Lemonade pass first — exactly the cost this PR exists to remove. Constructing the judge up front closes it (same shape in eval_briefing_report.py and eval_action_item_report.py):

    # Build the judge before generation: a token set without the `claude` CLI on
    # PATH should cost a second, not a full Lemonade pass.
    judge = make_claude_judge()

    # Generation: drives the #1607 voice-profile drafting path per case
    # (Lemonade — this job holds the serial lemonade-eval slot).
    generations = generate_drafts(model, corpus_path=CORPUS_PATH)

🟢 Pin the CLI install

test_email_agent_eval.yml:371 and email_scorecard_refresh.yml:244 install @anthropic-ai/claude-code unpinned on a long-lived self-hosted runner, and the new transport depends on a specific flag set. Other workflows here already pin (claude-run.yml:307 → @2.1.218, claude-weekly-doc-walkthrough.yml:246 → @^2).

          npm install -g "@anthropic-ai/claude-code@^2"

🟢 --disallowed-tools value is one space-separated string

judge_client.py:153 passes all eleven names as a single argv token. The evidence bundle confirms the flag exists on 2.1.218, not that this value parses as a list — the CLI's own docs use repeated/comma-separated values. If it parses as one unknown tool name, nothing is actually disallowed and the failure is silent (mitigated only by the empty cwd and the empty MCP config). Worth one claude -p --disallowed-tools "Bash Read" ... check against the pinned version.

🟢 A personal path in a shared .gitignore comment

.gitignore:280,305 now name ~/Work/gaia-private/. The prior ../gaia-private-reports/ was machine-agnostic; the new one describes one contributor's home layout to every reader of the file.

Process note

The PR bundles the judge-transport fix with seven unrelated plan/reference docs and a .gitignore change. Not blocking, but it makes the diff 3.5K lines for a ~300-line fix and pushes the real change past where most reviewers stop.

Strengths

  • The subtle failure was found and tested, not shipped. claude -p exits 0 on an API error and prints it as the result, so --output-format text would have scored every case with the string "API Error: 400 ..." and reported a wholly unjudged run as green. Reading is_error and raising is the right call, and test_api_error_on_a_zero_exit_is_not_returned_as_a_verdict pins it.
  • The preflight is a live probe, not a presence check — which is precisely the distinction CLAUDE.md's "mocks prove we called it, not that the call is valid" rule asks for, and it is what the previous non-empty-string check missed for weeks.
  • Test coverage matches the risk surface: transport selection, empty-string credentials (the exact shape CI produces), stdin delivery of long prompts, context isolation flags, timeout, non-JSON stdout, empty reply.
  • The count_tokens guard (src/gaia/eval/claude.py:139) removes a second billed round-trip per judge call that only ever fed a debug line.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🟡 Two findings from the first review are still unfixed in this push.

The "selection lives in judge_client" comment still points the wrong way. release_agent_email.yml was updated to say "the subscription token is preferred and the key is the fallback (the choice lives in gaia.eval.judge_client)" — but make_judge_client picks the API key first and the OAuth token second. The code is right; the comment is backwards. Same error remains in the test_email_agent_eval.yml header ("prefer CLAUDE_CODE_OAUTH_TOKEN...fall back to ANTHROPIC_API_KEY").

lemonade-server serve is still in the new plan doc. docs/plans/email-eval-node-frontend.mdx still tells readers to run it. That binary is gone since Lemonade 10.7.

🔍 Technical details

release_agent_email.yml:95 (added in this PR):

the subscription token is preferred and the key is the fallback (the choice lives in gaia.eval.judge_client)

judge_client.py:3776-3781 (also added in this PR):

if api_key:
    return ClaudeClient(model=model)   # ← API key wins
if oauth_token:
    return ClaudeCliClient(model=model)

The docstring on make_judge_client was correctly updated ("ANTHROPIC_API_KEY wins when both are set"), but the workflow comments were not. Either flip those two sentences or flip the code preference; the split is the bug.

docs/plans/email-eval-node-frontend.mdx:457 still contains lemonade-server serve. Per CLAUDE.md, point at gaia init or call describe_start_hint() (src/gaia/llm/lemonade_launcher.py) instead.

These three assert the judge factories never send a `temperature`, by spying on
ClaudeClient. Routing the factories through judge_client made them read the
environment first, so on a runner with no credential they raised before ever
reaching the spy — green locally (a stray .env supplies a key) and red in CI.

Set the key and clear the token in the fixture, so the transport under test is
the one the assertion is about rather than whatever the machine happens to have.
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🟡 The credential-preference mismatch flagged in the prior review is still open, and this push adds more incorrect claims rather than fewer.

make_judge_client checks ANTHROPIC_API_KEY first, and JUDGE_CREDENTIAL_VARS = ("ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN") with "in the order they are preferred" — both say the API key wins. But three eval-script docstrings added in this push (drafting, action-item, briefing) each now read CLAUDE_CODE_OAUTH_TOKEN Judge credential, preferred, ANTHROPIC_API_KEY Judge credential, fallback — the opposite. release_agent_email.yml got a new comment with the same backwards claim: "the subscription token is preferred and the key is the fallback (the choice lives in gaia.eval.judge_client)". That comment names judge_client as the authority, but judge_client disagrees.

The lemonade-server serve line in docs/plans/email-eval-node-frontend.mdx (flagged in the prior review) is also still there.

🔍 Technical details

JUDGE_CREDENTIAL_VARS and make_judge_client are consistent with each other: API key wins. Everything else in this push says the opposite. The contradiction is now internal to the same file (judge_client.py constant vs. the scripts that import from it).

New incorrect claims introduced by this push:

  • hub/agents/email/python/packaging/eval_drafting_report.py:25 — "preferred … fallback" order reversed
  • hub/agents/email/python/packaging/eval_action_item_report.py:23 — same
  • hub/agents/email/python/packaging/eval_briefing_report.py:22 — same
  • .github/workflows/release_agent_email.yml:95 — "subscription token is preferred … key is the fallback"
  • hub/agents/email/npm/EVALUATION.md:89 (updated) — "CLAUDE_CODE_OAUTH_TOKEN (preferred)"

Fix: either flip the two if branches in make_judge_client (token first, key fallback — which also requires inverting the test_api_key_wins_when_both_are_set test), or reword every "preferred/fallback" label to match the current API-key-first behaviour.

docs/plans/email-eval-node-frontend.mdx:130 still has lemonade-server serve; CLAUDE.md says that binary was removed in Lemonade 10.7/10.8 and must not be named in instructions.

Ovtcharov and others added 3 commits September 11, 2026 19:00
Only `.gitignore` conflicted: both sides appended a new block at the end of
the file. Kept both — the local-scratch block from this branch and the
frozen-agent build block from main.
Follow-up fixes for #3490. Changed:
.github/workflows/{email_scorecard_refresh,test_email_agent_eval,release_agent_email}.yml;
.gitignore; docs/plans/email-eval-node-frontend.mdx;
hub/agents/email/npm/EVALUATION.md;
hub/agents/email/python/packaging/eval_{action_item,briefing,drafting}_report.py;
src/gaia/eval/judge_client.py; tests/unit/test_eval_judge_client.py;
hub/agents/email/python/tests/test_eval_{drafting,briefing}_report.py.
Exact changed path list is available from git diff.

This PR targets the original feature branch because the current account
cannot push to `amd/gaia`. It carries the prepared maintenance changes
for that PR.

## Test plan

- [x] Previously completed local validation: Validation: 43 tests passed
covering judge selection, CLI invocation/error handling and all three
report scripts (tests-3490.log). Exact live ClaudeCliClient transport
using the existing authenticated Max subscription returned ['OK'] in
about four seconds (3490-judge-probe.log). This proves actual tool
flags/model/auth invocation works, not only mocked selection. All three
workflow YAML files parse; Black/isort/Flake8/diff pass.
- [ ] Fresh CI on the combined feature branch.
- [ ] Remaining live-model, hardware or platform checks described in the
original PR, where applicable.
- [ ] Human review before merging the original PR.
# Conflicts:
#	.github/workflows/test_email_agent_eval.yml
#	docs/plans/email-triage-skill.mdx
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Every item in this review has already been fixed — the comment predates the current head by two weeks and was never re-run.

The credential docs and the code now agree: ANTHROPIC_API_KEY wins when both are set, and the five places that claimed the opposite no longer say it. The lemonade-server serve line is gone too. I checked all six sites against the branch as it stands rather than trusting either side.

Nothing to do here. The PR is mergeable.

🔍 Technical details

Verified at 5d8ab8e67 (review was written against the 2026-09-08 head).

The code is unchanged and deliberate — make_judge_client still prefers the key, and says why:

ANTHROPIC_API_KEY wins when both are set — the workflow blanks it when it wants the subscription path, matching every other Claude workflow here.

So the resolution taken was the second of the two the review offered: reword the labels to match API-key-first behaviour, rather than flip the if branches and invert test_api_key_wins_when_both_are_set. That is the right half to move — the blank-the-var-to-choose-the-path convention is shared with the other Claude workflows, and flipping the code would have made this one the odd one out.

Site by site:

Claimed Now
eval_drafting_report.py:25 "preferred … fallback" gone — no credential-ordering claim in the file
eval_action_item_report.py:23 gone
eval_briefing_report.py:22 gone
release_agent_email.yml:95 "subscription token is preferred" gone; the only remaining fallback) at :74 is about GAIA_HUB_PUBLISH_URL, unrelated
EVALUATION.md:89 "CLAUDE_CODE_OAUTH_TOKEN (preferred)" now CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY (takes precedence when both are set) — matches the code
docs/plans/email-eval-node-frontend.mdx:130 lemonade-server serve gone

Unrelated but worth knowing before anyone reads this PR's eval lanes: the judge credential's org is out of monthly spend (#4080) until Sep 23 8am Pacific, so a red eval check on this branch right now measured nothing.

Main added judge-outage classification (judge_completion_text /
JudgeOutageError) to the three email judges while this branch moved them
onto make_judge_client. The two are orthogonal — kept both: the judges
select their transport by credential and still name an outage instead of
scoring it.

Main's TestJudgeFactoriesClassify patched gaia.eval.claude.ClaudeClient
directly, which this branch only reaches when ANTHROPIC_API_KEY is set,
so it failed on a keyless runner. The helper now pins the transport.

Also repoints this branch's new setup-node comment at eval_flagship.yml,
which main renamed from test_eval_agent_gemma_consolidation.yml.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 25, 2026
Merged via the queue into main with commit fae6fa3 Sep 25, 2026
42 of 54 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/email-eval-judge-credential branch September 25, 2026 18:21
@github-actions

Copy link
Copy Markdown
Contributor

🟡 A new test in the action-item test file will fail with AttributeError when run — it patches generate_briefings, which doesn't exist on the action-item report module.

The test test_missing_judge_transport_fails_before_generation in test_eval_action_item_report.py was copied from the briefing test but the function name wasn't updated: the action-item report imports generate_extractions, not generate_briefings. monkeypatch.setattr(mod, "generate_briefings", generate) will raise AttributeError before the test body even runs.

🔍 Technical details

hub/agents/email/python/tests/test_eval_action_item_report.py — new test at the bottom of the file:

# wrong: eval_action_item_report has no generate_briefings attribute
monkeypatch.setattr(mod, "generate_briefings", generate)

eval_action_item_report.py imports generate_extractions (line 37), not generate_briefings. monkeypatch.setattr with the default raising=True will raise AttributeError on a missing attribute, so the test fails before reaching the assertion.

Fix — swap the function name:

    monkeypatch.setattr(mod, "generate_extractions", generate)

The analogous tests in test_eval_briefing_report.py and test_eval_drafting_report.py correctly use generate_briefings and generate_drafts respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes devops DevOps/infrastructure changes documentation Documentation changes eval Evaluation framework changes performance Performance-critical changes sidecar Agent sidecar contract / harness tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants