Fetch Historical Transcript Data

Nucleic-Session: 11465D90-A8F3-43AA-A1DC-37EA1EC1B909
Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
2026-07-05 19:27:31 -07:00
co-authored by Nucleic
parent eff6127773
commit 10e4e27a1a
@@ -555,11 +555,25 @@ final class HostConnection {
case .transferAccept, .transferReject, .transferReady, .transferCommitted, .transferChunkAck: case .transferAccept, .transferReject, .transferReady, .transferCommitted, .transferChunkAck:
// Session-transfer replies (mesh P5) only reach a *source* Mac; a phone is never one. // Session-transfer replies (mesh P5) only reach a *source* Mac; a phone is never one.
break break
case .transcriptChunk, .transcriptFetchComplete, .transcriptUnavailable: case .transcriptChunk(let chunk):
// Full-transcript fetch replies (mesh sync) only arrive in response to a // One ordered slice of the full-history fetch we started on open. Match on request id so
// `fetchTranscript` this device sent. A phone pulls full history on demand via a // a stale batch from a previous open (session switched underneath us) is ignored.
// dedicated fetch path (not this subscribe stream), so nothing to do here yet. guard chunk.requestID == transcriptFetchRequestID, chunk.sessionID == openSessionID else { break }
break // De-dup against the tail/live stream and advance the warm-resubscribe cursor exactly like
// a snapshot/events batch, then hand the fresh (older) events to RemoteStore, which merges
// them into the transcript by seq rather than appending.
let fresh = chunk.events.filter { !seenSeq.contains($0.seq) }
seenSeq.formUnion(chunk.events.map(\.seq))
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):
// 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):
// 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 }
case .toolSummaries: case .toolSummaries:
// Collapsed Bash summary lines the owner pushes to peer *Macs* (mesh session sync). // Collapsed Bash summary lines the owner pushes to peer *Macs* (mesh session sync).
// The phone renders its own deterministic command summaries, so it ignores these. // The phone renders its own deterministic command summaries, so it ignores these.