Skip to content

fix(ai-vault): refresh the Codex title on a remote parse-cache hit - #17938

Closed
nwparker wants to merge 0 commit into
fix/relay-cpu-and-stale-pty-lifecyclefrom
fix/remote-parse-cache-codex-title
Closed

nwparker wants to merge 0 commit into
fix/relay-cpu-and-stale-pty-lifecyclefrom
fix/remote-parse-cache-codex-title

Conversation

@nwparker

@nwparker nwparker commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​76 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​56

Stacked on #17832, which it corrects. Retarget to main once that merges.

An adversarial review found a regression in #17832's vault half (#13753's parse cache).

The bug: derived content from a file the cache key does not measure

Codex session titles are not in the rollout transcript — they are in ~/.codex/session_index.jsonl, read by a callback that runs inside source.parse. The cache keys on the transcript's (mtimeMs, sizeBytes, hostKey) and justified that as sound "because discovery already folds a source's contentDependencyPath stat into both fields".

The codex sources declare no contentDependencyPath, so that argument never covered them. On a cache hit parse() never runs, the index is never read, and the title freezes at whatever the first parse produced. Codex writes the title asynchronously, after the rollout is created — so a session that gets named after its last transcript append keeps its fallback title indefinitely.

The local scanner already solved this. refreshCachedCodexTitle exists as its own module solely to defeat this staleness, called on the local cache's reuse path. The remote cache calls itself "its remote counterpart" in a comment and shipped without it. This is divergence between two things meant to be the same.

The fix: share the module, do not pair a copy

session-scanner-codex-cached-title.ts now exports the staleness rule as an IO-free core, with the local disk reader kept as a wrapper:

export async function refreshCodexTitleFromIndex(
  session: AiVaultSession,
  readIndexedTitle: (sessionId: string) => Promise<string | null>
): Promise<AiVaultSession>

Injecting the reader is what lets both sides share one implementation — a direct import of the remote reader would have dragged ../ssh/ssh-remote-platform into the local scanner worker's bundle, so the callback is the seam. The local call site is byte-identical to before.

remote-session-scanner-sources.ts now builds its parser's readIndexedTitle from the same exported remoteCodexIndexedTitleReader the refresh uses (the inline closure is deleted), so parse and refresh provably read the same map. The refreshed title is written back into the cache entry, matching the local behaviour.

The #13753 win is preserved: context.titleCaches is scan-scoped, so this is one session_index.jsonl read per CODEX_HOME per scan, shared with the parse path. No transcript is re-read — the new test asserts provider.readFilePaths is empty.

The test gap mattered as much as the bug

The suite could not have caught this by construction: CountingRemoteProvider filters to /sessions/, and session_index.jsonl sits outside it, so it was invisible to every assertion — while every fixture is a Codex rollout, i.e. the suite is built on the one agent whose title path the cache breaks and then filters that path out of what it measures.

The new test asserts both halves — new title and zero transcript reads — so a "fix" that merely invalidated the cache entry would fail it.

BEFORE (refreshReusedSession: undefined)
  × picks up a session_index title written after the transcript was cached
  AssertionError: expected 'First prompt' to be 'Named by Codex after the fact'
  Tests  1 failed | 5 passed (6)
AFTER
  Tests  6 passed (6)

The /sessions/ filter is left alone — it is the right instrument for the corpus term, and the new zero-read assertion depends on the index staying outside it. The filter was never the bug; the missing assertion was.

Subagent-count verdict: the review was right, remote is correct

remote-session-scanner.ts:249-252 re-applies subagentTranscriptCount on every return, hit or miss, from a value discovery recomputes each scan. Airtight for two reasons: the spread builds a new object and never writes back into entry.session, so the cached row stays count-free; and the > 0 guard cannot strand a stale non-zero count because the remote parse always produces 0 (countSubagentTranscripts is gated behind ownsTranscriptDisk, false for SSH). A 3 → 0 transition correctly falls through.

Other local/remote divergences, checked and left

  • No invalidateSessionParseCacheEntry on the remote cache. Benign for the reason the local comment gives — discovery walks first, so a deleted file is never rediscovered — but a deleted remote transcript occupies an LRU slot until evicted.
  • No incremental byte-offset resume remotely: the relay readFile has no ranged read. Intentional.
  • No cross-restart persistence remotely: process-lifetime only, scoped to the sidecar's 10-minute idle retirement. Intentional.
  • Codex was the only uncovered case. Antigravity's workspace resolver reads history files but through a scan-scoped resolver on every parse and declares contentDependencyPath; cline and opencode likewise declare theirs.

Verification

pnpm test src/main/ai-vault/ — 77 files, 494 tests passed. pnpm tc:node clean. check:code-quality:changed 0 new findings.

A first draft pushed session-scanner-parse-cache.ts one line over the max-lines ceiling. Rather than bump or disable it (prohibited), the factoring was changed so the local call site keeps its original shape and the remote path takes the new core — the better structure anyway.

Refs #13753

@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

A fix for a regression in #17832's remote parse-cache half: Codex titles live in session_index.jsonl, which the remote cache's (mtimeMs, sizeBytes, hostKey) key does not measure, so a cache hit froze the fallback title forever.

  • Shared staleness rule — session-scanner-codex-cached-title.ts extracts an IO-free refreshCodexTitleFromIndex(session, readIndexedTitle) core; the local refreshCachedCodexTitle becomes a byte-identical wrapper.
  • Remote reader factory — remoteCodexIndexedTitleReader(codexHome, context) reuses the scan-scoped titleCaches path, so parse and reuse provably read the same index map.
  • Reuse-path refresh — parseRemoteSessionFileCached gains an optional refreshReusedSession hook, applied only on cache hit and written back into the entry; reusedCodexTitleRefresh wires it for Codex candidates only.
  • Regression test — proves a title written after the transcript was cached is picked up on the next scan while the transcript itself is not re-read.

The test is real coverage, not theatre: without the fix it fails with expected 'First prompt' to be 'Named by Codex after the fact', and it fails today on src/main/ai-vault/remote-session-parse-cache.test.ts if refreshReusedSession is omitted. Verified the hostPlatform source in the new reader is identical to the old closure's (context.hostPlatform === args.hostPlatform), that no new heavy dependency is dragged into the remote bundle, and that the cached entry stays free of subagentTranscriptCount (it is re-applied post-cache).

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

@nwparker
nwparker force-pushed the fix/relay-cpu-and-stale-pty-lifecycle branch from ccd3b8d to 030916e Compare September 2, 2026 20:51
@nwparker

nwparker commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #17832 and closing here.

This fix is not an enhancement on top of that PR — it repairs a user-visible regression #17832 introduces. Before the remote parse cache, the scanner re-parsed every transcript on the renderer's 30 s forced rescan, so a Codex title written into session_index.jsonl after the rollout did eventually surface. Codex sources set no contentDependencyPath, so the cache's (mtime, size) key cannot see an index-only change and the fallback title would freeze for the sidecar's life.

Landing it as a stacked PR would put a commit on main that ships the regression and a later one that removes it. It also cannot apply to main on its own: the parse cache it hooks into does not exist there.

So the whole change — the refreshReusedSession hook, remoteCodexIndexedTitleReader, and extracting refreshCodexTitleFromIndex out of the local-disk-only refreshCachedCodexTitle — is now a commit inside #17832, with its test (picks up a session_index title written after the transcript was cached) alongside the cache's own tests. Same move used for #18013/#18029 and #17939 in this sweep.

Nothing is lost; review it at #17832.

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