Skip to content

CC-390: cache parsed snapshot segments across refresh cycles - #464

Merged
swu-wise[bot] merged 6 commits into
mainfrom
wise/cc390-reader-parse-cache
Nov 10, 2026
Merged

swu-wise[bot] merged 6 commits into
mainfrom
wise/cc390-reader-parse-cache

Conversation

@jaywedgeworth22

@jaywedgeworth22 jaywedgeworth22 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Addresses the remaining tracked #390 matrix finding f6: the one-minute refresh re-read and re-parsed every snapshot in the 90-minute window each cycle.
#390 stays closed; this completes its tracked remainder. Independent of #462 (different files).

Summary

Implements CC-390: caches parsed snapshot segments across refresh cycles so unchanged snapshots are reused. The cache is process-wide and shared across readers for the one-minute refresh path.

Changes

  • Adds MuseCodeSnapshotSegmentCache keyed by path, mtime and size with hit/miss counters, reset support and 8,192-entry capacity with clear-on-full behavior.
  • Routes MuseCodeSessionReader.segment(...) through the shared cache, with existing read/parse logic preserved in parseSegment(...).

Tests

  • Added testReaderServesUnchangedSnapshotsFromParseCache covering cache reuse on second read with no additional parses.
  • Added testReaderReparsesASnapshotRewrittenInPlace covering re-parse after rewrite with new mtime/content.
  • Test execution results were not provided in the changes, so passing status is unverified.

Risks / Open review findings

  • Automated review reports 2 medium findings in Sources/QuotaCore/MuseCodeSessionReader.swift, both unverified as resolved: weak cache key may return stale tokens on same-size rewrite (line 185), and cache clears all entries on overflow causing thrash (line 197).

Summary

Addresses CC-390 by retaining parsed snapshot segments in MuseCodeSnapshotSegmentCache across refresh cycles. Changes cache overflow handling to evict a single entry when over capacity instead of clearing all entries, so an over-cap working set degrades to partial misses rather than causing full re-parses on the next scan.

Tests Added

Adds testParseCacheOverflowEvictsOneEntryInsteadOfClearingAll, which fills the cache to capacity, inserts one overflow entry, then verifies the remaining entries stay cached without re-parsing. Run results and runtime verification are unverified in the provided changes.


Summary

Caches parsed Muse Code snapshot segments across refresh cycles for CC-390. The snapshot segment cache key now includes path, file resource identity, modification time, and size, so unchanged snapshots avoid a second read and parse across the one-minute refresh cycles. The change also guards against stale hits when a snapshot path is reused after rotation by replacement.

Changes

  • Updated MuseCodeSnapshotSegmentCache.segment(sessionId:url:modified:size:parse:) to include fileResourceIdentifier in the cache key alongside path, mtime, and size. Updated comments to document write-once UUID names with rotation by replacement.

Impact

Reduces repeated file reads and parsing during refreshes when snapshots are unchanged, while preserving correctness for replaced files. No additional user-facing behavior change beyond efficiency and staleness protection is inferred from this diff.

Testing

No test additions or test execution evidence are present in the provided diff, so behavior remains unverified.

Risks / Open Review Findings

  • [Medium] Unstable String(describing:) file identifier may break snapshot cache hits at Sources/QuotaCore/MuseCodeSessionReader.swift:193.
  • [Low] Extra identifier stat may double syscalls in the snapshot cache hot loop at the same location.

Summary

Related to CC-390. Avoids re-parsing snapshot segments across refresh cycles by caching by content identity, while still re-parsing when the underlying file is replaced.

Changes

  • Builds cache key from path, systemFileNumber + creation date, modification date, and size using FileManager.attributesOfItem instead of cached URL resource values. This distinguishes a replacement file with identical path/size/mtime and avoids returning stale segments with one stat per lookup.

Tests

  • Added testParseCacheReparseesReplacedFileWithIdenticalMetadata for same-path replacement with identical size and mtime. Pass/fail, execution, and runtime verification remain unverified in this summary.

@kody-ai

This comment has been minimized.

@kody-ai

kody-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Automatic approval held

Kody's assessment:

Kody could not verify the current PR head and labels.

@kody-ai

This comment has been minimized.

@kody-ai

This comment has been minimized.

@kody-ai

kody-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

​

Automatic approval held: Kody could not verify the current PR head and labels.

@swu-wise
swu-wise Bot merged commit 86564cb into main Nov 10, 2026
11 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.

1 participant