fix(sync): avoid false session loading errors

New sessions fetched history before their confirmed empty state was published, and cold worktree selection ignored globally indexed session directories.

Initialize new transcripts before navigation, reject stale-runtime creation responses, and resolve cold sessions through their known directory. Preserve earlier live records and explicit recovery.

Validated 191 focused tests, UI type-check and ESLint. Reviewed dead-code and oxlint reports; existing anti-slop findings remain outside the added code. Remote and Windows runtime behavior has not been manually verified.
This commit is contained in:
Bohdan Triapitsyn
2026-09-09 22:32:04 +03:00
parent 590af5c513
commit d419fe9248
7 changed files with 231 additions and 1 deletions
@@ -176,6 +176,30 @@ export class SessionMessageLoader {
this.disposed = false
}
initializeCreatedSession(target: SessionMessageTarget): void {
const normalized = this.normalizeTarget(target)
if (!normalized || this.disposed) return
const store = this.childStores.ensureChild(normalized.directory, { bootstrap: false })
const current = store.getState()
// The create response establishes an empty transcript, but events or a
// prompt may already have materialized a newer snapshot while it travelled.
if (current.message[normalized.sessionID] !== undefined) return
const entry = this.getEntry(normalized)
this.bumpGeneration(entry)
entry.inflight = null
store.setState({ message: { ...current.message, [normalized.sessionID]: [] } })
this.patchEntry(entry, {
status: "ready",
loadingKind: null,
error: null,
resolved: true,
cursor: undefined,
complete: true,
updatedAt: Date.now(),
})
this.persistCoverage(normalized, entry.snapshot)
}
ensure(
target: SessionMessageTarget,
options?: { force?: boolean; reason?: "navigation" | "reactive" | "prefetch" },