From bc4df43d7433638c26ad41db0ef23fc563154645 Mon Sep 17 00:00:00 2001 From: jaeone lee <89377375+jaeone94@users.noreply.github.com> Date: Thu, 15 Oct 2026 06:00:56 +0000 Subject: [PATCH] fix: mint shifted DynamicGroup row values after a middle-row removal (#21057) ## Summary In a doc-bound workflow, deleting a middle DynamicGroup row only minted the row-count `set_widget`. The later rows were renamed locally, but nothing was minted for the shifted `group.N.*` fields, so the document and peers dropped the last row and kept the deleted row's values (3 rows, delete row 0: this tab shows `[r1, r2]`, the doc ends up `[r0, r1]`). Each serializable widget renamed by a row shift now announces its current value (`announceValue`) under its new name. The minter still mints only local writes, so remote and load removals mint nothing. Stacked on #20992. Fixes https://github.com/Comfy-Org/ComfyUI_frontend/pull/20992#discussion_r4277691206 ## Review focus - The shifted field `set_widget`s are minted before the count decrement. The doc host resolves each register by stamp, so the order does not change the final state. - Follow-up, not in this PR: the removed trailing row's registers are not cleared in the doc. A local regrow overwrites them (#20992 mints every added field), but a remote count write that regrows the group without field values could still bring back stale values. ## Tests - Red: new `mints the shifted field values after a middle row is removed` failed on the base branch. Only `set_widget loras 3 -> 2` was minted, with no `loras.1.*` ops. - Green: `pnpm -s vitest run src/core/graph src/workbench/extensions/agent/crdt src/stores/widgetValueStore.test.ts`: 89 files, 1375 passed, 1 expected fail. - Reverted only the implementation and confirmed the new test fails again. - Added `mints nothing for a row removed by a agent-remote/load write`. --- src/core/graph/widgets/dynamicGroupWidget.ts | 21 ++++-- .../extensions/agent/crdt/docOpMinter.test.ts | 68 +++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/core/graph/widgets/dynamicGroupWidget.ts b/src/core/graph/widgets/dynamicGroupWidget.ts index 4586b940340..0db92e7e809 100644 --- a/src/core/graph/widgets/dynamicGroupWidget.ts +++ b/src/core/graph/widgets/dynamicGroupWidget.ts @@ -214,16 +214,29 @@ export function dynamicGroupWidget( } } + function renameRowWidgets(oldPrefix: string, newPrefix: string) { + for (const widget of node.widgets ?? []) { + if (widget.name !== oldPrefix && !widget.name.startsWith(`${oldPrefix}.`)) + continue + const name = newPrefix + widget.name.slice(oldPrefix.length) + widget.name = name + if ( + widget.name === name && + widget.serialize !== false && + widget.type !== 'button' && + widget.widgetId + ) + store.announceValue(widget.widgetId) + } + } + function renameRow( oldPrefix: string, newPrefix: string, hosts: PromotionHostLookup ) { const rowLabel = rows().find((row) => row.name === oldPrefix)?.label - for (const widget of node.widgets ?? []) { - if (widget.name === oldPrefix || widget.name.startsWith(`${oldPrefix}.`)) - widget.name = newPrefix + widget.name.slice(oldPrefix.length) - } + renameRowWidgets(oldPrefix, newPrefix) for (const input of node.inputs) { if (!input.name.startsWith(`${oldPrefix}.`)) continue input.name = newPrefix + input.name.slice(oldPrefix.length) diff --git a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts index d0097907ee1..f9e33c09977 100644 --- a/src/workbench/extensions/agent/crdt/docOpMinter.test.ts +++ b/src/workbench/extensions/agent/crdt/docOpMinter.test.ts @@ -1776,6 +1776,74 @@ describe('attachDocOpMinter', () => { ]) }) + function seedThreeRows() { + const seeded = seedGroup() + const { widget } = seeded + withGraphIntentSource('load', () => { + widget('loras').value = 3 + widget('loras.0.seed').value = 10 + widget('loras.1.seed').value = 11 + widget('loras.1.seed.0').value = 'increment' + widget('loras.2.seed').value = 12 + widget('loras.2.seed.0').value = 'decrement' + }) + return seeded + } + + it('mints the shifted field values after a middle row is removed', async () => { + const { node, widget } = seedThreeRows() + + widget('loras.1').callback?.(undefined) + await afterFlush() + + const setWidget = (name: string, value: unknown, old: unknown) => ({ + op: 'set_widget', + node_id: node.id, + widget: name, + value, + old + }) + expect(minted).toEqual([ + setWidget('loras.1.lora_name', 'A', undefined), + setWidget('loras.1.seed', 12, undefined), + setWidget('loras.1.seed.0', 'decrement', undefined), + setWidget('loras', 2, 3) + ]) + }) + + it('does not mint a shifted field whose rename was refused', async () => { + const { node, widget } = seedThreeRows() + vi.spyOn(useWidgetValueStore(), 'renameWidget').mockReturnValue(undefined) + + widget('loras.1').callback?.(undefined) + await afterFlush() + + expect(minted).toEqual([ + { + op: 'set_widget', + node_id: node.id, + widget: 'loras', + value: 2, + old: 3 + } + ]) + }) + + it.for(['agent-remote', 'load'] as const)( + 'mints nothing for a row removed by a %s write', + async (source) => { + const { widget } = seedThreeRows() + + withGraphIntentSource(source, () => { + widget('loras.1').callback?.(undefined) + }) + await afterFlush() + + expect(widget('loras.1.seed').value).toBe(12) + expect(minted).toEqual([]) + } + ) + it.for(['agent-remote', 'load'] as const)( 'mints nothing for a row added by a %s write', async (source) => {