From 02fd9e88c39503f77aefb50c97bc2ed4e59a53cc Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:06:50 -0800 Subject: [PATCH] Await metadata publication before choosing a transcript reread Verify title-only updates through actual transcript I/O and searchable results. Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com> --- .../session-search-dependency-work.test.ts | 15 ++++++++------- .../session-search-index-consumer.ts | 9 ++++----- .../ai-vault-search/session-search-index-pass.ts | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/ai-vault-search/session-search-dependency-work.test.ts b/src/main/ai-vault-search/session-search-dependency-work.test.ts index 03055ffd5ec..664aeb9c18c 100644 --- a/src/main/ai-vault-search/session-search-dependency-work.test.ts +++ b/src/main/ai-vault-search/session-search-dependency-work.test.ts @@ -7,7 +7,6 @@ import { appendFile, mkdir, writeFile } from 'node:fs/promises' import { dirname, join } from 'node:path' import { expect, it, vi } from 'vitest' import * as filesystem from '../native-chat/wsl-transcript-fs-access' -import * as parser from '../ai-vault/parse-cache/session-scanner-parse-cache' import { codexFixture, CODEX_FIXTURE_SESSION_ID @@ -39,12 +38,14 @@ it.each([40, 400])( }) const streams = vi.spyOn(filesystem, 'openTranscriptReadStream') const slices = vi.spyOn(filesystem, 'readTranscriptSlice') - const reads = vi.spyOn(parser, 'parseAgentSessionFileCached') + const transcripts = new Set() try { await mkdir(root, { recursive: true }) for (const id of ids) { + const path = join(root, fixture.fileName.replace(CODEX_FIXTURE_SESSION_ID, id)) + transcripts.add(path) await writeFile( - join(root, fixture.fileName.replace(CODEX_FIXTURE_SESSION_ID, id)), + path, `${fixture.seedLines.join('\n').replaceAll(CODEX_FIXTURE_SESSION_ID, id)}\n` ) } @@ -52,13 +53,13 @@ it.each([40, 400])( await subject.start() streams.mockClear() slices.mockClear() - reads.mockClear() // Lost delivery must re-observe the input, not reread it or force every transcript. notifySessionSearchOverflow(dirname(root)) clock.advance(20000) await subject.settled() expect(streams.mock.calls.filter(([path]) => path === index)).toHaveLength(0) - expect(reads).not.toHaveBeenCalled() + expect(streams.mock.calls.filter(([path]) => transcripts.has(path))).toHaveLength(0) + expect(slices.mock.calls.filter(([path]) => transcripts.has(path))).toHaveLength(0) const append = `${JSON.stringify({ id: ids[0], thread_name: 'Changed title' })}\n` const size = Buffer.byteLength(records.join('') + append) await appendFile(index, append) @@ -81,7 +82,8 @@ it.each([40, 400])( expect(indexBytes).toBeLessThanOrEqual( 2 * (Buffer.byteLength(append) + Buffer.byteLength(records[0]) + 1) ) - expect(reads).toHaveBeenCalledTimes(1) + expect(streams.mock.calls.filter(([path]) => transcripts.has(path))).toHaveLength(0) + expect(slices.mock.calls.filter(([path]) => transcripts.has(path))).toHaveLength(0) expect( harness.read((db) => db.prepare("SELECT count(*) AS n FROM sessions WHERE title='Changed title'").get() @@ -95,7 +97,6 @@ it.each([40, 400])( } finally { streams.mockRestore() slices.mockRestore() - reads.mockRestore() await subject.close() await harness.cleanup() } diff --git a/src/main/ai-vault-search/session-search-index-consumer.ts b/src/main/ai-vault-search/session-search-index-consumer.ts index 917fb78a491..87dff990b28 100644 --- a/src/main/ai-vault-search/session-search-index-consumer.ts +++ b/src/main/ai-vault-search/session-search-index-consumer.ts @@ -59,7 +59,7 @@ export class SessionSearchIndexConsumer implements TranscriptConsumer { return this.store.resumableCursor(candidate)?.byteOffset ?? null } - beginRead(start: TranscriptReadStart): TranscriptReadConsumer | null { + beginRead(start: TranscriptReadStart): SessionSearchReadConsumer | null { const { candidate } = start if (this.store.acceptingReads === false) { return null @@ -182,7 +182,7 @@ class SessionSearchReadConsumer implements TranscriptReadConsumer { } } - finish(outcome: TranscriptReadOutcome): void { + finish(outcome: TranscriptReadOutcome): void | Promise { if ( outcome.cancelled || this.publication?.valid() === false || @@ -226,10 +226,9 @@ class SessionSearchReadConsumer implements TranscriptReadConsumer { this.publication?.release() } if (this.write.settled) { - void this.write.settled().then(acknowledge, () => acknowledge(false)) - } else { - acknowledge(true) + return this.write.settled().then(acknowledge, () => acknowledge(false)) } + acknowledge(true) return } // Stamp and count repeated read failures so unchanged unreadable files can be held out. diff --git a/src/main/ai-vault-search/session-search-index-pass.ts b/src/main/ai-vault-search/session-search-index-pass.ts index 793b6c06210..d5c6465daa5 100644 --- a/src/main/ai-vault-search/session-search-index-pass.ts +++ b/src/main/ai-vault-search/session-search-index-pass.ts @@ -84,7 +84,7 @@ export async function runSessionSearchIndexPass( signal: options.signal }) if (consumer) { - consumer.finish({ + await consumer.finish({ session, byteOffset: row.byteOffset, prefixHash: row.prefixHash,