From 177a054657dc2f95a65672d651cb6fc5c9bd1536 Mon Sep 17 00:00:00 2001 From: Daniel Sauer Date: Sun, 26 Jul 2026 13:19:18 +0200 Subject: [PATCH] Start clean when a rebuild converts to zero records REBUILD writes pi's prior history into a fresh Claude Code session and then resumes that id. When every prior message is one pi synthesises rather than one Claude Code can replay, convertAndImportMessages produces no records at all. session.save() then writes no file, and the resume fails the whole turn with "No conversation found with session ID", which reaches the user as a dead conversation rather than a recoverable error. A lone developer notice ahead of the first user turn is enough to trigger it, so an interactive session in a project that injects rules or an AGENTS.md notice hits this on its very first prompt. The extension's own verifyWrittenSession call already reports the underlying condition as "file missing after save". Fall back to a clean start when the rebuild yields no records. That also matches the actual state: nothing was written, so there is no session to resume. --- src/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/index.ts b/src/index.ts index 77e3b7f..6f88648 100644 --- a/src/index.ts +++ b/src/index.ts @@ -601,6 +601,19 @@ function syncSharedSession( ...(modelId ? { model: modelId } : {}), }); convertAndImportMessages(session, priorMessages, customToolNameToSdk); + // Nothing survived conversion. This happens when every prior message is one pi + // synthesises rather than one Claude Code can replay — a lone developer notice + // ahead of the first user turn is the common case, and an interactive session in + // a project that injects rules or an AGENTS.md notice starts exactly that way. + // save() then writes no file at all, so resuming this id fails the whole turn + // with "No conversation found with session ID". Starting clean is also the + // accurate description: there is no prior turn for Claude Code to resume. + if (session.messages.length === 0) { + debug(`rebuild produced 0 records from ${priorMessages.length} prior message(s); starting clean instead of resuming a session that was never written`); + debug(`syncResult: path=clean-start empty-rebuild`); + sharedSession = null; + return { sessionId: null }; + } session.save(); verifyWrittenSession(session.jsonlPath, session.sessionId, session.messages.length, cwd); sharedSession = { sessionId: session.sessionId, cursor: priorMessages.length, cwd };