Skip to content

Add answer-quality scoring to compare suite summaries - #239

Merged
mohanagy merged 1 commit into
mainfrom
issue-233-answer-quality-summary
May 21, 2026
Merged

mohanagy merged 1 commit into
mainfrom
issue-233-answer-quality-summary

Conversation

@mohanagy

@mohanagy mohanagy commented May 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add deterministic answer-quality scoring to native_agent compare runs when the questions file has a sibling quality-gates.json
  • persist per-question answer_quality findings in report.json/report.share-safe.json and roll up suite pass/fail counts in the terminal summary
  • document that these deterministic term gates are a smoke test, not a full semantic grader

Test Plan

  • npm run typecheck
  • npm run build
  • CI=1 npm run test:run

Fixes #233

Summary by CodeRabbit

  • New Features

    • Added answer quality evaluation for compare mode with deterministic pass/fail gates, detection of missing required terms and forbidden terms in answers, and suite-level aggregated statistics.
    • Answer quality reports now display per-question results and summary metrics.
  • Documentation

    • Updated guidance for running compare with native-agent baseline mode, including JSON output format recommendations and answer quality gate reporting details.
  • Tests

    • Added test coverage for answer quality gate evaluation with and without quality-gate configuration.

Review Change Stack

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 21, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds deterministic answer-quality scoring to native_agent compare reports. The feature loads optional quality-gates.json configs alongside question definitions, evaluates baseline and graphify answers for required and forbidden term presence, tracks pass/fail counts per mode, and extends terminal summaries and report artifacts with gate evaluation results.

Changes

Answer-quality gating for native_agent compare

Layer / File(s) Summary
Answer-quality data contracts
src/infrastructure/compare.ts
NativeAgentCompareReport gains optional answer_quality object with gate metadata and per-mode evaluation results (passed boolean, missing required terms, forbidden terms). NativeAgentCompareResult gains optional aggregated summary with question counts, pass counts per mode, and aggregate term/forbidden-term findings.
Answer-quality gate loading and evaluation
src/infrastructure/compare.ts
Internal helpers load and parse quality-gates.json config, validate gate schema, normalize answer text, compute required/forbidden term matches via normalized substring containment, and aggregate suite-level pass/fail summaries from per-question evaluations.
Compare execution integration
src/infrastructure/compare.ts
executeNativeAgentCompare loads gates once when questionsPath is provided, evaluates each question's baseline and graphify answers after runs complete, attaches per-report results to report shell, and computes aggregated summary for final returned result.
Summary formatting for answer-quality results
src/infrastructure/compare.ts
formatNativeAgentCompareSummary prints top-level answer-quality line with pass/fail counts and manual-review note count, plus per-question details showing baseline/graphify PASS/FAIL status and enumerated missing/forbidden term findings.
Test coverage for answer-quality gating
tests/unit/compare.test.ts
Two test scenarios: one validates gate-based pass/fail accounting and persisted report fields when quality-gates.json exists; the other verifies answer_quality remains undefined and summaries omit the section when no gate config is present. Includes imports for compare execution and summary formatting helpers.
Documentation for answer-quality gating
docs/proof-workflows.md
Updated guidance for --baseline-mode native_agent reporting: notes Anthropic JSON usage output requirement for token-reduction metrics, suite-level comparative metrics, and how optional quality-gates.json results are aggregated from saved answer artifacts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • mohanagy/graphify-ts#215: Introduces standalone verify-answer-quality.js verifier performing deterministic rubric checks against saved answer artifacts using the same quality-gates.json gate evaluation logic.
  • mohanagy/graphify-ts#210: Extends native-agent compare suite-level reporting with input-token/turn/latency win-loss and mean/median rollups, modifying the same formatNativeAgentCompareSummary output path.
  • mohanagy/graphify-ts#211: Adds cache-aware Anthropic uncached/cache token lines to the same formatNativeAgentCompareSummary formatter, overlapping at the shared summary-generation logic.

Poem

🐰 A gate checks the answers true,
Required terms, forbidden few,
No tokens lost to faulty prose—
Fewer words, same quality flows!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding answer-quality scoring to compare suite summaries.
Description check ✅ Passed The PR description includes a summary of changes and test plan. The checklist items are present but not marked. Documentation and testing are covered in the objectives.
Linked Issues check ✅ Passed All coding requirements from issue #233 are met: deterministic quality-gate evaluation [#233], per-question and suite-level reporting [#233], terminal summary output [#233], and documentation that gates are smoke tests [#233].
Out of Scope Changes check ✅ Passed All changes are scoped to adding answer-quality features: updates to docs, core compare logic, test coverage, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-233-answer-quality-summary

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/infrastructure/compare.ts (1)

