From 2f8fa2d52fa84d9f951b59b80045d361b796a303 Mon Sep 17 00:00:00 2001 From: Andrew Blakeslee Moore Date: Mon, 6 Jul 2026 19:43:42 -0700 Subject: [PATCH] Transcript Incremental Projection Nucleic-Session: 0FFD007B-0696-4517-9429-129C7B0FD5AC Co-authored-by: Nucleic --- NucleicRemote/NucleicRemote/Models/HostConnection.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NucleicRemote/NucleicRemote/Models/HostConnection.swift b/NucleicRemote/NucleicRemote/Models/HostConnection.swift index 8365fbd..7fa7d94 100644 --- a/NucleicRemote/NucleicRemote/Models/HostConnection.swift +++ b/NucleicRemote/NucleicRemote/Models/HostConnection.swift @@ -584,6 +584,12 @@ final class HostConnection { // Session-transfer replies (mesh P5) only reach a *source* Mac; a phone is never one. break case .transcriptChunk(let chunk): + // A slice of a *background prefetch*: accumulate it whole — it never touches the + // open transcript's cursor/dedup state, which belongs to the on-screen session. + if chunk.requestID == prefetchRequestID { + if chunk.sessionID == prefetchSessionID { prefetchEvents.append(contentsOf: chunk.events) } + break + } // One ordered slice of the full-history fetch we started on open. Match on request id so // a stale batch from a previous open (session switched underneath us) is ignored. guard chunk.requestID == transcriptFetchRequestID, chunk.sessionID == openSessionID else { break } @@ -595,10 +601,12 @@ final class HostConnection { if let maxSeq = chunk.events.map(\.seq).max() { openMaxSeq = max(openMaxSeq ?? 0, maxSeq) } if !fresh.isEmpty { callbacks.openBackfill(EventBatch(sessionID: chunk.sessionID, events: fresh)) } case .transcriptFetchComplete(let done): + if done.requestID == prefetchRequestID { finishPrefetch(delivering: true); break } // Terminal success — every batch shipped. Clear the in-flight id; the cursor/dedup state // is already advanced by the chunks above. if done.requestID == transcriptFetchRequestID { transcriptFetchRequestID = nil } case .transcriptUnavailable(let un): + if un.requestID == prefetchRequestID { finishPrefetch(delivering: false); break } // The host holds no transcript for this session (or can't serve the format). The cold tail // still shows; there's just no deeper history to add. Clear the in-flight id. if un.requestID == transcriptFetchRequestID { transcriptFetchRequestID = nil }