From ae2641c233e8d180ced82564e2db5005d224bd2b Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 1 Oct 2026 21:11:36 -0700 Subject: [PATCH 01/20] fix(agent): keep op sender stamps and displaced admissions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The human write leg lost work in two ways when an admission raced a workflow change or an unbound window. A single mint cursor was shared by every workflow, so an admission that was never addressed to a document — one taken while unbound, or on a detached sender — reset it. The next bound admission then re-minted a counter the previous one had already used, and two ops with the same creator-owned Lamport stamp fall through to the op_id tiebreak, so which of the two human edits survives is arbitrary. The cursor is now kept per workflow and advanced only once an admission has a target. An admission whose open group was closed by a reentrant serialization callback was settled `undeliverable` even though the sender was live, unaborted and still bound: a human edit the user had already made was silently dropped. It is now sealed into the queue at the position it was admitted at, keeping its original op ids, and delivery is held for the whole admission so the ops a reentrant callback enqueues cannot reach the wire ahead of the earlier-minted ops still being placed. Two merged assertions contradicted the production intent they shipped with and were red on main: the recovery-probe count (#19860 deliberately stopped probing once an abort invalidates the seal, and #19866 depends on that early return for abort telemetry attribution) and the workflow-change pump case, which asserted an unbound batch would be sent and encoded the dropped admission above. Both now pin the delivered behaviour, with the abort attribution and the full drain asserted. --- .../extensions/agent/crdt/opSender.test.ts | 128 ++++++++++++-- .../extensions/agent/crdt/opSender.ts | 165 +++++++++++++----- 2 files changed, 238 insertions(+), 55 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index 8dde6087e2b..66e1cfe96cb 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -194,6 +194,54 @@ describe('createOpSender', () => { expect(sent[1].ops[0].base_version).toBe(41) }) + it('an admission taken while unbound leaves the bound workflow its own counter', () => { + sender.admit([addNode(1)]) + boundWorkflow = null + + sender.admit([addNode(2)]) + + boundWorkflow = WORKFLOW + sender.admit([addNode(3)]) + sender.flush() + + // The unbound admission is settled, not addressed to any doc, so it must + // not move or reset this doc's cursor: node 3 mints past node 1 instead of + // reusing its counter and colliding on the stamp. + expect( + sender.pendingOps().flatMap(({ ops }) => ops.map((op) => op.base_version)) + ).toEqual([41, 42]) + expect(settled.map(summarizeSettlement)).toEqual([ + { state: 'undeliverable', nodeIds: [2] } + ]) + }) + + it('keeps one Lamport counter per workflow across a switch away and back', () => { + sender.admit([addNode(1)]) + boundWorkflow = 'wf-2' + sender.admit([addNode(2)]) + boundWorkflow = WORKFLOW + sender.admit([addNode(3)]) + sender.flush() + + const minted = sender.pendingOps().map(({ workflowId, ops }) => ({ + workflowId, + versions: ops.map((op) => op.base_version) + })) + expect(minted).toEqual([ + { workflowId: WORKFLOW, versions: [41] }, + { workflowId: 'wf-2', versions: [41] }, + { workflowId: WORKFLOW, versions: [42] } + ]) + const perWorkflow = new Map() + for (const { workflowId, versions } of minted) + perWorkflow.set(workflowId, [ + ...(perWorkflow.get(workflowId) ?? []), + ...versions + ]) + for (const versions of perWorkflow.values()) + expect(new Set(versions).size).toBe(versions.length) + }) + it('serializes batches: the next sends only after the result settles the first', () => { sender.enqueue([addNode(1)]) sender.enqueue([addNode(2)]) @@ -1367,10 +1415,25 @@ describe('createOpSender', () => { localSender.admit([first, second]) localSender.flush() - expect(firstSerializations).toBe(2) + // The abort invalidated the seal before recovery began, so the valid prefix + // is never probed and never rechunked: one serialization, not three. + expect(firstSerializations).toBe(1) expect(localSettled).toHaveLength(1) expect(localSettled[0].state).toBe('undeliverable') expect(localSettled[0].ops).toHaveLength(2) + // The abort, not the serialization failure, is why the seal was dropped. + expect(reportError).toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ + errorType: 'failure_chunking_agent_op_sender_abort' + }) + ) + expect(reportError).not.toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ + errorType: 'failure_chunking_agent_op_sender' + }) + ) expect(localSender.pending()).toBe(0) localSender.detach() }) @@ -1423,19 +1486,24 @@ describe('createOpSender', () => { }) it('resumes a pump requested during workflow-change sealing', () => { - const localSent: Op[][] = [] + const localSent: Array<{ workflowId: string; ops: Op[] }> = [] + const localSettled: BatchOutcome[] = [] + let localResultListener!: (result: OpsResultView) => void let workflow = 'wf-old' const localSender = createOpSender({ - sendOps: (_workflowId, _tab, ops) => { - localSent.push(ops) + sendOps: (workflowId, _tab, ops) => { + localSent.push({ workflowId, ops }) return true }, - onOpsResult: () => vi.fn(), + onOpsResult: (listener) => { + localResultListener = listener + return vi.fn() + }, workflowId: () => workflow, tab: TAB, actor: () => ACTOR, baseVersion: () => 41, - onBatchSettled: vi.fn() + onBatchSettled: (outcome) => localSettled.push(outcome) }) const outer = addNode(1) let reentered = false @@ -1454,10 +1522,50 @@ describe('createOpSender', () => { localSender.admit([addNode(2)]) - expect(localSent).toHaveLength(1) - expect('node_id' in localSent[0][0] ? localSent[0][0].node_id : null).toBe( - 1 - ) + // The deferred pump runs once the admission is placed, not mid-seal: node 2 + // was minted before the node 3 its serialization enqueued, so it goes first. + expect( + localSent.map(({ workflowId, ops }) => ({ + workflowId, + nodeIds: ops.map((op) => ('node_id' in op ? op.node_id : undefined)) + })) + ).toEqual([{ workflowId: 'wf-new', nodeIds: [2] }]) + // Nothing is dropped: the admission displaced by the nested enqueue keeps + // its place in mint order ahead of it, and node 1's unbound batch waits its + // turn instead of being re-addressed. + expect( + localSender.pendingOps().map(({ workflowId, ops }) => ({ + workflowId, + nodeIds: ops.map((op) => ('node_id' in op ? op.node_id : undefined)), + versions: ops.map((op) => op.base_version) + })) + ).toEqual([ + { workflowId: 'wf-new', nodeIds: [2], versions: [41] }, + { workflowId: 'wf-old', nodeIds: [1], versions: [41] }, + { workflowId: 'wf-new', nodeIds: [3], versions: [42] } + ]) + const deliveredIds = localSent[0].ops.map((op) => op.op_id) + + localResultListener({ ok: true, applied: deliveredIds, skipped: [] }) + + expect( + localSent.map(({ workflowId, ops }) => ({ + workflowId, + nodeIds: ops.map((op) => ('node_id' in op ? op.node_id : undefined)), + opIds: ops.map((op) => op.op_id) + })) + ).toEqual([ + { workflowId: 'wf-new', nodeIds: [2], opIds: deliveredIds }, + { + workflowId: 'wf-new', + nodeIds: [3], + opIds: [expect.stringMatching(/^[0-9a-f]{32}$/)] + } + ]) + expect(localSettled.map(summarizeSettlement)).toEqual([ + { state: 'acknowledged', nodeIds: [2] }, + { state: 'undeliverable', nodeIds: [1] } + ]) localSender.detach() }) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index c945edbf166..33f2bb41717 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -81,6 +81,13 @@ export interface OpSender { * Mint and target-pin operations into the open admission group without * starting transport delivery. Consecutive admissions for one workflow * share the group until `flush()` seals it. + * + * An admission for another workflow seals the open group first, and custom + * serialization can re-enter the sender from inside that seal. If the nested + * call closes the open group, these ops are sealed into the queue at the + * position they were admitted at — ahead of what the nested call enqueued, + * with their original `op_id`s — rather than dropped. Delivery the nested + * call requested is held until then, so mint order reaches the wire intact. */ admit(operations: GraphOperation[]): void /** Seal the open admission group into wire batches and start delivery. */ @@ -148,12 +155,21 @@ export function createOpSender(deps: OpSenderDeps): OpSender { let queueHead = 0 let open: { workflowId: string; ops: Op[] } | null = null let inFlight: InFlight | null = null - let lastMintedVersion = -1 - let lastMintedWorkflowId: string | null = null + // Creator-owned Lamport counters, one per workflow: the stamp must be + // monotonic per (actor, doc), so a mint that is never addressed to a doc — an + // admission taken while unbound, or on a detached sender — must not move or + // reset the cursor of a doc that is still live. A single shared slot let an + // unbound admission between two bound ones hand the second one a counter the + // first had already used, and two ops with the same stamp fall through to the + // op_id tiebreak, so which of the two human edits survives is arbitrary. + const lastMintedVersions = new Map() let detached = false let suspended = false let pumping = false - let sealing = 0 + // Delivery deferral depth: a seal or an admission in progress parks the pump + // until it unwinds, so work a reentrant serialization callback enqueues + // cannot reach the wire ahead of the earlier-minted ops still being placed. + let pumpDeferrals = 0 let pumpRequested = false let stateEpoch = 0 let abortGeneration = 0 @@ -178,6 +194,42 @@ export function createOpSender(deps: OpSenderDeps): OpSender { { reports: number; startedAt: number } >() const MAX_CHUNK_FAILURE_REPORTS = 3 + // Bounded so a long session switching between many docs cannot grow the + // cursor map without limit. Evicting the least recently minted workflow only + // falls back to the follower's observed sequence for that doc. + const MAX_TRACKED_MINT_CURSORS = 64 + + /** + * The counter the next op for `workflowId` mints at: at least the follower's + * last observed sequence, and always past this actor's last mint for that + * same doc. An unbound admission has no doc to be monotonic against. + */ + function mintBaseVersion(workflowId: string | null): number { + const observed = deps.baseVersion() + if (workflowId === null) return observed + const lastMinted = lastMintedVersions.get(workflowId) + return lastMinted === undefined + ? observed + : Math.max(observed, lastMinted + 1) + } + + function rememberMintedVersion(workflowId: string, version: number): void { + // Re-insert so iteration order is least-recently-minted first. + lastMintedVersions.delete(workflowId) + lastMintedVersions.set(workflowId, version) + if (lastMintedVersions.size > MAX_TRACKED_MINT_CURSORS) { + const oldest = lastMintedVersions.keys().next() + if (!oldest.done) lastMintedVersions.delete(oldest.value) + } + } + + function releasePumpDeferral(): void { + pumpDeferrals-- + if (pumpDeferrals === 0 && pumpRequested) { + pumpRequested = false + pump() + } + } function retire(batch: InFlight, answered: number): void { const outstanding = batch.sends - answered @@ -374,7 +426,7 @@ export function createOpSender(deps: OpSenderDeps): OpSender { } function pump(): void { - if (sealing > 0) { + if (pumpDeferrals > 0) { pumpRequested = true return } @@ -423,7 +475,8 @@ export function createOpSender(deps: OpSenderDeps): OpSender { minted: Op[], admissionTarget: string, admissionEpoch: number, - admissionAbortGeneration: number + admissionAbortGeneration: number, + admissionInsertionIndex: number ): boolean { if (stateEpoch === admissionEpoch) return false if (detached) { @@ -442,46 +495,59 @@ export function createOpSender(deps: OpSenderDeps): OpSender { stateEpoch++ return true } - guardedSettlementNotifier('failure_settling_agent_op_sender')({ - state: 'undeliverable', - ops: minted - }) + // The nested call closed the open group (or retargeted it at another doc), + // so there is nothing left to merge into — but this sender is live, is not + // aborted, and these ops are still addressed to a doc. Dropping them here + // discarded a human edit the user had already made. Seal them at the queue + // position they held when they were admitted instead: ahead of whatever the + // nested call enqueued, carrying their original op ids. + sealGroup( + { workflowId: admissionTarget, ops: minted }, + admissionInsertionIndex + ) + stateEpoch++ return true } function admit(operations: GraphOperation[]): void { if (operations.length === 0) return const workflowId = deps.workflowId() - if (workflowId !== lastMintedWorkflowId) { - lastMintedVersion = -1 - lastMintedWorkflowId = workflowId - } - const baseVersion = Math.max(deps.baseVersion(), lastMintedVersion + 1) + const baseVersion = mintBaseVersion(workflowId) const actor = deps.actor() const minted = operations.flatMap((operation, index) => mintWireOps([operation], { actor, baseVersion: baseVersion + index }) ) - lastMintedVersion = baseVersion + minted.length - 1 const admissionTarget = admissionTargetOrSettle(minted, workflowId) if (admissionTarget === null) return - const admissionEpoch = stateEpoch - const admissionAbortGeneration = abortGeneration - // seal() can synchronously re-enter the sender through its settlement - // callback. Do not resurrect an aborted admission or append old-workflow - // ops to state installed by a nested admit(). - if (open?.workflowId !== admissionTarget) seal() - if ( - restoreReentrantAdmission( - minted, - admissionTarget, - admissionEpoch, - admissionAbortGeneration + rememberMintedVersion(admissionTarget, baseVersion + minted.length - 1) + // Hold delivery for the whole admission: seal() below can re-enter through + // custom serialization and request a pump, and draining it before these ops + // are placed would put later-minted work on the wire first. + pumpDeferrals++ + try { + const admissionEpoch = stateEpoch + const admissionAbortGeneration = abortGeneration + const admissionInsertionIndex = queue.length + // seal() can synchronously re-enter the sender through its settlement + // callback. Do not resurrect an aborted admission or append old-workflow + // ops to state installed by a nested admit(). + if (open?.workflowId !== admissionTarget) seal() + if ( + restoreReentrantAdmission( + minted, + admissionTarget, + admissionEpoch, + admissionAbortGeneration, + admissionInsertionIndex + ) ) - ) - return - if (open) for (const op of minted) open.ops.push(op) - else open = { workflowId: admissionTarget, ops: minted } - stateEpoch++ + return + if (open) for (const op of minted) open.ops.push(op) + else open = { workflowId: admissionTarget, ops: minted } + stateEpoch++ + } finally { + releasePumpDeferral() + } } function sealInterruption( @@ -597,13 +663,17 @@ export function createOpSender(deps: OpSenderDeps): OpSender { return ops.length } - function seal(): boolean { - if (!open) return detached - const { workflowId, ops } = open + /** + * Chunk one admission group into wire batches at `insertionIndex`, the queue + * position the group held when it was admitted. Delivery stays parked until + * the seal unwinds, so a reentrant serialization callback cannot overtake it. + */ + function sealGroup( + { workflowId, ops }: { workflowId: string; ops: Op[] }, + insertionIndex: number + ): void { const sealAbortGeneration = abortGeneration - const insertionIndex = queue.length - open = null - sealing++ + pumpDeferrals++ try { const chunks = chunkWireOps(ops) const interrupted = sealInterruption(sealAbortGeneration) @@ -612,12 +682,16 @@ export function createOpSender(deps: OpSenderDeps): OpSender { } catch (cause) { recoverSeal(cause, workflowId, ops, sealAbortGeneration, insertionIndex) } finally { - sealing-- - if (sealing === 0 && pumpRequested) { - pumpRequested = false - pump() - } + releasePumpDeferral() } + } + + function seal(): boolean { + if (!open) return detached + const group = open + const insertionIndex = queue.length + open = null + sealGroup(group, insertionIndex) return detached } @@ -707,8 +781,9 @@ export function createOpSender(deps: OpSenderDeps): OpSender { abortAll() { stateEpoch++ abortGeneration++ - lastMintedVersion = -1 - lastMintedWorkflowId = null + // A doc_reset breaks lineage: every cursor is against a document that no + // longer exists, so the next mint restarts from the new doc's sequence. + lastMintedVersions.clear() drainOutstanding( guardedSettlementNotifier('failure_settling_agent_op_sender_abort'), 'failure_chunking_agent_op_sender_abort' From a6d25afc9b7b23a1f1929233c2031f8a048006e9 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 1 Oct 2026 21:41:41 -0700 Subject: [PATCH 02/20] fix(agent): retain every workflow mint cursor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review finding on #19871: the 64-entry LRU on the per-workflow Lamport cursor reintroduces the defect the cursor was added to remove, only rarer. No eviction policy is safe here, and the reason is sharper than the memory bound it bought. `reconcile()` clears `lastSeq`/`ackSeq` when it sends a `subscribe`, so `LayoutFollowerBridge.lastSequence` — the sender's `baseVersion()` dep — reads 0 from the moment the subscribe leaves until `doc_subscribed` acks it, while `subscribedWorkflowId` already names the new doc. A human edit landing in that window mints against 0, and this doc's own cursor is the only thing carrying it past this actor's last stamp for that doc. So dropping a cursor does not "fall back to the follower's observed sequence" as the removed comment claimed: it hands a re-bound workflow a counter it has already used, and two ops with the same creator-owned stamp fall through to the `op_id` tiebreak — arbitrary which human edit survives (KEEP-ALIVE #2). A retained cursor can only raise a stamp through `Math.max`, never lower one, so retention is the safe direction and the eviction is removed rather than retuned. The cost is one number per edited workflow per page session. Mutation-backed: restoring the eviction with a bound of 1 turns both cursor pins red. The new pin drives `baseVersion()` to 0 across a switch away and back, which is the window above; the existing per-workflow pin covers the constant-sequence case. Also drops the `perWorkflow` loops from the switch-away-and-back pin per docs/guidance/testing-principles.md — the `toEqual` on the whole minted collection already asserts the distinct counters they recomputed. --- .../extensions/agent/crdt/opSender.test.ts | 37 ++++++++++++++----- .../extensions/agent/crdt/opSender.ts | 22 ++++++----- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index 66e1cfe96cb..56394938ca6 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -118,6 +118,7 @@ describe('createOpSender', () => { let transportUp: boolean let transportThrows: boolean let boundWorkflow: string | null + let observedSequence: number let sender: ReturnType const unsubscribe = vi.fn(() => { resultListener = null @@ -140,6 +141,7 @@ describe('createOpSender', () => { transportUp = true transportThrows = false boundWorkflow = WORKFLOW + observedSequence = 41 sender = createOpSender({ sendOps: (workflowId, tab, ops) => { if (transportThrows) throw new Error('frame serialization failed') @@ -154,7 +156,7 @@ describe('createOpSender', () => { workflowId: () => boundWorkflow, tab: TAB, actor: () => ACTOR, - baseVersion: () => 41, + baseVersion: () => observedSequence, onBatchSettled: (outcome) => settled.push(outcome) }) }) @@ -232,14 +234,31 @@ describe('createOpSender', () => { { workflowId: 'wf-2', versions: [41] }, { workflowId: WORKFLOW, versions: [42] } ]) - const perWorkflow = new Map() - for (const { workflowId, versions } of minted) - perWorkflow.set(workflowId, [ - ...(perWorkflow.get(workflowId) ?? []), - ...versions - ]) - for (const versions of perWorkflow.values()) - expect(new Set(versions).size).toBe(versions.length) + }) + + it('keeps a workflow its counter while a re-subscribe has not been acknowledged', () => { + sender.admit([addNode(1)]) + sender.admit([addNode(2)]) + // Switching docs re-subscribes, and a subscribe resets the follower's + // observed sequence until `doc_subscribed` acks it. A human edit landing in + // that window has nothing but this doc's own cursor to mint past. + boundWorkflow = 'wf-2' + observedSequence = 0 + sender.admit([addNode(3)]) + boundWorkflow = WORKFLOW + sender.admit([addNode(4)]) + sender.flush() + + expect( + sender.pendingOps().map(({ workflowId, ops }) => ({ + workflowId, + versions: ops.map((op) => op.base_version) + })) + ).toEqual([ + { workflowId: WORKFLOW, versions: [41, 42] }, + { workflowId: 'wf-2', versions: [0] }, + { workflowId: WORKFLOW, versions: [43] } + ]) }) it('serializes batches: the next sends only after the result settles the first', () => { diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index 33f2bb41717..e6b55ab2403 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -194,10 +194,6 @@ export function createOpSender(deps: OpSenderDeps): OpSender { { reports: number; startedAt: number } >() const MAX_CHUNK_FAILURE_REPORTS = 3 - // Bounded so a long session switching between many docs cannot grow the - // cursor map without limit. Evicting the least recently minted workflow only - // falls back to the follower's observed sequence for that doc. - const MAX_TRACKED_MINT_CURSORS = 64 /** * The counter the next op for `workflowId` mints at: at least the follower's @@ -213,14 +209,20 @@ export function createOpSender(deps: OpSenderDeps): OpSender { : Math.max(observed, lastMinted + 1) } + /** + * Kept for every workflow this actor has minted against, for this sender's + * whole life: no eviction policy is safe here. A `subscribe` resets the + * follower's observed sequence to 0 until `doc_subscribed` acks it, so an + * edit made in that window mints against 0 and the cursor is the ONLY thing + * keeping it past this actor's last stamp for that doc. Dropping a cursor + * therefore does not "fall back to the observed sequence" — it hands a + * re-bound workflow a counter it has already used, which is the stamp + * collision this cursor exists to prevent. A retained cursor can only ever + * raise a stamp (`Math.max`), never lower one, so retention is the safe + * direction; the cost is one number per edited workflow per page session. + */ function rememberMintedVersion(workflowId: string, version: number): void { - // Re-insert so iteration order is least-recently-minted first. - lastMintedVersions.delete(workflowId) lastMintedVersions.set(workflowId, version) - if (lastMintedVersions.size > MAX_TRACKED_MINT_CURSORS) { - const oldest = lastMintedVersions.keys().next() - if (!oldest.done) lastMintedVersions.delete(oldest.value) - } } function releasePumpDeferral(): void { From ec6e0b1d5047c772bffbe865e44be9dc2c4c5fe9 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 1 Oct 2026 21:56:07 -0700 Subject: [PATCH 03/20] fix(agent): reset only the document whose lineage broke MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cursor-review finding, 4 of 8 reviewers: `abortAll()` cleared EVERY workflow's mint cursor, but a `doc_reset` replaces only one document. `useAgentCrdtFollower.onDocReset` dispatches it under `if (!isCurrentWorkflow(detail?.workflowId)) return`, so the comment's premise — "every cursor is against a document that no longer exists" — was false for every other doc visited this session, whose lineage was untouched. The consequence is the defect this map was added to remove. A reset in workflow B discarded workflow A's high-water mark; returning to A and editing before A's observed sequence catches up — which includes the whole window between a `subscribe` and its `doc_subscribed` ack, where `lastSequence` reads 0 — re-mints a `base_version` this actor already used for A. Two ops then share `(actor, base_version)` and the `op_id` tiebreak arbitrarily picks which human edit survives (KEEP-ALIVE #2). Now only `deps.workflowId()`'s entry is cleared, which is the reset doc by the caller's own guard. An unbound sender has no broken lineage and clears nothing. Mutation-backed: restoring `lastMintedVersions.clear()` turns the new pin `a document reset restarts only the reset document, not every workflow visited` red. It asserts both halves — the reset doc restarts at the new document's sequence, the untouched doc mints past its own last stamp. Also corrects the `admit` contract doc, which claimed mint order reaches the wire globally intact (cursor-review, 3 of 8 reviewers). It is intact per document, which is the order the stamp contract is defined over; the group an admission seals is by construction another workflow's, and it queues behind these later-minted ops because the insertion index is taken before the seal. Two documents' ops have no causal relation, so only cross-document transport order is affected, and the comment now says so rather than overclaiming. --- .../extensions/agent/crdt/opSender.test.ts | 30 +++++++++++++++++++ .../extensions/agent/crdt/opSender.ts | 21 ++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index 56394938ca6..ddcae204370 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -196,6 +196,36 @@ describe('createOpSender', () => { expect(sent[1].ops[0].base_version).toBe(41) }) + it('a document reset restarts only the reset document, not every workflow visited', () => { + sender.admit([addNode(1)]) + sender.admit([addNode(2)]) + sender.flush() + // The reset lands on wf-2, which is what the follower is bound to: it is + // dispatched under an isCurrentWorkflow guard, so no other doc's lineage + // broke and no other doc's high-water mark may be discarded. + boundWorkflow = 'wf-2' + sender.admit([addNode(3)]) + sender.abortAll() + sender.admit([addNode(4)]) + // Back on wf-1 before its re-subscribe is acknowledged. + boundWorkflow = WORKFLOW + observedSequence = 0 + sender.admit([addNode(5)]) + + // wf-2's lineage broke, so it restarts at the new document's sequence. + // wf-1's did not, so node 5 mints past node 2 rather than at the + // not-yet-acknowledged 0. + expect( + sender.pendingOps().map(({ workflowId, ops }) => ({ + workflowId, + versions: ops.map((op) => op.base_version) + })) + ).toEqual([ + { workflowId: 'wf-2', versions: [41] }, + { workflowId: WORKFLOW, versions: [43] } + ]) + }) + it('an admission taken while unbound leaves the bound workflow its own counter', () => { sender.admit([addNode(1)]) boundWorkflow = null diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index e6b55ab2403..dfff78bd437 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -87,7 +87,13 @@ export interface OpSender { * call closes the open group, these ops are sealed into the queue at the * position they were admitted at — ahead of what the nested call enqueued, * with their original `op_id`s — rather than dropped. Delivery the nested - * call requested is held until then, so mint order reaches the wire intact. + * call requested is held until then, so mint order reaches the wire intact + * PER DOCUMENT, which is the order the stamp contract is defined over. It is + * not globally intact: the group this admission sealed is by construction + * another workflow's (an admission for the SAME workflow never seals), and + * that group queues behind these later-minted ops because the insertion index + * is taken before the seal. Two documents' ops have no causal relation, so + * only the cross-document transport order is affected. */ admit(operations: GraphOperation[]): void /** Seal the open admission group into wire batches and start delivery. */ @@ -783,9 +789,16 @@ export function createOpSender(deps: OpSenderDeps): OpSender { abortAll() { stateEpoch++ abortGeneration++ - // A doc_reset breaks lineage: every cursor is against a document that no - // longer exists, so the next mint restarts from the new doc's sequence. - lastMintedVersions.clear() + // A doc_reset breaks the lineage of the BOUND document only — the + // follower dispatches this under an `isCurrentWorkflow` guard — so only + // that cursor is against a document that no longer exists and only it + // restarts from the new doc's sequence. Clearing the whole map would + // discard the high-water mark of every other doc visited this session, + // and returning to one of those before its observed sequence catches up + // would then re-mint a counter this actor already used there, which is + // the stamp collision this map exists to prevent. + const resetWorkflowId = deps.workflowId() + if (resetWorkflowId !== null) lastMintedVersions.delete(resetWorkflowId) drainOutstanding( guardedSettlementNotifier('failure_settling_agent_op_sender_abort'), 'failure_chunking_agent_op_sender_abort' From df1de6c0820294cf06d184c6d65c346b00e946b6 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:03:01 +0000 Subject: [PATCH 04/20] docs: shorten admission contract Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239079 --- src/workbench/extensions/agent/crdt/opSender.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index dfff78bd437..f43e52ffa9b 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -82,18 +82,11 @@ export interface OpSender { * starting transport delivery. Consecutive admissions for one workflow * share the group until `flush()` seals it. * - * An admission for another workflow seals the open group first, and custom - * serialization can re-enter the sender from inside that seal. If the nested - * call closes the open group, these ops are sealed into the queue at the - * position they were admitted at — ahead of what the nested call enqueued, - * with their original `op_id`s — rather than dropped. Delivery the nested - * call requested is held until then, so mint order reaches the wire intact - * PER DOCUMENT, which is the order the stamp contract is defined over. It is - * not globally intact: the group this admission sealed is by construction - * another workflow's (an admission for the SAME workflow never seals), and - * that group queues behind these later-minted ops because the insertion index - * is taken before the seal. Two documents' ops have no causal relation, so - * only the cross-document transport order is affected. + * + * If custom serialization re-enters and closes the open group, these ops are + * sealed at the queue position they were admitted at, keeping their + * `op_id`s, and delivery waits until they are placed. Mint order is + * preserved per document, not across documents. */ admit(operations: GraphOperation[]): void /** Seal the open admission group into wire batches and start delivery. */ From d7c4173b558cd0d75b79fc06cce2ba202ac6e4cf Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:03:18 +0000 Subject: [PATCH 05/20] docs: clarify workflow cursor retention Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239084 --- src/workbench/extensions/agent/crdt/opSender.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index f43e52ffa9b..7ac3e467209 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -154,13 +154,9 @@ export function createOpSender(deps: OpSenderDeps): OpSender { let queueHead = 0 let open: { workflowId: string; ops: Op[] } | null = null let inFlight: InFlight | null = null - // Creator-owned Lamport counters, one per workflow: the stamp must be - // monotonic per (actor, doc), so a mint that is never addressed to a doc — an - // admission taken while unbound, or on a detached sender — must not move or - // reset the cursor of a doc that is still live. A single shared slot let an - // unbound admission between two bound ones hand the second one a counter the - // first had already used, and two ops with the same stamp fall through to the - // op_id tiebreak, so which of the two human edits survives is arbitrary. + // One Lamport cursor per workflow, cleared only by that doc's reset: the + // observed sequence reads 0 between a subscribe and its ack, so only the + // cursor keeps a re-bound workflow's stamps past ones this actor used there. const lastMintedVersions = new Map() let detached = false let suspended = false From 4038bdd78af28172b2720b1f79f826f28adfd251 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:03:34 +0000 Subject: [PATCH 06/20] docs: remove redundant mint version comment Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239091 --- src/workbench/extensions/agent/crdt/opSender.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index 7ac3e467209..67ef294e003 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -190,11 +190,6 @@ export function createOpSender(deps: OpSenderDeps): OpSender { >() const MAX_CHUNK_FAILURE_REPORTS = 3 - /** - * The counter the next op for `workflowId` mints at: at least the follower's - * last observed sequence, and always past this actor's last mint for that - * same doc. An unbound admission has no doc to be monotonic against. - */ function mintBaseVersion(workflowId: string | null): number { const observed = deps.baseVersion() if (workflowId === null) return observed From 151fedfa2c1a8baf7eaa4900ead5013be7fdcd03 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:03:49 +0000 Subject: [PATCH 07/20] refactor: write minted version directly Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239103 --- src/workbench/extensions/agent/crdt/opSender.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index 67ef294e003..9a1a5c9dec2 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -511,7 +511,7 @@ export function createOpSender(deps: OpSenderDeps): OpSender { ) const admissionTarget = admissionTargetOrSettle(minted, workflowId) if (admissionTarget === null) return - rememberMintedVersion(admissionTarget, baseVersion + minted.length - 1) + lastMintedVersions.set(admissionTarget, baseVersion + minted.length - 1) // Hold delivery for the whole admission: seal() below can re-enter through // custom serialization and request a pump, and draining it before these ops // are placed would put later-minted work on the wire first. From 26964d742881ae692255705973114e0992e2cf36 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:04:09 +0000 Subject: [PATCH 08/20] refactor: remove minted version alias Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239095 --- src/workbench/extensions/agent/crdt/opSender.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index 9a1a5c9dec2..a5ae0736ef0 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -199,22 +199,6 @@ export function createOpSender(deps: OpSenderDeps): OpSender { : Math.max(observed, lastMinted + 1) } - /** - * Kept for every workflow this actor has minted against, for this sender's - * whole life: no eviction policy is safe here. A `subscribe` resets the - * follower's observed sequence to 0 until `doc_subscribed` acks it, so an - * edit made in that window mints against 0 and the cursor is the ONLY thing - * keeping it past this actor's last stamp for that doc. Dropping a cursor - * therefore does not "fall back to the observed sequence" — it hands a - * re-bound workflow a counter it has already used, which is the stamp - * collision this cursor exists to prevent. A retained cursor can only ever - * raise a stamp (`Math.max`), never lower one, so retention is the safe - * direction; the cost is one number per edited workflow per page session. - */ - function rememberMintedVersion(workflowId: string, version: number): void { - lastMintedVersions.set(workflowId, version) - } - function releasePumpDeferral(): void { pumpDeferrals-- if (pumpDeferrals === 0 && pumpRequested) { From b6d2009236140b5f33820cd63d315a1fe0a023d6 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:04:28 +0000 Subject: [PATCH 09/20] docs: shorten displaced admission comment Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239098 --- src/workbench/extensions/agent/crdt/opSender.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index a5ae0736ef0..d99522f35a1 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -471,12 +471,8 @@ export function createOpSender(deps: OpSenderDeps): OpSender { stateEpoch++ return true } - // The nested call closed the open group (or retargeted it at another doc), - // so there is nothing left to merge into — but this sender is live, is not - // aborted, and these ops are still addressed to a doc. Dropping them here - // discarded a human edit the user had already made. Seal them at the queue - // position they held when they were admitted instead: ahead of whatever the - // nested call enqueued, carrying their original op ids. + // The nested call closed or retargeted the open group: seal these ops at + // their admitted position, ahead of what the nested call enqueued. sealGroup( { workflowId: admissionTarget, ops: minted }, admissionInsertionIndex From 88a211f8c701fd280328ec8b693daf2c57022178 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:04:47 +0000 Subject: [PATCH 10/20] docs: remove duplicate pump deferral comment Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239109 --- src/workbench/extensions/agent/crdt/opSender.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index d99522f35a1..f3ec9107233 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -492,9 +492,6 @@ export function createOpSender(deps: OpSenderDeps): OpSender { const admissionTarget = admissionTargetOrSettle(minted, workflowId) if (admissionTarget === null) return lastMintedVersions.set(admissionTarget, baseVersion + minted.length - 1) - // Hold delivery for the whole admission: seal() below can re-enter through - // custom serialization and request a pump, and draining it before these ops - // are placed would put later-minted work on the wire first. pumpDeferrals++ try { const admissionEpoch = stateEpoch From 2c37e41c14229e27f99409f49e84ca7c9f346d65 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:05:04 +0000 Subject: [PATCH 11/20] docs: trim seal group comment Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239113 --- src/workbench/extensions/agent/crdt/opSender.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index f3ec9107233..fb6f8c88456 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -634,8 +634,7 @@ export function createOpSender(deps: OpSenderDeps): OpSender { /** * Chunk one admission group into wire batches at `insertionIndex`, the queue - * position the group held when it was admitted. Delivery stays parked until - * the seal unwinds, so a reentrant serialization callback cannot overtake it. + * position the group held when it was admitted. */ function sealGroup( { workflowId, ops }: { workflowId: string; ops: Op[] }, From 99752880dcb8f140cda550de7c3d34a4a8b280fc Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:05:35 +0000 Subject: [PATCH 12/20] refactor: name admission group shape Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239121 --- src/workbench/extensions/agent/crdt/opSender.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index fb6f8c88456..3e2c50c4aba 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -75,6 +75,11 @@ export type BatchOutcome = | { state: 'unconfirmed'; ops: Op[] } | { state: 'undeliverable'; ops: Op[] } +interface AdmissionGroup { + workflowId: string + ops: Op[] +} + export interface OpSender { enqueue(operations: GraphOperation[]): void /** @@ -94,7 +99,7 @@ export interface OpSender { /** Unsettled batch count for observability; 0 = drained. */ pending(): number /** Every unsettled batch, in-flight first, each addressed to its mint-time workflow. */ - pendingOps(): ReadonlyArray<{ workflowId: string; ops: Op[] }> + pendingOps(): ReadonlyArray /** * The bound workflow's tab went inactive: the subscription is paused, not * lost. Until `resume()`, a batch reaching `transmit()` is parked instead @@ -150,9 +155,9 @@ interface InFlight { } export function createOpSender(deps: OpSenderDeps): OpSender { - const queue: Array<{ workflowId: string; ops: Op[] }> = [] + const queue: AdmissionGroup[] = [] let queueHead = 0 - let open: { workflowId: string; ops: Op[] } | null = null + let open: AdmissionGroup | null = null let inFlight: InFlight | null = null // One Lamport cursor per workflow, cleared only by that doc's reset: the // observed sequence reads 0 between a subscribe and its ack, so only the @@ -390,7 +395,7 @@ export function createOpSender(deps: OpSenderDeps): OpSender { } } - function dequeue(): { workflowId: string; ops: Op[] } | undefined { + function dequeue(): AdmissionGroup | undefined { if (queueHead >= queue.length) return const queued = queue[queueHead] queueHead++ @@ -637,7 +642,7 @@ export function createOpSender(deps: OpSenderDeps): OpSender { * position the group held when it was admitted. */ function sealGroup( - { workflowId, ops }: { workflowId: string; ops: Op[] }, + { workflowId, ops }: AdmissionGroup, insertionIndex: number ): void { const sealAbortGeneration = abortGeneration From 467176df3e8e99daa567732b542af018f5301aee Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:05:56 +0000 Subject: [PATCH 13/20] docs: shorten reset cursor comment Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239125 --- src/workbench/extensions/agent/crdt/opSender.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index 3e2c50c4aba..7b38be3576d 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -754,14 +754,8 @@ export function createOpSender(deps: OpSenderDeps): OpSender { abortAll() { stateEpoch++ abortGeneration++ - // A doc_reset breaks the lineage of the BOUND document only — the - // follower dispatches this under an `isCurrentWorkflow` guard — so only - // that cursor is against a document that no longer exists and only it - // restarts from the new doc's sequence. Clearing the whole map would - // discard the high-water mark of every other doc visited this session, - // and returning to one of those before its observed sequence catches up - // would then re-mint a counter this actor already used there, which is - // the stamp collision this map exists to prevent. + // A doc_reset replaces only the bound document (the follower guards on + // isCurrentWorkflow), so only its cursor restarts. const resetWorkflowId = deps.workflowId() if (resetWorkflowId !== null) lastMintedVersions.delete(resetWorkflowId) drainOutstanding( From d2d25a7c3b62965dc6de97db9c728ec31dc896cd Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:06:10 +0000 Subject: [PATCH 14/20] test: trim reset isolation narration Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239131 --- src/workbench/extensions/agent/crdt/opSender.test.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index ddcae204370..b95c6dd335a 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -200,9 +200,6 @@ describe('createOpSender', () => { sender.admit([addNode(1)]) sender.admit([addNode(2)]) sender.flush() - // The reset lands on wf-2, which is what the follower is bound to: it is - // dispatched under an isCurrentWorkflow guard, so no other doc's lineage - // broke and no other doc's high-water mark may be discarded. boundWorkflow = 'wf-2' sender.admit([addNode(3)]) sender.abortAll() @@ -212,9 +209,6 @@ describe('createOpSender', () => { observedSequence = 0 sender.admit([addNode(5)]) - // wf-2's lineage broke, so it restarts at the new document's sequence. - // wf-1's did not, so node 5 mints past node 2 rather than at the - // not-yet-acknowledged 0. expect( sender.pendingOps().map(({ workflowId, ops }) => ({ workflowId, From 0e1067cae79f862fedb97a42a31e9e81b4f346cc Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:06:19 +0000 Subject: [PATCH 15/20] test: remove redundant unbound cursor comment Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239134 --- src/workbench/extensions/agent/crdt/opSender.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index b95c6dd335a..d8a70d9f5e1 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -230,9 +230,6 @@ describe('createOpSender', () => { sender.admit([addNode(3)]) sender.flush() - // The unbound admission is settled, not addressed to any doc, so it must - // not move or reset this doc's cursor: node 3 mints past node 1 instead of - // reusing its counter and colliding on the stamp. expect( sender.pendingOps().flatMap(({ ops }) => ops.map((op) => op.base_version)) ).toEqual([41, 42]) From bdb9d324c059459601b1cd6409e1f35aa6f38231 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:06:31 +0000 Subject: [PATCH 16/20] test: remove redundant resubscribe comment Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239136 --- src/workbench/extensions/agent/crdt/opSender.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index d8a70d9f5e1..dcd44f9ff1c 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -260,9 +260,6 @@ describe('createOpSender', () => { it('keeps a workflow its counter while a re-subscribe has not been acknowledged', () => { sender.admit([addNode(1)]) sender.admit([addNode(2)]) - // Switching docs re-subscribes, and a subscribe resets the follower's - // observed sequence until `doc_subscribed` acks it. A human edit landing in - // that window has nothing but this doc's own cursor to mint past. boundWorkflow = 'wf-2' observedSequence = 0 sender.admit([addNode(3)]) From 3ccaf821262b66b56ffd9ca167841aaa131701b1 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:06:42 +0000 Subject: [PATCH 17/20] test: remove redundant abort comments Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239140 --- src/workbench/extensions/agent/crdt/opSender.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index dcd44f9ff1c..2008390d451 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -1452,13 +1452,10 @@ describe('createOpSender', () => { localSender.admit([first, second]) localSender.flush() - // The abort invalidated the seal before recovery began, so the valid prefix - // is never probed and never rechunked: one serialization, not three. expect(firstSerializations).toBe(1) expect(localSettled).toHaveLength(1) expect(localSettled[0].state).toBe('undeliverable') expect(localSettled[0].ops).toHaveLength(2) - // The abort, not the serialization failure, is why the seal was dropped. expect(reportError).toHaveBeenCalledWith( expect.any(Error), expect.objectContaining({ From 51c3a3e9135c58f015b5e6da8861a89ffb9d7ff7 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 06:06:55 +0000 Subject: [PATCH 18/20] test: remove redundant admission ordering comments Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163239150 --- src/workbench/extensions/agent/crdt/opSender.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index 2008390d451..6072c829d23 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -1556,17 +1556,12 @@ describe('createOpSender', () => { localSender.admit([addNode(2)]) - // The deferred pump runs once the admission is placed, not mid-seal: node 2 - // was minted before the node 3 its serialization enqueued, so it goes first. expect( localSent.map(({ workflowId, ops }) => ({ workflowId, nodeIds: ops.map((op) => ('node_id' in op ? op.node_id : undefined)) })) ).toEqual([{ workflowId: 'wf-new', nodeIds: [2] }]) - // Nothing is dropped: the admission displaced by the nested enqueue keeps - // its place in mint order ahead of it, and node 1's unbound batch waits its - // turn instead of being re-addressed. expect( localSender.pendingOps().map(({ workflowId, ops }) => ({ workflowId, From 1055431d836410f773a19afd67b1bcf1ce160317 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 1 Oct 2026 23:49:30 -0700 Subject: [PATCH 19/20] docs: drop the duplicate blank line in the admit contract Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19871#discussion_r4163361089 --- src/workbench/extensions/agent/crdt/opSender.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/workbench/extensions/agent/crdt/opSender.ts b/src/workbench/extensions/agent/crdt/opSender.ts index 7b38be3576d..0b13256fe26 100644 --- a/src/workbench/extensions/agent/crdt/opSender.ts +++ b/src/workbench/extensions/agent/crdt/opSender.ts @@ -87,7 +87,6 @@ export interface OpSender { * starting transport delivery. Consecutive admissions for one workflow * share the group until `flush()` seals it. * - * * If custom serialization re-enters and closes the open group, these ops are * sealed at the queue position they were admitted at, keeping their * `op_id`s, and delivery waits until they are placed. Mint order is From 2b89b579f6e06de9fa2d98703bb4c8e45dfa1fe0 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sat, 3 Oct 2026 01:23:50 -0700 Subject: [PATCH 20/20] test: pin the mint cursor against two surviving mutants Both killed mutants leave 91/91 green at 1055431d83: - `lastMintedVersions.set(target, baseVersion)` instead of `baseVersion + minted.length - 1`. Every cursor test admits one op at a time, so the cursor's dependence on the admission's length was unasserted. Under the mutant a three-op admission followed by another admission in the same tick re-mints `base_version` 42, duplicating `(actor, 42)` on one doc. Reachable in production: `docOpMinter.flush()` enqueues an N-node edit as a single multi-op `admit`, and `restoreOpMinter` can admit again before the coalescer's microtask flush. - `Math.max(observed, lastMinted + 1)` reduced to `lastMinted + 1`. No test advanced the observed sequence past the cursor, so the floor that keeps a stamp at or above the doc sequence this follower has seen was unasserted. Both assert wire `base_version` through `pendingOps()`, not sender internals. --- .../extensions/agent/crdt/opSender.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/workbench/extensions/agent/crdt/opSender.test.ts b/src/workbench/extensions/agent/crdt/opSender.test.ts index 9f4d8227d0d..f9fe53515de 100644 --- a/src/workbench/extensions/agent/crdt/opSender.test.ts +++ b/src/workbench/extensions/agent/crdt/opSender.test.ts @@ -283,6 +283,27 @@ describe('createOpSender', () => { ]) }) + it('mints past every stamp in a multi-operation admission', () => { + sender.admit([addNode(1), addNode(2), addNode(3)]) + sender.admit([addNode(4)]) + sender.flush() + + expect( + sender.pendingOps().flatMap(({ ops }) => ops.map((op) => op.base_version)) + ).toEqual([41, 42, 43, 44]) + }) + + it('mints from the observed sequence once the document advances past this actor', () => { + sender.admit([addNode(1)]) + observedSequence = 90 + sender.admit([addNode(2)]) + sender.flush() + + expect( + sender.pendingOps().flatMap(({ ops }) => ops.map((op) => op.base_version)) + ).toEqual([41, 90]) + }) + it('serializes batches: the next sends only after the result settles the first', () => { sender.enqueue([addNode(1)]) sender.enqueue([addNode(2)])