Skip to content

refactor(ai-vault): split the session scanner into a transcript reader and consumers - #19666

Merged
Jinwoo-H merged 8 commits into
mainfrom
session-search-pr1-reader
Sep 9, 2026
Merged

Jinwoo-H merged 8 commits into
mainfrom
session-search-pr1-reader

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1225 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1225
Prod 44 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2036 $\color{#cf222e}{\Huge{\mathbf{−}}}$​740 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1296

Summary

First of a stacked split of #18112 (agent session search). This PR only restructures the existing ai-vault scanner so a second reader of the same transcripts can be added later without touching the scanner. Nothing user-visible changes except Cursor sessions gaining a workspace and timestamps.

Reader / consumer split. The scanner's only output was the Session History summary, so any other reader of transcripts had to hook the parse itself. Now:

  • session-transcript-reader.ts owns each file read: resume from the byte cursor when the file only grew and the offset sits on a line boundary, otherwise re-read whole; drive the parser; report where the read ended.
  • session-transcript-channel.ts fans every decoded message out per read.
  • session-transcript-consumers.ts is the registry. A consumer opts in per read with beginRead(start), receives message(...) calls, and gets finish({ byteOffset, incomplete }). Consumers keep their own cursor and never query each other.
  • The session list stays a fold inside the parser (it needs cwd, branch, tokens, which the stream deliberately omits) and is the only consumer here.
  • Parsers take an optional TranscriptMessageSink parameter instead of a module-global scope.

Also in this PR

  • Cursor: read chats/<md5 of cwd>/<uuid>/meta.json for cwd, title, timestamps. Cursor transcripts carry only role and message, so these sessions had no workspace match before. Local file reads only; SSH content parses opt out.
  • OpenCode: extract LazyWorkerThreadHost (shared with the port-scan probe) and probe the schema before querying so a changed OpenCode layout degrades instead of throwing mid-read.
  • Discovery: keep the newest-N set with a bounded insert instead of sorting every file.
  • Codex parser: session_meta field readers split into their own module (the file was at the line limit).

Deliberately not in this PR (later PRs in the stack): any search index or FTS table, inode identity on resume points, a Codex state-DB metadata fallback.

Verification

  • pnpm tc, tc:node; src/main + src/shared tests (4,056 files / 41,347 tests); check:code-quality:changed and check:react-doctor:changed, 0 new findings.
  • Session list equivalence against origin/main (e80fae0): fixture scans for all 18 providers cold, 8 resumable providers appended with an unterminated last line, and one Cursor transcript with a meta.json. 26 of 27 sessions byte-identical. The Cursor session gains cwd, createdAt, updatedAt, and a cd prefix on resumeCommand; title unchanged.
  • session-transcript-consumers.test.ts: two independent consumers receive the same 12-message stream; append-mode replays only new lines; a trailing unterminated line is published once; a throwing or declining consumer does not affect the list.

Not verified: WSL and SSH equivalence (fixtures ran on macOS).

…r and consumers

The scanner's only output was the Session History summary; a second reader
of the same transcripts (a search index) had nowhere to plug in without
hooking the parse itself. Extract a reader that owns each file read, keeps
the resumable cursor and publishes every decoded message to registered
consumers. The session list stays a fold inside the parser and is the only
consumer here. Parsers take an optional message sink instead of a scope.

Also: read Cursor chats/<md5>/<uuid>/meta.json for cwd, title and
timestamps (Cursor transcripts carry only role and message); share the
lazily spawned worker-thread host between the OpenCode SQLite reader and
the port-scan probe; probe OpenCode's schema before querying; keep the
newest-N discovery set with a bounded insert instead of sort+slice.

Session list output is byte-identical to main across all 18 providers
cold and append-resumed; the one Cursor session gains cwd/timestamps
from meta.json.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Reader / consumer split — the scanner's read path is separated into session-transcript-reader (owns each file read and its cursor), session-transcript-channel (fans decoded messages to every consumer), and session-transcript-consumers (the registry); the session list stays a fold inside the parser and is the only consumer wired today.
  • Cursor meta.json enrichment — Cursor sessions now resolve chats/<md5 of cwd>/<uuid>/meta.json for cwd, title and timestamps, folded into discovery freshness via an async contentDependencyPath so a rewritten meta.json invalidates the parse cache; SSH content parses opt out.
  • Shared worker lifetime — LazyWorkerThreadHost is extracted from the OpenCode SQLite client and reused by the port-scan probe client, removing the previously-duplicated lifecycle code.
  • Bounded discovery + schema probes — SessionNewestFiles replaces sort-all-then-slice; OpenCode SQLite probes its schema (session-scanner-opencode-sqlite-schema.ts) before querying so a changed layout degrades instead of throwing mid-read.

The reader/channel/consumer seam is clean, and the tests are behavioral rather than theatrical — they assert exact message streams, resume byte offsets, replace/append modes, and the once-only trailing-unterminated-line publication.

ℹ️ OpenCode SQLite sessions don't reach the message stream

parseAgentSessionFile routes OpenCode 1.17.x candidates to parseOpenCodeSqliteSessionViaWorker with no messages sink, so a registered consumer receives beginRead → zero messages → finishRead({ session, incomplete: false }) for those sessions. A future search-index consumer would silently treat every modern OpenCode session as having no messages. The legacy JSON OpenCode path does thread messages; worth an explicit note (or an opt-out flag) so the second reader doesn't mistake this for an empty transcript.

Technical details
# OpenCode SQLite path is invisible to transcript consumers

## Affected sites
- src/main/ai-vault/session-scanner-agent-parser.ts:61 — `parseOpenCodeSqliteSessionViaWorker(...)` receives no `messages`.
- src/main/ai-vault/session-transcript-reader.ts:132 — `readWholeTranscript` calls `parseAgentSessionFile(candidate, platform, channel)`, so the channel is handed to a path that never publishes.

## Required outcome
- Confirm this is deliberate (SQLite sessions out of scope for the first reader) and record it so the later search-index consumer accounts for it, or thread a sink through the SQLite worker path.

## Open questions for the human
- Is the search index meant to cover OpenCode SQLite sessions at all? If yes, this seam will need a second hook independent of the file-transcript reader.

ℹ️ Cursor chat-meta index is re-validated once per parsed session

applyCursorChatMeta runs on every finalize, and its early-return guard (cwd && createdAt && updatedAt && title) never trips for Cursor because the transcript never populates cwd. Each finalize outside withCursorChatMetaScan therefore re-runs readCursorChatMetaIndex (one readdir plus a stat per workspace hash). On a cold scan that is O(cursor sessions × workspace hashes) extra filesystem calls during parse, on top of the single index read discovery already did inside the scan scope. This is intentional per the "applies the fallback on every finalize of a resumed parse" test, so it is not a correctness issue — just a cost worth revisiting if cursor-heavy cold scans show up in traces.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The AI Vault scanner now streams bounded session discovery and resolves Cursor metadata within the scan scope. Transcript consumers receive normalized messages through supported parsers and resumable reads. Parse cache storage, transcript reading, and per-path parse coordination are separated. OpenCode SQLite access uses shared schema checks. Port scanning and OpenCode SQLite clients share lazy worker lifecycle management. Tests cover these flows and their refusal, resume, caching, and failure cases.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 9909f

Session scanning can retain stale metadata after sibling access is refused, and OpenCode SQLite sessions cannot provide transcript messages to consumers. These correctness gaps should be addressed before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.52% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 132 functions across 42 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description provides a strong summary and verification details, but it omits required template sections, including the linked issue, Visual Proof with N/A and a reason, AI Disclosure, Review, Ag… Add all required template sections. Include a Fixes #... issue reference, state N/A with a reason under Visual Proof, complete Testing checkboxes, provide AI Disclosure details or the required exemption, address Review, Agent skill upst…
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main refactor: splitting the AI Vault session scanner into a transcript reader and consumers.
Full details: Description check

Explanation

The description provides a strong summary and verification details, but it omits required template sections, including the linked issue, Visual Proof with N/A and a reason, AI Disclosure, Review, Agent skill upstream boundary, Notes, and the checklist.

Resolution

Add all required template sections. Include a Fixes #... issue reference, state N/A with a reason under Visual Proof, complete Testing checkboxes, provide AI Disclosure details or the required exemption, address Review, Agent skill upstream boundary, Notes, and Checklist items.

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/main/ai-vault/session-scanner-agent-parser.ts (1)

61-65: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Forward transcript messages for SQLite-backed OpenCode sessions.

readWholeTranscript supplies a live TranscriptMessageChannel, but this branch does not pass it to parseOpenCodeSqliteSessionViaWorker. OpenCode 1.17.x SQLite sessions therefore return a folded session without delivering transcript messages to registered consumers.

Extend the worker request and response path to publish normalized messages through messages, or use a parser path that accepts the sink.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d31d2817-154c-4d1b-8030-6948b00655a3

📥 Commits

Reviewing files that changed from the base of the PR and between e80fae0 and dae2b49.

📒 Files selected for processing (40)
  • src/main/ai-vault/session-newest-files.test.ts
  • src/main/ai-vault/session-newest-files.ts
  • src/main/ai-vault/session-parse-cache-store.ts
  • src/main/ai-vault/session-scanner-accumulator.ts
  • src/main/ai-vault/session-scanner-agent-parser.ts
  • src/main/ai-vault/session-scanner-agent-sources.ts
  • src/main/ai-vault/session-scanner-antigravity-parser.ts
  • src/main/ai-vault/session-scanner-candidates.ts
  • src/main/ai-vault/session-scanner-cline-parser.ts
  • src/main/ai-vault/session-scanner-codex-parser.ts
  • src/main/ai-vault/session-scanner-codex-session-meta.ts
  • src/main/ai-vault/session-scanner-copilot-parser.ts
  • src/main/ai-vault/session-scanner-cursor-chat-meta.test.ts
  • src/main/ai-vault/session-scanner-cursor-chat-meta.ts
  • src/main/ai-vault/session-scanner-cursor-parser.ts
  • src/main/ai-vault/session-scanner-devin-parser.ts
  • src/main/ai-vault/session-scanner-discovery.ts
  • src/main/ai-vault/session-scanner-droid-parser.ts
  • src/main/ai-vault/session-scanner-gemini-parsers.ts
  • src/main/ai-vault/session-scanner-graph-parsers.ts
  • src/main/ai-vault/session-scanner-grok-parser.ts
  • src/main/ai-vault/session-scanner-hermes-parser.ts
  • src/main/ai-vault/session-scanner-kimi-parser.ts
  • src/main/ai-vault/session-scanner-opencode-parser.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite-schema.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite-worker-client.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite.ts
  • src/main/ai-vault/session-scanner-parse-cache.ts
  • src/main/ai-vault/session-scanner-primary-parsers.ts
  • src/main/ai-vault/session-scanner-source-discovery.ts
  • src/main/ai-vault/session-scanner-types.ts
  • src/main/ai-vault/session-scanner.ts
  • src/main/ai-vault/session-transcript-channel.ts
  • src/main/ai-vault/session-transcript-consumers.test.ts
  • src/main/ai-vault/session-transcript-consumers.ts
  • src/main/ai-vault/session-transcript-message-content.test.ts
  • src/main/ai-vault/session-transcript-message-content.ts
  • src/main/ai-vault/session-transcript-reader.ts
  • src/main/lazy-worker-thread-host.ts
  • src/main/ports/port-scan-command-client.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Overlapping parses of one transcript share the cached resume point's
message channel, so the second beginRead dropped the first read's
consumers and the first finishRead handed them the wrong outcome. Two
callers really do overlap: a forced refresh restarts a scan while the
aborted scan's parse is still in flight, and the title reader parses
outside any scan. Restore the per-path lane around the whole
lookup-read-store sequence.

OpenCode's SQLite sessions are decoded on a worker thread the channel
cannot reach, so their reads published no messages while reporting a
complete span. Finish those reads as incomplete instead, so a consumer
never records a cursor for a stream it did not receive.
@Jinwoo-H

Jinwoo-H commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

(see above)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Per-path parse serialization — parseAgentSessionFileCached now runs its whole lookup-read-store sequence inside inSessionParseFileLane (session-parse-file-lane.ts), so overlapping parses of one path (a forced refresh racing an aborted scan, plus session-title-file-reader.ts parsing outside any scan) no longer share a resume point's channel or move the cursor backwards. The chained-promise mutex is correct, including the pending.get(path) === run guard on cleanup.
  • Unpublished reads reported as incomplete — parserPublishesMessages (false only for OpenCode SQLite candidates, using the same predicate as the parse router) lets readWholeTranscript report incomplete: true for reads whose messages decode on the worker thread and never reach the sink, closing the prior informational note about SQLite sessions silently reading as empty.
  • Behavioral tests — the two new cases assert an exact single append read with no orphaned outcome, and an incomplete: true outcome for the mocked worker path; both fail with their respective fixes removed.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…g sessions

A refused WSL read of Cursor's chats tree rethrew, and the per-file catch
in discovery then recorded an issue and skipped the transcript. Before
the meta.json join Cursor had no content dependency, so a stalled distro
could not hide a Cursor session at all. Degrade to no metadata for the
scan and report the chats root once. The parse cache stays honest without
the throw: discovery stats no meta.json on a refused scan, so the entry's
recorded size omits it and the next healthy scan re-reads the transcript.

The per-scan index scope covered discovery only, so every Cursor finalize
re-read the chats root to validate the module cache. Move the scope to
scanAiVaultSessions, which spans discovery and parse.

Also drop the unused signal parameters the sink threading added to the
Devin and Hermes content parsers, by giving each file parser a private
record parser instead.
@Jinwoo-H

Jinwoo-H commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Second review round (Opus adversarial pass) addressed in b04a171:

  • A refused WSL read of Cursor's chats tree dropped every Cursor session. The meta index now degrades to "no metadata for this scan" instead of throwing: the session is still listed with null cwd/timestamps, one scan issue is recorded per chats root (not per transcript), and the cache entry omits the meta.json size so the next healthy scan re-reads it. Test: lists cursor sessions without metadata when the chats tree is refused, then heals.
  • The per-scan meta index cache only covered discovery. withCursorChatMetaScan now wraps the whole scan, so parse-phase finalizes hit the same index. Test: reads the chats root once per scan across discovery and parse (fails with 4 reads when scoped to discovery only).
  • Removed the unused _signal parameter on the Devin and Hermes parsers.
  • Added a note in the title reader that its cache key has no content dependency, which only matches the scanner for claude/codex (the request type's agent union).

Known and documented, not changed: a consumer registered after a cache hit sees nothing for that file; the later indexer PR owns its own reads for that reason.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor observation inline about cache honesty in the new refusal path.

Reviewed changes

  • Refusal degradation for the Cursor chats read — a refused WSL read of the chats tree (or of meta.json) now degrades to "no metadata" instead of taking the session down, and the refused chats root is reported once as a cursor scan issue rather than once per transcript.
  • Scan scope moved to span discovery + parse — withCursorChatMetaScan was lifted out of discoverAiVaultSessionSources up to scanAiVaultSessions, so one scan reads the chats tree once across both phases; the scan is also wrapped in an aiVault.scan trace span.
  • Devin / Hermes parser cleanup — each file parser now delegates to a private parse…Record helper and the content parsers drop the unused signal parameter the sink threading had introduced.
  • Behavioral tests — a new cursor chat meta scan failures block asserts the refusal-then-heal flow (sessions listed without metadata, one issue for the chats root, healed on the next scan) and that the chats root is read exactly once per scan.

The scope move, the once-per-scan index read, and the heal behavior are all exercised by tests that would fail with their fixes reverted. The only gap is the meta.json-read refusal branch, noted inline.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…efused

Discovery stats meta.json into the candidate's cache key, so when only
the meta.json read is refused the un-enriched session was stored under a
key that looks unchanged and reuseCachedSession never re-ran the enrich
hook. The session stayed without cwd until Cursor rewrote the file. The
enrich hook now reports 'refused', the resumable state exposes
isCacheable, and the parse cache drops the entry instead of storing it,
so the next healthy scan re-parses. The index-read branch is unaffected:
it never stats meta.json, so its key is honest already.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Cache-honest meta.json refusal — a refused meta.json read now makes the parse non-cacheable: the enrich hook returns 'refused', accumulatorFoldResumeState exposes isCacheable(), and parseCachedInLane calls invalidateSessionParseCacheEntry instead of storing an un-enriched result under an unchanged mtimeMs + sizeBytes key. This closes the prior gap where the index-read refusal was safe but the meta.json-read refusal left a metadata-less session cached until Cursor rewrote the file.
  • Scan-scoped refusal tracking — readCursorChatMeta records the refused transcript in a per-scan refusedTranscripts set, consulted by wasCursorChatMetaRefused from applyCursorChatMeta, so the refusal is reported once per chats root (not per transcript) and surfaces as 'refused' only for the branch that actually needs it.
  • Behavioral test — the new does not cache an un-enriched session when only its meta.json read is refused case mocks wslGatedReadFile (so discovery stays healthy while only the parse-time read fails) and asserts the refused scan lists the sessions without cwd and that a follow-up scan heals them. It fails if the store is forced back on.

The reader-side flag (read.cacheable) is threaded only through the resumable path, which is correct: Cursor is the sole enrichBeforeFinalize user and the sole resumable parser that can refuse, while every other accumulator-fold state keeps enrichmentRefused permanently false.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

sizeBytes folds a content dependency's size in, so it is a cache key
rather than a file length. The reader compared a transcript byte offset
against it and reported it as a whole-file read offset, which for Cline
handed consumers an offset past the end of the file it read. Carry the
dependency's own size on FileWithMtime and subtract it in the reader.

A refused sibling stat rethrew, so discovery recorded an issue and
skipped the transcript, the same drop removed for the readdir and read
paths. Degrade to no dependency, note the tree once, and mark the key
untrustworthy.

An untrustworthy key no longer costs the resume cursor: the entry is
stored under an mtime no stat can produce, so unchanged is false while
the resume point survives and the next scan resumes instead of re-reading
the whole transcript.
@Jinwoo-H

Jinwoo-H commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Third review round (second Opus adversarial pass) addressed in 9909ff3:

  • Resume guard compared the cache-key size (transcript + meta.json) against a transcript-only byte offset. Discovery now records dependencySizeBytes separately and the reader subtracts it. In practice the guard was masked (an offset past a truncated EOF fails the newline probe anyway), but the same inflated size was being published as the whole-file read offset for providers with a sibling file, which a consumer would have recorded as a cursor past the transcript's end. Test: reports the transcript size, not the cache key, as a whole-file read offset.
  • A refused meta.json read dropped the resume cursor with the cache entry. The entry is now stored under an unmatchable mtime, so the key cannot match but resume survives and the next healthy scan resumes instead of full-reading. Test asserts incremental on the healthy scan.
  • A refused meta.json stat in discovery still dropped the session. The dependency stat now returns a refusal marker; the file is added with a transcript-only stat, one issue per refused dependency, and the parse takes the same untrustworthy-key path. Test: lists a cursor session whose meta.json stat is refused instead of dropping it.

All three mutation-checked. CI green on the prior head; rerunning.

Both refusal tests asserted that a later healthy scan re-enriches, which
a plain store would also satisfy once the resume cursor was preserved.
Assert the cache entry directly: its mtime is the unmatchable sentinel
and its resume point survives. The sentinel is exported so the tests name
the contract instead of repeating -1.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/main/ai-vault/session-scanner-parse-cache.ts (1)

158-159: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not reuse a cache entry after a refused dependency stat.

A whole-file candidate can set file.contentDependencyRefused, but this branch stores its normal mtime and incomplete size key. A later scan with the same refused stat satisfies unchanged and reuses the cached session without reparsing. Dependency-derived fields can then remain stale while the stat failure persists.

Store UNMATCHABLE_MTIME_MS for whole-file entries when file.contentDependencyRefused is true. Add a regression test for a whole-file parser with a refused sibling stat.

Proposed fix
   storeSessionParseCacheEntry(file.path, {
-    mtimeMs: file.mtimeMs,
+    mtimeMs: file.contentDependencyRefused ? UNMATCHABLE_MTIME_MS : file.mtimeMs,
     sizeBytes: file.sizeBytes ?? null,

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 33e29416-40c0-4acd-a19c-e89631ebadf4

📥 Commits

Reviewing files that changed from the base of the PR and between 286241a and 9909ff3.

📒 Files selected for processing (6)
  • src/main/ai-vault/session-scanner-cursor-chat-meta.test.ts
  • src/main/ai-vault/session-scanner-discovery.ts
  • src/main/ai-vault/session-scanner-parse-cache.ts
  • src/main/ai-vault/session-scanner-types.ts
  • src/main/ai-vault/session-transcript-consumers.test.ts
  • src/main/ai-vault/session-transcript-reader.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

One cache-honesty gap remains in the new refused-dependency path, noted inline: the whole-file branch ignores contentDependencyRefused, unlike the resumable branch.

Reviewed changes

  • Transcript size separated from the cache key — FileWithMtime now carries dependencySizeBytes (and contentDependencyRefused), and transcriptSizeBytes subtracts the content dependency so a resume or whole-file byte offset is compared against the transcript's own length, closing the window where a truncation smaller than Cursor's meta.json was silently tolerated.
  • Refused dependency stat degrades instead of dropping — optionalContentDependencyStat returns 'refused' rather than throwing, the transcript is still listed with contentDependencyRefused, and one issue is recorded per root; the resumable cache path stores such entries under an UNMATCHABLE_MTIME_MS = -1 key so the resume cursor survives while the key never reads as unchanged.
  • Behavioral tests — three new Cursor cases (sub-sibling truncation re-read, poisoned-key resume preservation, refused-stat list-then-heal) plus a Cline whole-file byte-offset assertion, each failing with its fix reverted.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…nscript

Folding Cursor's meta.json stat into the transcript's mtime/size made one
key mean two things, and every round of review found another consequence:
a byte offset could not be compared against it, a refused sibling read
took the transcript down with it, and an un-enriched parse cached under
it looked current forever. Main already had the answer for a file the
transcript key cannot see: Codex titles are refreshed at reuse time over
the cached session, not folded into the key.

Discovery now records the sibling as its own observation, unknown when it
could not be read. A cache hit needs both the transcript key and the
sidecar to match. When only the sidecar moved, Cursor re-merges it over
the stored un-enriched fold result and never re-reads the transcript;
Cline, which reads its sibling as part of the parse, re-parses.

Merging over the fold result rather than the accumulator makes enrichment
pure, so a meta.json rewritten with a new cwd replaces the old one
instead of losing to it. That was unreachable while the merge used ??= on
a session it had already enriched.

Cline and the remote scanner move to the same field, so the fold is gone
from both discovery paths.
@Jinwoo-H

Jinwoo-H commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Round 4: Cursor sidecar tracked apart from the transcript (design change)

Three review rounds produced seven findings that all traced to one root: discovery folded the Cursor meta.json sidecar's mtime/size into the transcript's cache key, so one number meant both "the transcript grew" and "the sidecar changed". The fixes were scaffolding around that fold (UNMATCHABLE_MTIME_MS, dependencySizeBytes, contentDependencyRefused, isCacheable).

d918be1f07 replaces the fold. Two independent design evaluations (Opus, Codex) picked this shape over keeping the fold, a joined second candidate, or Grok's sole-candidate pattern.

Shape

  • Transcript identity is the transcript's own stat, exactly as on main. All fold scaffolding is deleted.
  • Discovery records file.sidecar: { path, mtimeMs, sizeBytes } | 'none' | 'unknown' beside the stat; the remote discovery copy does the same instead of folding.
  • The cache entry gains sidecar and an in-memory foldSession (what the transcript alone produced). Unchanged = transcript key equal AND sidecar equal AND neither unknown.
  • Sidecar-only change → re-run enrichment over foldSession without a parse and without touching the resume cursor (same reuse-time pattern as refreshCachedCodexTitle).
  • Enrichment is a pure mergeCursorChatMeta(foldSession, meta); the old accumulator ??= would have kept a stale cwd forever after meta.json was rewritten.
  • A refused sidecar stat/read leaves the transcript entry intact, records 'unknown', and the next healthy scan re-enriches. One issue per chats root.
  • Cline moves to the same field. No SCHEMA_VERSION bump: a persisted entry without sidecar reads as unknown and re-enriches once.

Verification (rerun by the lead, not the worker)

  • pnpm tc, pnpm tc:node, pnpm test src/main/ai-vault src/main/ports (91 files, 686 tests), check:code-quality:changed, check:react-doctor:changed, audit:code-quality:native (the duplicate-import failure from round 3 is fixed): all pass.
  • Mutation: changing the re-enrich to merge over entry.session instead of entry.foldSession fails re-enriches without a parse when only the sidecar is rewritten.
  • Equivalence vs origin/main e80fae0c4d on the fixture corpus: 26 of 27 sessions byte-identical; the one Cursor session gains cwd, createdAt, updatedAt and a cd prefix on its resume command, which is the intended new behavior.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Sidecar observation replaces the folded cache key — FileWithMtime drops dependencySizeBytes/contentDependencyRefused for a tri-state sidecar (stat | 'none' | 'unknown', session-sidecar-stat.ts), so sizeBytes is again the transcript's own length and a refused sibling no longer poisons the key.
  • Cursor enrichment moves out of the fold — session-scanner-sidecar-enrichment.ts merges a meta.json onto the transcript-only fold as a pure (fold, sibling) function, re-run on a sibling-only change without re-reading bytes, and rebuilds the resumeCommand when cwd changes.
  • Whole-file cache-honesty gap closed — the parse-cache entry gains foldSession (in-memory) and sidecar; a refused sibling is stored as 'unknown', which sidecarUnchanged never treats as unchanged, so the whole-file branch re-parses instead of reusing a stale entry. This resolves the prior contentDependencyRefused finding.
  • Remote cache adopts the same model — remote-session-parse-cache.ts / discovery record sidecar beside the transcript stat instead of folding mtime/size.
  • Behavioral tests — Cline whole-file sidecar re-parse, Cursor sidecar-only re-enrichment (a rewritten cwd replaces the merged one), refused-sidecar resume survival, and the sidecarUnchanged tri-state semantics, each failing with its fix reverted.

The sidecar split is a clean generalization: it makes the resume byte-offset check compare against the transcript's own length, keeps a refused sibling from taking the session down, and applies the same cache-honesty treatment to both resumable and whole-file branches that the earlier commits only gave to the resumable path.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Three places collapsed the two. sidecarUnchanged returned true for any
observed 'none' without reading the entry, so a sidecar that was deleted,
or one that was unreadable last scan, both read as cache hits. Native
discovery mapped every non-WSL stat failure to 'none', so an EACCES on
meta.json left a session enriched from a file nobody can see, with no
scan issue. Remote discovery could not tell a missing sibling from a
failed stat, because statRemoteSessionFile returns null for both.

'none' is now a claim: absent-now is a hit only when it was absent before
or the agent never had a sidecar, and only ENOENT/ENOTDIR reads as
absent. statRemoteSessionFile grows an opt-in rethrow so its caller can
distinguish the two failures it already reports.

Also rewrites three comments in the cursor chat-meta reader that still
described the deleted fold.
@Jinwoo-H

Jinwoo-H commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Round 4 review of d918be1 → c08d929

An Opus adversarial review of the design-B commit found no P0 and two real holes, both on the "sidecar is absent" side. Fixed in c08d929076.

Findings and fixes

  1. sidecarUnchanged returned a cache hit for any observed 'none' without looking at the cached entry, so present→none and unknown→none never re-enriched. Now: 'unknown' on either side is a change; observed 'none' is a hit only when the entry is 'none' or absent (an agent with no sidecar). Pinned by a 20-cell truth table test.
  2. Native discovery mapped every non-WSL stat error to 'none'. On macOS/Linux/Windows the gate is a bare fs.stat, so EACCES on meta.json silently kept stale enrichment forever with no scan issue. Now only ENOENT/ENOTDIR mean 'none'; anything else is 'unknown' plus one scan issue per root.
  3. The remote path collapsed "stat failed" and "no sidecar" into 'none'. statRemoteSessionFile gained an opt-in rethrowFailures so a remote Cline messages-file stat failure is 'unknown' and re-parses instead of serving the cached row. New remote-session-sidecar-observation.test.ts.
  4. No test covered the sidecar surviving the persistence round trip. Added for object / 'none' / 'unknown' / absent.
  5. Three comments still described the deleted fold. Rewritten.

Mutations (rerun by the lead): deleting the remote sidecarUnchanged check fails the remote re-parse test. The worker also reports the round-3 always-hit on 'none' failing 6 table cells, mapping non-WSL errors back to 'none' failing the EACCES test, and disabling parsePersistedSidecar failing three round-trip cases.

Gates: tc, tc:node, ai-vault + ports tests (92 files, 712 tests), both changed-code gates, native audit: all pass.

Scope correction: the PR body previously listed per-path parse serialization as out of scope. It is in this PR (035614614a): a forced refresh overlaps an aborted scan's in-flight parse and the title reader parses outside any scan, so two parses of one file would share a message channel. Body updated.

Earlier CI failure on d918be1: one shard failed ssh-remote-commands.test.ts, which this branch does not touch; rerun requested.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Local sidecar: missing vs unreadable — isMissingSidecarError narrows 'none' to a genuine ENOENT/ENOTDIR, so an EACCES/EIO/WSL-stall now records 'unknown' instead of reading as "no sidecar"; sidecarUnchanged additionally treats a vanished sidecar as a change rather than a cache hit.
  • Remote sidecar: missing vs unreadable — statRemoteSessionFile gains rethrowFailures, and observeRemoteSidecar maps a non-missing stat failure to 'unknown', closing the bi-state gap where a failed remote sidecar stat collapsed to 'none' and reused a stale row.
  • Behavioral tests — remote re-parse-on-failed-stat, local EACCES → 'unknown' → heal, the expanded sidecarUnchanged truth table, and a persistence round-trip covering all three observations.

The distinction is correct on both branches. On the WSL path a genuinely missing file is reconstructed by the helper process with its ENOENT code (not wrapped in WslTranscriptFsError), so 'none' remains the missing-file verdict while gate refusals stay 'unknown'. The tests fail with their fixes reverted.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 65631e4 into main Sep 9, 2026
28 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