fix(collab): chunked welcome so large session snapshots can join
The host used to ship the entire transcript inside a single welcome frame, so a multi-MB session spent the guest's 30s first-welcome timeout on the relay transfer itself: ~1.3 MB took ~3s, ~4.2 MB took ~12s, and ~13.6 MB never arrived before the guest gave up with 'timed out waiting for the host's welcome'. Bump COLLAB_PROTO to 2 and split the welcome: - welcome carries metadata only (header, state, agents, entryCount, readOnly) and lands in well under one second. - a train of snapshot-chunk frames (SNAPSHOT_CHUNK_BYTES = 512 KB, oversize entries ship alone) carries the transcript. Last chunk flips final: true; an empty snapshot still emits one final chunk. - the host queues welcome + chunks synchronously inside #handleHello, preserving the host comment's ordering invariant (later broadcast frames cannot interleave between them). - the TUI guest accumulates chunks under a SNAPSHOT_PROGRESS_TIMEOUT_MS that resets per chunk; only after final does it write the replica jsonl, switchSession, and render. The first-welcome timeout still guards arrival of the small welcome. - the collab-web GuestClient streams entries into the snapshot as chunks arrive and flips phase to 'live' on final. Includes a contract test (in-process relay) asserting the welcome is metadata-only, the chunk train fans the 1.5 MB synthetic transcript across multiple frames with only the last marked final, and the flattened entries match the source snapshot. Fixes #3144
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
|
||||
describe("collab wire constants", () => {
|
||||
it("exports the protocol constants consumed by host, guest, and relay links", () => {
|
||||
expect(COLLAB_PROTO).toBe(1);
|
||||
expect(COLLAB_PROTO).toBe(2);
|
||||
expect(COLLAB_PROMPT_MESSAGE_TYPE).toBe("collab-prompt");
|
||||
expect(ENVELOPE_HEADER_LENGTH).toBe(4);
|
||||
expect(ROOM_ID_BYTES).toBe(16);
|
||||
|
||||
Reference in New Issue
Block a user