Skip to content

fix(eval): read past thinking blocks in the Claude judge response - #3885

Merged
itomek merged 1 commit into
mainfrom
autofix/issue-3884
Sep 15, 2026
Merged

itomek merged 1 commit into
mainfrom
autofix/issue-3884

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Every eval that judged through the Python Claude client died on the judge's first reply with AttributeError: 'ThinkingBlock' object has no attribute 'text' — the default judge model answers with a thinking block first, and the client always read block zero. The judge now reads the first text block, so it works against its own default model; a response with no text block at all raises an error naming the model and the block types instead of degrading to an empty reply, which would have parsed as a failed case and quietly lowered the score.

Closes #3884

Test plan

  • python -m pytest tests/unit/eval/ -q passes (530 tests)
  • python util/lint.py --all passes
  • With a judge credential on the box, an eval that uses the Python judge completes a case against DEFAULT_CLAUDE_MODEL without an AttributeError — e.g. gaia eval session or the email quality judges. This needs a live API call, so it was not run here.

⚠️ Needs manual validation — lint and the unit suite confirm no Python regression and pin the [thinking, text] shape with mocks, but nothing here makes a real API call. A maintainer with ANTHROPIC_API_KEY set should run one judged eval before merging.

🔍 Technical details

Root cause. ClaudeClient unpacked replies as message.content[0].text in four places (src/gaia/eval/claude.py — the two analyze_file branches and the two analyze_file_with_usage branches). claude-opus-5 (DEFAULT_CLAUDE_MODEL) returns [thinking, text], so block zero is a ThinkingBlock with no .text. The HTTP call succeeded; only the unpacking failed, which is why it surfaced as a client-side AttributeError.

Change. New module-level first_text_block(blocks, model) in claude.py returns the first block carrying text and otherwise raises a ValueError naming the model and the block types received. ClaudeClient._extract_text(message) wraps it, and all four sites call that. Selection is duck-typed on the presence of .text rather than type == "text", matching the existing pattern in action_item_quality.py / draft_quality.py / briefing_quality.py and keeping the SDK's non-text block types (thinking, redacted_thinking, tool_use) out.

pdf_document_generator.py had the same indexing bug on the raw block list returned by get_completion_with_usage (both the generate and the extend path), so it uses the same helper. The three judge factories and session_eval._as_text already filtered on hasattr(block, "text") and were unaffected.

Tests. tests/unit/eval/test_claude_judge.py adds TestFirstTextBlock (skips a leading thinking block; returns the first of several text blocks; raises naming model + block types; raises on empty content) and TestExtractionPathsWithThinkingBlock (all four extraction paths against a [thinking, text] response, plus the no-text-block raise). tests/unit/eval/test_pdf_document_generator.py pins the generator path. No live API call in any of them.

One discrepancy with the issue. The issue lists gaia eval agent --category tool_selection as an acceptance criterion, but that runner scores via the claude -p CLI subprocess (src/gaia/eval/runner.py), not ClaudeClient — so this fix does not touch that path, and neither does it fix #3341. The in-process judges (session_eval, the email quality judges) and the document generators are the callers this actually unblocks. Worth confirming before closing #3884 on the strength of criterion 4.

Not validated here: the full tests/unit/ run had 6 pre-existing environment failures unrelated to this change (sherpa_onnx not installed; pip absent inside the uv-created venv, which test_hub_installer.py shells out to).

The judge's default model (claude-opus-5) answers with [thinking, text], so
every extraction that indexed content[0] hit a ThinkingBlock and raised
AttributeError on the judge's first reply. Select the first text-typed block
instead, and raise naming the model and the block types received when a
response carries no text at all — an empty reply would parse as a failed case
and quietly lower the score.

Also fixes the same indexing in the PDF fixture generator, which reads the raw
block list returned by get_completion_with_usage.

Closes #3884
@itomek
itomek marked this pull request as ready for review September 15, 2026 14:29
@itomek
itomek added this pull request to the merge queue Sep 15, 2026
Merged via the queue into main with commit 995bafb Sep 15, 2026
32 of 35 checks passed
@itomek
itomek deleted the autofix/issue-3884 branch September 15, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant