Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export function computeProcessedWidgets({
forceDisabled = false,
isGraphReady,
rootGraph,
ui,
ui
}: ComputeProcessedWidgetsOptions): ProcessedWidget[] {
if (!nodeData) return []

Expand Down Expand Up @@ -512,7 +512,7 @@ export function computeProcessedWidgets({
missingModelStore,
missingMediaStore,
nodeDefStore,
ui,
ui
}

return Array.from(new Set(ids))
Expand Down
44 changes: 44 additions & 0 deletions src/workbench/extensions/agent/crdt/docFrameClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
22 changes: 21 additions & 1 deletion src/workbench/extensions/agent/crdt/docFrameClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -85,6 +93,7 @@ interface WireData {
workflow_id?: unknown
seq?: unknown
update_b64?: unknown
op_ids?: unknown
actor?: unknown
ok?: unknown
code?: unknown
Expand All @@ -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<string, unknown> | null {
return typeof value === 'object' && value !== null
? Object.fromEntries(Object.entries(value))
Expand Down Expand Up @@ -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] })
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/workbench/extensions/agent/crdt/followerSubscription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {})
Expand Down
Loading