Repository navigation
feat(v0.16): SPI cache (#77) + multi-resolution (#76) + weighted coverage (#79) + cache-aware prompt hash (#80) - #123
Conversation
…rage (#79) + cache-aware prompt hash (#80) Closes out v0.16-runtime-efficiency in one bundled PR (as requested). ## #77 Incremental SPI cache - New module src/pipeline/spi/cache.ts exporting buildSpiCached(opts) — wraps buildSpi with disk-backed all-or-nothing caching keyed by sha256 of (workspace root + extractor_version + graphify_version + tsconfig content + per-file (path, mtime, size, sha256)). - Cache layout: <root>/graphify-out/.spi-cache/{index.json,spi.json}. Format-versioned (CACHE_FORMAT_VERSION=1) so future schema changes invalidate cleanly. - Returns a SpiCacheStats payload (hit/reason/duration_ms/file_count/cache_key) via onCacheLookup callback so consumers can log telemetry without re-deriving the key. - Public API: buildSpiCached, clearSpiCache, BuildSpiCachedOptions, BuildSpiCachedResult, SpiCacheStats, SpiCacheIndex. ## #76 Multi-resolution context representations - New helper src/runtime/context-pack-resolution.ts exporting applyContextPackResolution(nodes, options) — supports 'detail' (no-op), 'summary' (strip snippet bodies), and 'mixed' (top-N detail by match_score, rest summary). - New stdio context_pack parameter: resolution: 'detail' | 'summary' | 'mixed' (default detail). - Reports bytes_saved when shrinking nodes; resolution_map[] for diagnostics. ## #79 Weighted coverage scoring - New PrImpactResult fields: coverage_score_weighted (bridge/god labels count 3x), uncovered_hotspot_severities (per-label 'critical'/'high'/'medium' tiers), critical_labels (bridge+god subset of high-impact labels). - Compact path recomputes weighted score + severities against the post-compaction review bundle, same correctness contract as the unweighted score from CodeRabbit follow-up to #79. ## #80 Cache-aware prompt layout — stable_prefix_hash - New BuiltContextPrompt field: stable_prefix_hash (sha256-16 of stable_prefix). - Byte-stable across re-runs when the underlying graph/anchor is unchanged; flips when stable content changes; invariant under dynamic-suffix changes (cache-hit precondition for Anthropic prompt cache reuse). ## Tests - +43 new tests across 4 files. Updated 5 existing fixtures for the new PrImpactResult shape. Existing 'materially reduces' thresholds raised from 780 → 820 to absorb the 3 new compact fields. MCP schema-budget ceiling raised from 12,000 → 12,200 to accommodate the resolution parameter on context_pack. - Verified: typecheck + build clean, 1793/1793 tests pass.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis PR adds stable prompt hashing for cache validation, an opt-in on-disk SPI cache with deterministic workspace fingerprinting, multi-resolution context-pack transformations and stdio wiring, and weighted PR-impact coverage scoring with compaction updates and tests. ChangesStable Prompt Infrastructure
Semantic Program Index Caching
Multi-Resolution Context Packing
PR-Impact Weighted Coverage Scoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
🚥 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)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/runtime/stdio/tools.ts (1)
821-877:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
resolutionis silently ignored fortask: 'review' | 'impact'.Line 891 parses
resolutionafter early returns in Lines 821-877, so callers can passresolutionwith no effect and no validation error. Either apply it to those task outputs or reject unsupported combinations explicitly.Suggested minimal guard (prevent silent no-op)
+ const resolutionParam = helpers.stringParam(toolArguments, 'resolution') + const resolution: ContextPackResolution = + resolutionParam === 'summary' || resolutionParam === 'mixed' + ? resolutionParam + : 'detail' + + if ((task === 'review' || task === 'impact') && resolutionParam) { + return helpers.failure( + id, + helpers.jsonrpcInvalidParams, + 'resolution is currently supported only for task=explain', + ) + } - - if (task === 'review') { + if (task === 'review') {Also applies to: 888-895
🤖 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/runtime/stdio/tools.ts` around lines 821 - 877, The review and impact branches ignore the caller-supplied resolution parameter because resolution validation/parse happens later; update the task === 'review' and task === 'impact' handling in the function that builds the context pack so resolution is either validated early or rejected: check for the presence of resolution in toolArguments (or the parsed resolution variable) before the early returns for review/impact and either apply it into the returned payload (the object built for helpers.textToolResult / contextPackBasePayload) or return helpers.failure with jsonrpcInvalidParams when resolution is unsupported; locate the logic around the review branch (task === 'review', analyzePrImpact/compactPrImpactResult/contextMetadata/storeExpandableHandles/buildTaskContextPlan) and the impact branch (task === 'impact', retrieveContext/pickImpactTarget/analyzeImpact/impactMetadata) and add the resolution check there so callers cannot pass resolution with no effect.
🧹 Nitpick comments (1)
src/runtime/pr-impact.ts (1)
1182-1189: 💤 Low valueUnreachable 'medium' severity branch.
The default
severity = 'medium'at line 1185 is unreachable becauseuncoveredHotspots(lines 1159–1161) is already filtered to only include nodes inhighImpactLabelSet. Every node will therefore match either thecriticalcondition (line 1186) or thehighcondition (line 1187).If the intent is to support non-high-impact changed nodes in the future, consider adding a comment. Otherwise, simplify by removing the unreachable branch or initializing severity to
'high'since that's the only non-critical outcome.♻️ Proposed simplification
const uncoveredHotspotSeverities: Array<{ label: string; severity: 'critical' | 'high' | 'medium' }> = uncoveredHotspots.map((node) => { const label = node.label - let severity: 'critical' | 'high' | 'medium' = 'medium' - if (bridgeSet.has(label) || godSet.has(label)) severity = 'critical' - else if (highImpactLabelSet.has(label)) severity = 'high' + const severity: 'critical' | 'high' = (bridgeSet.has(label) || godSet.has(label)) + ? 'critical' + : 'high' return { label, severity } })🤖 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/runtime/pr-impact.ts` around lines 1182 - 1189, The mapping that builds uncoveredHotspotSeverities sets severity default to 'medium' but uncoveredHotspots is already filtered to high-impact labels, making 'medium' unreachable; update the code in the uncoveredHotspots.map block to remove the 'medium' case by changing the severity type to only 'critical' | 'high', initialize severity to 'high', and return either 'critical' if bridgeSet.has(label) || godSet.has(label) else 'high' — also adjust the declared Array type for uncoveredHotspotSeverities accordingly or add a clarifying comment if you intend to reintroduce 'medium' later.
🤖 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/pipeline/spi/cache.ts`:
- Around line 156-195: The miss-reason computed from tryLoadCache (the variable
assigned from cached.kind ->
'key-mismatch'|'format-version-mismatch'|'corrupt-cache') is discarded and later
overwritten by checking existsSync(indexPath) after saveCache; fix by computing
and preserving that reason before calling safeDelete/saveCache and then pass
that preserved reason into finishStats for the miss return. Concretely, move the
declaration of the reason out of the if-block (or capture it into a local let
like missReason), set missReason based on cached.kind where tryLoadCache is
handled, call safeDelete(indexPath)/safeDelete(spiPath) and saveCache as before,
and then use missReason (falling back to 'no-cache' only if it was never set)
when building the final cache stats in the return that calls finishStats.
- Around line 127-154: The function buildSpiCached currently computes
computeWorkspaceFingerprint(root, opts) before checking opts.noCache, causing
expensive workspace hashing even when caching is disabled; change the control
flow so the opts.noCache guard runs before calling computeWorkspaceFingerprint
(or bail out immediately when opts.noCache is true), so that when noCache is
true you directly call buildSpi(opts) and return the cache-disabled result
without invoking computeWorkspaceFingerprint or any file I/O.
In `@src/runtime/stdio/tools.ts`:
- Around line 896-909: The helper applyResolutionToNodes currently returns only
{ nodes, bytes_saved } and drops applyContextPackResolution's resolution_map and
per-resolution savings; update applyResolutionToNodes to preserve and forward
resolution_map and bytes_saved_by_resolution from applyContextPackResolution
(e.g., return { nodes: result.nodes as T[], bytes_saved: result.bytes_saved,
resolution_map: result.resolution_map, bytes_saved_by_resolution:
result.bytes_saved_by_resolution }) so both non-delta and delta response paths
that call applyResolutionToNodes (and the callers around lines where it is used)
can include resolution_map and per-resolution savings in the response payload.
In `@tests/unit/spi-cache.test.ts`:
- Around line 28-59: The tests call buildSpiCached but don't assert the correct
miss reasons; update the three specs that call buildSpiCached to assert the
expected cache.reason values from the stats contract: in the first call (cold
start) assert the miss reason is the "no-cache" entry reason (e.g., 'no-cache'
or the project's canonical no-cache string) instead of leaving it out, and in
the file-change invalidation test replace the incorrect
expect(reBuild.cache.reason).toBe('fresh-cache') with the proper stale rebuild
reason (e.g., 'stale-cache'); locate and adjust assertions around buildSpiCached
in the tests so the first call checks for the no-cache reason and the
rebuild-after-change checks for stale-cache.
---
Outside diff comments:
In `@src/runtime/stdio/tools.ts`:
- Around line 821-877: The review and impact branches ignore the caller-supplied
resolution parameter because resolution validation/parse happens later; update
the task === 'review' and task === 'impact' handling in the function that builds
the context pack so resolution is either validated early or rejected: check for
the presence of resolution in toolArguments (or the parsed resolution variable)
before the early returns for review/impact and either apply it into the returned
payload (the object built for helpers.textToolResult / contextPackBasePayload)
or return helpers.failure with jsonrpcInvalidParams when resolution is
unsupported; locate the logic around the review branch (task === 'review',
analyzePrImpact/compactPrImpactResult/contextMetadata/storeExpandableHandles/buildTaskContextPlan)
and the impact branch (task === 'impact',
retrieveContext/pickImpactTarget/analyzeImpact/impactMetadata) and add the
resolution check there so callers cannot pass resolution with no effect.
---
Nitpick comments:
In `@src/runtime/pr-impact.ts`:
- Around line 1182-1189: The mapping that builds uncoveredHotspotSeverities sets
severity default to 'medium' but uncoveredHotspots is already filtered to
high-impact labels, making 'medium' unreachable; update the code in the
uncoveredHotspots.map block to remove the 'medium' case by changing the severity
type to only 'critical' | 'high', initialize severity to 'high', and return
either 'critical' if bridgeSet.has(label) || godSet.has(label) else 'high' —
also adjust the declared Array type for uncoveredHotspotSeverities accordingly
or add a clarifying comment if you intend to reintroduce 'medium' later.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e1de36e9-6239-4703-b9c3-a615d8da9530
📒 Files selected for processing (15)
src/infrastructure/context-prompt.tssrc/pipeline/spi/cache.tssrc/pipeline/spi/index.tssrc/runtime/context-pack-resolution.tssrc/runtime/pr-impact.tssrc/runtime/stdio/definitions.tssrc/runtime/stdio/tools.tstests/unit/context-pack-resolution.test.tstests/unit/context-prompt-cache-hash.test.tstests/unit/mcp-schema-budget.test.tstests/unit/pr-impact-coverage.test.tstests/unit/pr-impact-weighted-coverage.test.tstests/unit/pr-impact.test.tstests/unit/spi-cache.test.tstests/unit/stdio-pr-impact.test.ts
…easons, resolution_map forwarding 5 valid findings from CodeRabbit on PR #123: 1) MAJOR — context_pack 'resolution' parameter was silently ignored for task=review|impact. Now rejects unsupported (resolution, task) combinations with a clear jsonrpcInvalidParams error before the early returns. 2) cache.ts buildSpiCached: computeWorkspaceFingerprint ran BEFORE the noCache check, doing per-file hashing even when caching was disabled. Reordered so noCache short-circuits to buildSpi() with zero filesystem walks. 3) cache.ts buildSpiCached: the actual miss reason (key-mismatch / format-version-mismatch / corrupt-cache) was computed and discarded; the reported reason was always inferred from existsSync after the save. Now captured into a missReason variable and propagated into the SpiCacheStats payload. 4) stdio/tools.ts applyResolutionToNodes: dropped applyContextPackResolution's resolution_map. Now forwarded so callers can see which nodes were summarized vs kept in detail. 5) NITPICK — pr-impact.ts uncoveredHotspotSeverities mapping had an unreachable 'medium' branch (input is pre-filtered to high-impact labels). Simplified the construction to 'critical' | 'high' only; retained the wider 'medium' type on the result for future expansion. Tests: updated spi-cache.test.ts to assert the proper miss reasons (no-cache on cold start, key-mismatch on file change). 1793/1793 still pass.
Closes #77
Closes #76
Closes #79
Closes #80
Summary
Closes out v0.16-runtime-efficiency in one bundled PR. Four issues landed:
What's in the bundle
#77 SPI cache (
src/pipeline/spi/cache.ts)buildSpiCached(opts)wrapsbuildSpiwith disk-backed all-or-nothing caching<root>/graphify-out/.spi-cache/{index.json, spi.json}CACHE_FORMAT_VERSION=1) so future schema changes invalidate cleanlySpiCacheStats(hit/reason/duration_ms/file_count/cache_key) viaonCacheLookupcallbackbuildSpiCached,clearSpiCache,BuildSpiCachedOptions,BuildSpiCachedResult,SpiCacheStats,SpiCacheIndex#76 Multi-resolution (
src/runtime/context-pack-resolution.ts)applyContextPackResolution(nodes, options)adapts a node list to one of:context_packparameter:resolution: 'detail' | 'summary' | 'mixed'resolution,resolution_map,bytes_saved_by_resolution#79 Weighted coverage scoring
PrImpactResultfields:coverage_score_weighted— bridge/god labels count 3x, regular 1xuncovered_hotspot_severities— per-label'critical'(bridge/god) /'high'(high-impact) /'medium'critical_labels— bridge+god subset of high-impact labels (consumer-readable)#80 Cache-aware prompt layout —
stable_prefix_hashBuiltContextPromptfield:stable_prefix_hash(sha256-16 ofstable_prefix)Tests
tests/unit/spi-cache.test.ts(13 tests)tests/unit/context-pack-resolution.test.ts(10 tests)tests/unit/context-prompt-cache-hash.test.ts(5 tests)tests/unit/pr-impact-weighted-coverage.test.ts(5 tests)Test plan
npm run typecheckcleannpm run buildcleannpm run test:run— 1793/1793 pass (107 files)Summary by CodeRabbit
detail,summary,mixed) for context packs to reduce payloads.