Skip to content

Add benchmark-readiness preflight for native-agent compare - #392

Merged
mohanagy merged 2 commits into
nextfrom
issue-387-benchmark-preflight
May 28, 2026
Merged

mohanagy merged 2 commits into
nextfrom
issue-387-benchmark-preflight

Conversation

@mohanagy

@mohanagy mohanagy commented May 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add retrieval-backed benchmark-readiness assessment for native-agent compare
  • record readiness in report JSON/summary and fail early under strict mode before runner spend
  • expose strict readiness via madar compare --strict / --strict-benchmark-readiness

Closes #387

Summary by CodeRabbit

  • New Features

    • Added --strict / --strict-benchmark-readiness flag to the compare command to enforce benchmark-readiness checks.
    • Compare output now shows a benchmark readiness status, reasons, and suggested next-step graph scope.
  • Documentation

    • CLI help and usage updated to document the new --strict / --strict-benchmark-readiness flag and usage string.
  • Tests

    • Added unit tests covering benchmark-readiness assessment, reporting, strict-mode behavior, and CLI parsing.

Review Change Stack

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

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR adds a benchmark-readiness assessment feature that evaluates whether a native-agent compare run is likely to produce reliable results, considering graph scope, SPI support, execution phases, and confidence metrics. It introduces a new --strict / --strict-benchmark-readiness CLI flag that gates compare runs and reports readiness status to users.

Changes

Benchmark Readiness Assessment & CLI Integration