2556-2559: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Preserve answer_quality output for answer_only native-agent runs.

This early return skips the new deterministic gate details whenever either side is answer_only. That path is already treated as a supported native-agent result elsewhere, so suite summaries will silently omit answer_quality even though executeNativeAgentCompare() computed and persisted it.

💡 Suggested fix
-    if (report.baseline.kind === 'answer_only' || report.graphify.kind === 'answer_only') {
-      lines.push(`- "${report.question}" → answer-only run saved; no Anthropic usage block was available, so provider-proof reductions were not computed (see ${portablePath(report.paths.report)})`)
-      continue
-    }
+    const isAnswerOnlyRun = report.baseline.kind === 'answer_only' || report.graphify.kind === 'answer_only'
+    if (isAnswerOnlyRun) {
+      lines.push(
+        `- "${report.question}" → answer-only run saved; no Anthropic usage block was available, so provider-proof reductions were not computed (see ${portablePath(report.paths.report)})`,
+      )
+      if (report.answer_quality) {
+        const baselineFindings = [
+          ...report.answer_quality.baseline.missing_required_terms.map((term) => `missing ${term}`),
+          ...report.answer_quality.baseline.forbidden_terms_present.map((term) => `forbidden ${term}`),
+        ]
+        const graphifyFindings = [
+          ...report.answer_quality.graphify.missing_required_terms.map((term) => `missing ${term}`),
+          ...report.answer_quality.graphify.forbidden_terms_present.map((term) => `forbidden ${term}`),
+        ]
+        lines.push(
+          `    answer quality: baseline ${report.answer_quality.baseline.passed ? 'PASS' : `FAIL (${baselineFindings.join(', ')})`} · graphify ${report.answer_quality.graphify.passed ? 'PASS' : `FAIL (${graphifyFindings.join(', ')})`}${report.answer_quality.manual_review_notes.length > 0 ? ` · manual review: ${formatCount(report.answer_quality.manual_review_notes.length, 'note', 'notes')}` : ''}`,
+        )
+      }
+      continue
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/infrastructure/compare.ts` around lines 2556 - 2559, The current
early-continue that checks report.baseline.kind === 'answer_only' ||
report.graphify.kind === 'answer_only' both suppresses provider-proof reduction
text and also prevents emitting the previously-computed answer_quality for
native-agent runs; change the handling so we still preserve and emit
answer_quality from executeNativeAgentCompare() while only skipping the
provider-proof reduction block. Concretely, in the block that references
report.baseline.kind/report.graphify.kind and portablePath(report.paths.report),
remove the unconditional continue and instead push the “answer-only run saved;
no Anthropic usage block…” message but allow the subsequent code that writes
deterministic gate / answer_quality details (the code that reads
report.answer_quality or calls executeNativeAgentCompare results) to run; if
necessary, guard only the provider-proof reduction logic with the answer_only
condition rather than the entire early-return.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/infrastructure/compare.ts`:
- Around line 2556-2559: The current early-continue that checks
report.baseline.kind === 'answer_only' || report.graphify.kind === 'answer_only'
both suppresses provider-proof reduction text and also prevents emitting the
previously-computed answer_quality for native-agent runs; change the handling so
we still preserve and emit answer_quality from executeNativeAgentCompare() while
only skipping the provider-proof reduction block. Concretely, in the block that
references report.baseline.kind/report.graphify.kind and
portablePath(report.paths.report), remove the unconditional continue and instead
push the “answer-only run saved; no Anthropic usage block…” message but allow
the subsequent code that writes deterministic gate / answer_quality details (the
code that reads report.answer_quality or calls executeNativeAgentCompare
results) to run; if necessary, guard only the provider-proof reduction logic
with the answer_only condition rather than the entire early-return.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c5b2e478-1a44-4571-8f46-437c6836925d

📥 Commits

Reviewing files that changed from the base of the PR and between 07f895b and 29d9a38.

📒 Files selected for processing (3)
  • docs/proof-workflows.md
  • src/infrastructure/compare.ts
  • tests/unit/compare.test.ts

@mohanagy
mohanagy merged commit b388937 into main May 21, 2026
7 checks passed
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.

[P1] Add answer-quality scoring to benchmark suite summaries

1 participant