@@ -8,12 +8,20 @@ Branch: codex/runturn-backlog-coalesce (from origin/dev). One PR.
88
99In createAdapterEventQueue push(): when no reader is waiting and the queue
1010tail exists:
11- - tail.type === "text_delta" && event.type === "text_delta" && same phase ->
12- replace tail with { type:"text_delta", text: tail.text + event.text,
13- phase: tail.phase } (do NOT mutate the original object; queued events may
14- be shared).
11+ - tail.type === "text_delta" && event.type === "text_delta" && identical
12+ phase field (both undefined, or === — an omitted phase is a continuation
13+ downstream (bridge.ts:922-925) but merge only on strict equality to stay
14+ provably safe) -> REPLACE tail with a new object
15+ { type:"text_delta", text: tail.text + event.text, phase: tail.phase }.
16+ Never mutate pushed objects: push() has no ownership/copy contract
17+ (run-turn-queue.ts:7-11) and adapters may retain/re-emit event objects —
18+ interface-level alias safety, so replacement only (A-gate blocker 6).
19+ - Byte bound (A-gate blocker 5): merge only while tail.text.length <= 64KB;
20+ past that, append as a new item so a single merged item cannot grow
21+ unbounded and re-copy on every push. The backlog cap then bounds total
22+ memory at ~ 64KB * 1024.
1523- tail.type === "thinking_delta" && event.type === "thinking_delta" ->
16- merge thinking strings likewise.
24+ merge thinking strings likewise (same replacement + byte-bound rules) .
1725- event.type === "heartbeat" && tail.type === "heartbeat" -> drop event
1826 (one pending heartbeat is enough).
1927- All other types append as today. Never merge across a non-delta boundary;
@@ -31,15 +39,27 @@ turn aborted" and the pushed error gains status/retryable hints untouched
3139
3240### 3. Tests — MODIFY tests/run-turn-queue.test.ts
3341
34- - NEW: 5000 alternating-text deltas with no reader -> backlog stays 1 merged
35- text item (+ terminal), no overflow, collect() returns concatenated text.
42+ - NEW: 5000 ADJACENT text_delta chunks (same phase) with no reader ->
43+ backlog stays 1 merged item, no overflow, collect() returns exact
44+ concatenation (activation for the text-merge branch).
45+ - NEW: 5000 adjacent thinking_delta chunks -> 1 merged item, exact
46+ concatenation (activation for the thinking-merge branch, A-gate blocker 3).
47+ - NEW: byte-bound activation — chunks totalling >64KB split into 2+ items,
48+ concatenation preserved across items.
3649- NEW: heartbeat collapse — 50 heartbeats no reader -> 1 queued heartbeat.
3750- NEW: interleaved text/tool/text does not merge across the tool event.
38- - NEW: phase-boundary text deltas (phase change) do not merge.
51+ - NEW: phase transitions do not merge: "final"->"commentary", and
52+ explicit-phase -> omitted-phase (undefined) stays separate (blocker 4).
53+ - NEW: empty-string deltas merge without corrupting concatenation.
3954- KEEP: overflow still fires for 1024+ DISTINCT non-coalescible events
40- (e.g. tool_call_start floods) and message updated.
55+ (tool_call_start floods) and the message assertion updated.
4156
42- ### 4. MODIFY tests/abort-race.test.ts — message string sync.
57+ ### 4. MODIFY tests/abort-race.test.ts — the overflow flood at :56 uses
58+ 1025 text_delta events which coalescing would now merge; switch the flood
59+ to non-coalescible events (tool_call_start with distinct ids) so the
60+ abort-race contract still activates overflow (A-gate blocker 1), and sync
61+ the message string (only three live refs exist: run-turn-queue.ts:76 + the
62+ two test assertions; no runtime parser — blocker 7 verified).
4363
4464## Accept criteria + activation
4565
0 commit comments