Layer / File(s) Summary
CLI Parser: strictBenchmarkReadiness Option
src/cli/parser.ts, tests/unit/cli.test.ts
CompareCliOptions adds strictBenchmarkReadiness: boolean field. CLI parsing recognizes --strict and --strict-benchmark-readiness flags to enable readiness strictness. Usage text and help documentation are updated. Tests verify parser output and option aliasing.
CLI Main: wiring and error translation
src/cli/main.ts
strictBenchmarkReadiness option is forwarded into runCompareCommand. BenchmarkReadinessError is imported and caught to rethrow as a UsageError. Help text for compare documents --strict / --strict-benchmark-readiness.
Readiness Assessment Core Logic
src/infrastructure/compare.ts, tests/unit/compare.test.ts
assessBenchmarkReadinessFromRetrieveResult evaluates readiness by checking critical execution phases, detecting SPI evidence, assessing confidence, and suggesting narrower graph scope. Returns BenchmarkReadiness with status ('ready', 'degraded', 'not_ready'), reasons, and optional suggested_graph_scope. New types BenchmarkReadinessStatus, BenchmarkReadiness, and BenchmarkReadinessInput define the interface. Unit tests cover non-SPI, SPI-degraded, and backend SPI-ready scenarios.
Native Agent Integration & Readiness Error
src/infrastructure/compare.ts, tests/unit/compare-native-agent.test.ts
NativeAgentCompareReport gains optional benchmark_readiness field. ExecuteNativeAgentCompareDependencies accepts injectable assessBenchmarkReadiness function. executeNativeAgentCompare conditionally loads graph, computes/injects readiness, populates report, and throws BenchmarkReadinessError when strictBenchmarkReadiness is enabled and status is not 'ready'. Unit tests verify readiness is persisted in report.json and formatted in summary output, and verify early failure when strict mode rejects non-ready status.
Tests: coverage and CLI routing
tests/unit/*
CLI tests updated to expect strictBenchmarkReadiness in parser output and routed compare requests. New readiness-focused tests validate classification, persisted report payloads, summary formatting, and strict-mode gating behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • mohanagy/madar#387: P1 issue requesting benchmark-readiness preflight assessment that gates compare when graph scope or SPI support is unsuitable, which this PR directly addresses with strict-mode gating and readiness reporting.

Possibly related PRs

  • mohanagy/madar#343: Modifies native-agent compare execution and report fields; related to reporting/gating changes here.
  • mohanagy/madar#321: Also extends executeNativeAgentCompare reporting; overlaps at compare/report integration points.
  • mohanagy/madar#239: Touches executeNativeAgentCompare and summary/report formatting; adjacent to this PR's diagnostics additions.

Poem

"A rabbit hops to check the ground,
Before the heavy compare is found.
SPI and scope it scans with care,
Suggests a tweak, then stops to stare.
Hop on, small check — avoid the wear! 🐇"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add benchmark-readiness preflight for native-agent compare' accurately summarizes the main change: adding benchmark readiness assessment as a preflight check.
Description check ✅ Passed The description provides a clear summary and references the closed issue, though it lacks some template sections like Testing checklist and detailed verification steps.
Linked Issues check ✅ Passed The PR implementation aligns with all key requirements from issue #387: benchmark readiness assessment, early failure under strict mode, CLI flags, and report JSON recording.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing benchmark-readiness assessment; no unrelated modifications detected across CLI, parser, infrastructure, and test files.

✏️ 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-387-benchmark-preflight

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.

Actionable comments posted: 1

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)

3515-3590: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Run strict benchmark-readiness as a full preflight before any arm execution.

strictBenchmarkReadiness is enforced inside the question execution loop. That means earlier questions may already consume runner resources before a later question fails strict readiness, and the failing question’s readiness is not persisted before throwing. This undermines fail-fast behavior for suite runs.

🤖 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 3515 - 3590, The strict
benchmark-readiness check is currently performed inside the questions loop (when
building reportShell) which lets earlier questions consume resources before a
later question fails; fix by preflighting all questions before any execution:
iterate over questions and compute readiness using assessBenchmarkReadiness or
assessBenchmarkReadinessFromRetrieveResult (calling retrieveCompareContext when
graph is present) to populate a map of question -> readiness, persist those
readiness results, and if input.strictBenchmarkReadiness is true throw
BenchmarkReadinessError immediately for any non-'ready' readiness; then in the
per-question loop set reportShell.benchmark_readiness from the precomputed map
instead of recomputing.
🤖 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.

Inline comments:
In `@src/infrastructure/compare.ts`:
- Around line 1638-1641: The SPI detection in retrievalHasSpiEvidence is missing
top-level "spi/" paths; update the predicate (which iterates
collectBenchmarkReadinessSourceFiles(retrieval)) to also detect "spi" as a path
segment at the start or between slashes. Replace the current includes checks
with a single regex test such as /(^|\/)spi(\/|$)|\.spi\./ (or equivalent
startsWith('/spi')/startsWith('spi/') plus existing ".spi." check) so files like
"spi/runtime.ts", "/spi/foo", "lib/spi/bar" and dotted names are all detected.

---

Outside diff comments:
In `@src/infrastructure/compare.ts`:
- Around line 3515-3590: The strict benchmark-readiness check is currently
performed inside the questions loop (when building reportShell) which lets
earlier questions consume resources before a later question fails; fix by
preflighting all questions before any execution: iterate over questions and
compute readiness using assessBenchmarkReadiness or
assessBenchmarkReadinessFromRetrieveResult (calling retrieveCompareContext when
graph is present) to populate a map of question -> readiness, persist those
readiness results, and if input.strictBenchmarkReadiness is true throw
BenchmarkReadinessError immediately for any non-'ready' readiness; then in the
per-question loop set reportShell.benchmark_readiness from the precomputed map
instead of recomputing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: df2d24c1-1b76-4679-9aec-84545f798f87

📥 Commits

Reviewing files that changed from the base of the PR and between a3dab52 and 0161ae7.

📒 Files selected for processing (6)
  • src/cli/main.ts
  • src/cli/parser.ts
  • src/infrastructure/compare.ts
  • tests/unit/cli.test.ts
  • tests/unit/compare-native-agent.test.ts
  • tests/unit/compare.test.ts

Comment thread src/infrastructure/compare.ts Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@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.

Actionable comments posted: 0

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)

1620-1641: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Normalize source-file paths before SPI/scope checks.

Line 1640 and the scope derivation logic rely on /-separated paths. Windows-style \ paths (or mixed-case SPI) can be misclassified, causing false degraded/not_ready readiness and incorrect suggested_graph_scope under strict mode.

💡 Proposed fix
 function suggestBenchmarkGraphScope(graphPath: string, sourceFiles: readonly string[]): string | null {
   const scopes = new Set<string>()
   for (const sourceFile of sourceFiles) {
-    const [scope] = sourceFile.split('/', 1)
+    const normalized = sourceFile.replaceAll('\\', '/')
+    const [scope] = normalized.split('/', 1)
     if (scope && !['src', 'test', 'tests', 'docs'].includes(scope)) {
       scopes.add(scope)
     }
   }
@@
 function retrievalHasSpiEvidence(retrieval: RetrieveResult): boolean {
-  return collectBenchmarkReadinessSourceFiles(retrieval).some((sourceFile) =>
-    /(^|\/)spi(\/|$)|\.spi\./.test(sourceFile),
-  )
+  return collectBenchmarkReadinessSourceFiles(retrieval).some((sourceFile) => {
+    const normalized = sourceFile.replaceAll('\\', '/').toLowerCase()
+    return /(^|\/)spi(\/|$)|\.spi\./.test(normalized)
+  })
 }
🤖 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 1620 - 1641, Both
suggestBenchmarkGraphScope and retrievalHasSpiEvidence assume POSIX '/' paths
and case-sensitive "spi"; normalize source-file paths and graphPath by replacing
backslashes with '/' and lowercasing before checks. In
suggestBenchmarkGraphScope, compute scope from
sourceFile.replace(/\\/g,'/').toLowerCase() before split('/') and use a
normalized graphPath (replace backslashes and lowercase) when doing
graphPath.endsWith. In retrievalHasSpiEvidence (and any use of
collectBenchmarkReadinessSourceFiles), run each sourceFile through the same
replace(/\\/g,'/').toLowerCase() normalization and then test for
/(^|\/)spi(\/|$)|\.spi\./ to make SPI detection robust across Windows paths and
mixed casing.
🤖 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 1620-1641: Both suggestBenchmarkGraphScope and
retrievalHasSpiEvidence assume POSIX '/' paths and case-sensitive "spi";
normalize source-file paths and graphPath by replacing backslashes with '/' and
lowercasing before checks. In suggestBenchmarkGraphScope, compute scope from
sourceFile.replace(/\\/g,'/').toLowerCase() before split('/') and use a
normalized graphPath (replace backslashes and lowercase) when doing
graphPath.endsWith. In retrievalHasSpiEvidence (and any use of
collectBenchmarkReadinessSourceFiles), run each sourceFile through the same
replace(/\\/g,'/').toLowerCase() normalization and then test for
/(^|\/)spi(\/|$)|\.spi\./ to make SPI detection robust across Windows paths and
mixed casing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f6255c07-f8c4-47b4-97d5-f7324ff49bc3

📥 Commits

Reviewing files that changed from the base of the PR and between 0161ae7 and f5be622.

📒 Files selected for processing (3)
  • src/infrastructure/compare.ts
  • tests/unit/compare-native-agent.test.ts
  • tests/unit/compare.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/unit/compare-native-agent.test.ts
  • tests/unit/compare.test.ts

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