Repository navigation
Fix SPI readiness detection - #409
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@coderabbitai review |
📝 WalkthroughWalkthroughThis PR fixes a false-negative in benchmark-readiness SPI-evidence detection by switching from source-file path pattern matching to an explicit ChangesSPI-mode graph generation and readiness detection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 1675-1685: The graphPathHasSpiMode function can throw when
readFileSync/JSON.parse encounters IO or invalid JSON, turning a readiness check
into a crash; wrap the file read and JSON.parse in a try/catch and return false
on any error, keep the existing existsSync check and the parsed null/object/type
guard, and finally return whether (parsed as { spi_mode?: unknown }).spi_mode
=== true; this ensures failures are handled closed (false) rather than throwing.
In `@src/infrastructure/generate.ts`:
- Around line 441-443: The code sets graph.graph.spi_mode when options.useSpi is
true but never clears it, causing stale true values on update paths; update the
logic around options.useSpi so that when options.useSpi is false you explicitly
clear or set graph.graph.spi_mode = false (or delete the property) to ensure
non-SPI generation paths do not retain a previous SPI flag; look for the symbols
options.useSpi and graph.graph.spi_mode in generate.ts to make this change.
🪄 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: 092ed08c-351a-4d22-a91c-fb023a5b0d69
📒 Files selected for processing (5)
src/infrastructure/compare.tssrc/infrastructure/generate.tssrc/pipeline/export.tstests/unit/compare.test.tstests/unit/generate-spi-flag.test.ts
| function graphPathHasSpiMode(graphPath: string): boolean { | ||
| if (!existsSync(graphPath)) { | ||
| return false | ||
| } | ||
|
|
||
| const parsed = JSON.parse(readFileSync(graphPath, 'utf8')) as unknown | ||
| if (parsed === null || typeof parsed !== 'object') { | ||
| return false | ||
| } | ||
|
|
||
| return (parsed as { spi_mode?: unknown }).spi_mode === true |
There was a problem hiding this comment.
Guard graph JSON parsing in SPI readiness detection.
graphPathHasSpiMode() can throw on invalid JSON or read races (Line 1680), which turns a readiness check into a hard failure. This path should fail closed (false) instead.
Proposed fix
function graphPathHasSpiMode(graphPath: string): boolean {
if (!existsSync(graphPath)) {
return false
}
-
- const parsed = JSON.parse(readFileSync(graphPath, 'utf8')) as unknown
- if (parsed === null || typeof parsed !== 'object') {
- return false
- }
-
- return (parsed as { spi_mode?: unknown }).spi_mode === true
+ try {
+ const parsed = JSON.parse(readFileSync(graphPath, 'utf8')) as unknown
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
+ return false
+ }
+ return (parsed as { spi_mode?: unknown }).spi_mode === true
+ } catch {
+ return false
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function graphPathHasSpiMode(graphPath: string): boolean { | |
| if (!existsSync(graphPath)) { | |
| return false | |
| } | |
| const parsed = JSON.parse(readFileSync(graphPath, 'utf8')) as unknown | |
| if (parsed === null || typeof parsed !== 'object') { | |
| return false | |
| } | |
| return (parsed as { spi_mode?: unknown }).spi_mode === true | |
| function graphPathHasSpiMode(graphPath: string): boolean { | |
| if (!existsSync(graphPath)) { | |
| return false | |
| } | |
| try { | |
| const parsed = JSON.parse(readFileSync(graphPath, 'utf8')) as unknown | |
| if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) { | |
| return false | |
| } | |
| return (parsed as { spi_mode?: unknown }).spi_mode === true | |
| } catch { | |
| return false | |
| } | |
| } |
🤖 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 1675 - 1685, The
graphPathHasSpiMode function can throw when readFileSync/JSON.parse encounters
IO or invalid JSON, turning a readiness check into a crash; wrap the file read
and JSON.parse in a try/catch and return false on any error, keep the existing
existsSync check and the parsed null/object/type guard, and finally return
whether (parsed as { spi_mode?: unknown }).spi_mode === true; this ensures
failures are handled closed (false) rather than throwing.
| if (options.useSpi) { | ||
| graph.graph.spi_mode = true | ||
| } |
There was a problem hiding this comment.
Clear stale spi_mode on non-SPI generation paths.
spi_mode is only ever set, never unset. On Line 441, --update runs that reuse an old SPI graph can keep spi_mode: true even when useSpi is false, causing false-positive SPI readiness later.
Proposed fix
graph.graph.root_path = resolvedRootPath
- if (options.useSpi) {
- graph.graph.spi_mode = true
- }
+ if (!options.clusterOnly) {
+ if (options.useSpi) {
+ graph.graph.spi_mode = true
+ } else {
+ delete graph.graph.spi_mode
+ }
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (options.useSpi) { | |
| graph.graph.spi_mode = true | |
| } | |
| if (options.useSpi) { | |
| graph.graph.spi_mode = true | |
| } else { | |
| delete graph.graph.spi_mode | |
| } |
🤖 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/generate.ts` around lines 441 - 443, The code sets
graph.graph.spi_mode when options.useSpi is true but never clears it, causing
stale true values on update paths; update the logic around options.useSpi so
that when options.useSpi is false you explicitly clear or set
graph.graph.spi_mode = false (or delete the property) to ensure non-SPI
generation paths do not retain a previous SPI flag; look for the symbols
options.useSpi and graph.graph.spi_mode in generate.ts to make this change.
Summary
spi_modeflag in exported SPI graphsCloses #404
Verification
Summary by CodeRabbit
Bug Fixes