From 9e0da096643a728149cbedc80e8d35140c3dfab8 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 30 Aug 2026 14:44:26 -0700 Subject: [PATCH 1/2] feat(agent): parse optional doc_update op_ids for per-op effect attribution --- .../agent/crdt/docFrameClient.test.ts | 44 +++++++++++++++++++ .../extensions/agent/crdt/docFrameClient.ts | 22 +++++++++- .../agent/crdt/followerSubscription.test.ts | 18 ++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/crdt/docFrameClient.test.ts b/src/workbench/extensions/agent/crdt/docFrameClient.test.ts index c43e549a8c5..a252c84b21d 100644 --- a/src/workbench/extensions/agent/crdt/docFrameClient.test.ts +++ b/src/workbench/extensions/agent/crdt/docFrameClient.test.ts @@ -55,6 +55,50 @@ describe('doc frame client', () => { ) }) + it('parses well-formed doc_update op_ids into opIds (DQ-9 attribution)', () => { + const source = new Y.Doc() + source.getMap('nodes').set('one', { x: 10 }) + const frame = parseServerDocFrame({ + type: 'doc_update', + data: { + v: 1, + workflow_id: 'wf-1', + seq: 1, + update_b64: encodeBase64(Y.encodeStateAsUpdate(source)), + op_ids: ['op-1', 'op-2'] + } + }) + if (frame?.type !== 'doc_update') throw new Error('Expected doc_update') + expect(frame.data.opIds).toEqual(['op-1', 'op-2']) + }) + + it('reads absent or malformed op_ids as unattributed, never rejecting the frame', () => { + const source = new Y.Doc() + source.getMap('nodes').set('one', { x: 10 }) + const update_b64 = encodeBase64(Y.encodeStateAsUpdate(source)) + const base = { v: 1, workflow_id: 'wf-1', seq: 1, update_b64 } + + // Catch-up frames and pre-DQ-9 hosts legally omit the field entirely. + for (const op_ids of [ + undefined, + 'op-1', // non-array + 42, + { 0: 'op-1' }, + ['op-1', 7], // mixed-type array + [null] + ]) { + const frame = parseServerDocFrame({ + type: 'doc_update', + data: op_ids === undefined ? base : { ...base, op_ids } + }) + expect(frame?.type).toBe('doc_update') + if (frame?.type !== 'doc_update') throw new Error('Expected doc_update') + expect(frame.data.opIds).toBeUndefined() + // The update bytes still ride along untouched. + expect(frame.data.update.length).toBeGreaterThan(0) + } + }) + it('replaying an update is idempotent', () => { const source = new Y.Doc() source.getArray('items').push(['a']) diff --git a/src/workbench/extensions/agent/crdt/docFrameClient.ts b/src/workbench/extensions/agent/crdt/docFrameClient.ts index 5bf74412e1a..a71a8b0b8a0 100644 --- a/src/workbench/extensions/agent/crdt/docFrameClient.ts +++ b/src/workbench/extensions/agent/crdt/docFrameClient.ts @@ -11,6 +11,14 @@ export interface DocUpdate { seq: number update: Uint8Array actor?: string + /** + * Authoritative per-op effect attribution (DQ-9): the `op_id`s whose effects + * this update frame carries. Absent on catch-up frames (which legally fold + * many ops into one snapshot) and on hosts that predate DQ-9 — absence means + * "unattributed", never "no ops". A frame missing or malforming this field + * still applies; attribution is diagnostic, not a gate. + */ + opIds?: string[] } export interface DocSubscribed { @@ -85,6 +93,7 @@ interface WireData { workflow_id?: unknown seq?: unknown update_b64?: unknown + op_ids?: unknown actor?: unknown ok?: unknown code?: unknown @@ -111,6 +120,16 @@ function parseWireData(value: unknown): WireData | null { return typeof value === 'object' && value !== null ? value : null } +/** + * Tolerant `op_ids` guard: anything other than an array of strings — absent, + * non-array, or an array with a non-string member — reads as "unattributed" + * rather than rejecting the frame. Update bytes are the contract; attribution + * is best-effort metadata a malformed field must never take down. + */ +function isStringArray(value: unknown): value is string[] { + return Array.isArray(value) && value.every((item) => typeof item === 'string') +} + function parseRecord(value: unknown): Record | null { return typeof value === 'object' && value !== null ? Object.fromEntries(Object.entries(value)) @@ -139,7 +158,8 @@ export function parseServerDocFrame(value: unknown): ServerDocFrame | null { workflowId: data.workflow_id, seq: data.seq, update: decodeBase64(data.update_b64), - ...(typeof data.actor === 'string' && { actor: data.actor }) + ...(typeof data.actor === 'string' && { actor: data.actor }), + ...(isStringArray(data.op_ids) && { opIds: [...data.op_ids] }) } } } diff --git a/src/workbench/extensions/agent/crdt/followerSubscription.test.ts b/src/workbench/extensions/agent/crdt/followerSubscription.test.ts index 89e6107b102..18bdec9b29a 100644 --- a/src/workbench/extensions/agent/crdt/followerSubscription.test.ts +++ b/src/workbench/extensions/agent/crdt/followerSubscription.test.ts @@ -168,6 +168,24 @@ describe('FE-SUBSCRIBE-1 — a subscribe raced against socket startup recovers', }) }) +describe('DQ-9 — op attribution rides the re-dispatched frame', () => { + it('opIds pass through the bridge to doc_update listeners untouched', () => { + const { transport, bridge, projected } = wire() + transport.open = true + bridge.subscribe(WORKFLOW_ID) + + transport.deliver('doc_update', { + ...docUpdateFrame(hostDocUpdate()), + op_ids: ['op-1', 'op-2'] + }) + + expect(projected).toHaveLength(1) + expect(projected[0].opIds).toEqual(['op-1', 'op-2']) + // Attribution is metadata: the update itself was still applied. + expect(bridge.follower.updatesApplied).toBe(1) + }) +}) + describe('FE-TEARDOWN-1 — teardown completes with a dead socket', () => { it('releases every transport listener and the doc when unsubscribe cannot send', () => { const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}) From 59133959421ea1243323559ac382a3c4acdfea70 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 30 Aug 2026 21:48:26 +0000 Subject: [PATCH 2/2] [automated] Apply ESLint and Oxfmt fixes --- .../vueNodes/composables/processedWidgetRenderModel.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/extensions/vueNodes/composables/processedWidgetRenderModel.ts b/src/renderer/extensions/vueNodes/composables/processedWidgetRenderModel.ts index 60447e76160..7d6cd813a71 100644 --- a/src/renderer/extensions/vueNodes/composables/processedWidgetRenderModel.ts +++ b/src/renderer/extensions/vueNodes/composables/processedWidgetRenderModel.ts @@ -459,7 +459,7 @@ export function computeProcessedWidgets({ forceDisabled = false, isGraphReady, rootGraph, - ui, + ui }: ComputeProcessedWidgetsOptions): ProcessedWidget[] { if (!nodeData) return [] @@ -512,7 +512,7 @@ export function computeProcessedWidgets({ missingModelStore, missingMediaStore, nodeDefStore, - ui, + ui } return Array.from(new Set(ids))