Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
19f4bf4
test(agent-crdt): regression tests for agent-added nodes with no live…
christian-byrne Sep 2, 2026
654d998
test(agent-crdt): assert the layout port call in the qa-59 companion …
christian-byrne Sep 2, 2026
a3f7e7d
fix(agent-crdt): materialize a live LGraphNode adapter for agent-adde…
christian-byrne Sep 2, 2026
59ef1eb
fixup: drop unused LGraph re-export, type mountFollower's getGraph param
christian-byrne Sep 2, 2026
f229b46
fix(agent-crdt): add missing DevEventKind for qa-59's materialize event
christian-byrne Sep 2, 2026
fa48986
fix(agent-crdt): retain pending materialize ids and make materializer…
christian-byrne Sep 2, 2026
101cc21
chore: trigger PR sync after rebase (no-op)
christian-byrne Sep 2, 2026
4e70917
[automated] Apply ESLint and Oxfmt fixes
actions-user Sep 3, 2026
aa3f2f2
fix(agent-crdt): address round-2 review threads on qa-59 materializer…
christian-byrne Sep 3, 2026
54711d9
fix(agent-crdt): make adapter reconcile transactional against store r…
christian-byrne Sep 3, 2026
ea853f2
fix(agent-crdt): remove partially attached adapter when onAdded() thr…
christian-byrne Sep 3, 2026
c89eb0b
test(agent-crdt): use real reconcileNode mutation for the reconcile-p…
christian-byrne Sep 3, 2026
98df4e9
Merge remote-tracking branch 'origin/main' into pr16652
christian-byrne Sep 3, 2026
85e748f
fix(agent): derive live-node reconcile from store state
christian-byrne Sep 3, 2026
599f66b
test(agent): reconcile only applied frames; prove layout survives add…
christian-byrne Sep 3, 2026
f873f89
fix(agent): materialize remote link adapters
christian-byrne Sep 3, 2026
09835d2
Merge remote-tracking branch 'origin/main' into test/qa-59-agent-node…
christian-byrne Sep 3, 2026
5699bd1
fix(agent-crdt): keep materialize rollback atomic when cleanup throws
christian-byrne Sep 3, 2026
71bd5ec
fix(agent-crdt): reconcile live adapters after a reset and on activation
christian-byrne Sep 3, 2026
22c80eb
fix(agent-crdt): preserve removal lifecycle during reconciliation
christian-byrne Sep 3, 2026
2349270
fix: preserve successor errors during adapter replacement
christian-byrne Sep 3, 2026
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
33 changes: 33 additions & 0 deletions src/composables/graph/useErrorClearingHooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,39 @@ describe('onNodeRemoved clears missing asset errors by execution ID', () => {
expect(modelStore.missingModelCandidates).toBeNull()
})

it('preserves same-id successor missing model errors', () => {
const graph = new LGraph()
const orphan = new LGraphNode('CheckpointLoaderSimple')
graph.add(orphan)
const successor = new LGraphNode('CheckpointLoaderSimple')
successor.id = orphan.id
graph._nodes.push(successor)
graph._nodes_by_id[orphan.id] = successor

vi.spyOn(app, 'rootGraph', 'get').mockReturnValue(graph)
installErrorClearingHooks(graph)

const modelStore = useMissingModelStore()
modelStore.setMissingModels([
fromAny<
Parameters<typeof modelStore.setMissingModels>[0][number],
unknown
>({
nodeId: String(successor.id),
nodeType: 'CheckpointLoaderSimple',
widgetName: 'ckpt_name',
isAssetSupported: false,
name: 'model.safetensors',
isMissing: true
})
])

graph.remove(orphan, { preserveCanonicalState: true })

expect(graph.getNodeById(successor.id)).toBe(successor)
expect(modelStore.missingModelCandidates).toHaveLength(1)
})

it('removes missing model errors when the graph is cleared', () => {
const graph = new LGraph()
const node = new LGraphNode('CheckpointLoaderSimple')
Expand Down
15 changes: 11 additions & 4 deletions src/composables/graph/useErrorClearingHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import { useChainCallback } from '@/composables/functional/useChainCallback'
import { resolvePromotedWidgetSource } from '@/core/graph/subgraph/resolvePromotedWidgetSource'
import { createPromotionErrorReconciler } from '@/core/graph/subgraph/createPromotionErrorReconciler'
import type { NodeLifecycleEvent } from '@/lib/litegraph/src/infrastructure/LGraphEventMap'
import type {
NodeBeforeRemovedEvent,
NodeLifecycleEvent
} from '@/lib/litegraph/src/infrastructure/LGraphEventMap'
import { LiteGraph, Subgraph } from '@/lib/litegraph/src/litegraph'
import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
import {
Expand Down Expand Up @@ -585,16 +588,20 @@ export function installErrorClearingHooks(graph: LGraph): () => void {

// `node:before-removed` covers both single removals and graph.clear();
// `node:removed` fires only from LGraph.remove.
const onNodeRemoved = ({ detail: { node } }: NodeLifecycleEvent) => {
const onNodeRemoved = ({
detail: { node, successor }
}: NodeBeforeRemovedEvent) => {
if (disposed) return
for (const scan of pendingScans.get(node) ?? []) scan.cancel()
// Derive the execution ID from the graph the hook is installed on plus
// node.id. For subgraph interior nodes this yields the full
// "parentId:...:nodeId" path that matches how missing asset errors are
// keyed; without this, removal falls back to the local ID and misses
// subgraph entries.
const execId = getRemovedNodeExecutionId(graph, node.id)
removeNodeErrors(node, execId)
if (!successor) {
const execId = getRemovedNodeExecutionId(graph, node.id)
removeNodeErrors(node, execId)
}
scheduleDropOutOfScopeMissingMedia()
restoreNodeHooksRecursive(node)
promotionErrors.detachNode(node)
Expand Down
71 changes: 71 additions & 0 deletions src/lib/litegraph/src/LGraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import { createGraphMutations } from '@/core/graph/graphMutations'
import type { NodeLifecycleEvent } from '@/lib/litegraph/src/infrastructure/LGraphEventMap'
import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas'
import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
Expand Down Expand Up @@ -31,6 +32,7 @@ import { useEntityIdStore } from '@/stores/entityIdStore'
import { useLinkStore } from '@/stores/linkStore'
import { useExecutionOrderStore } from '@/stores/executionOrderStore'
import { useGraphMetadataStore } from '@/stores/graphMetadataStore'
import { useNodeDataStore } from '@/stores/nodeDataStore'
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
import { usePreviewExposureStore } from '@/stores/previewExposureStore'
import { useRerouteStore } from '@/stores/rerouteStore'
import { useWidgetValueStore } from '@/stores/widgetValueStore'
Expand Down Expand Up @@ -863,6 +865,57 @@ describe('Store-driven serialization parity', () => {
)
})

// Pins the desired outcome, not the current one. `agentNodeMaterializer.ts`
// closes this gap for anything routed through `useAgentCrdtFollower`, but a
// bare `LGraph` + `graphMutations.addNode()` (as below) never calls the
// materializer, so the `LGraph._nodes` gap this test documents is still
// real for any caller that skips the follower composable. `test.fails`
// keeps the assertions expressing the CORRECT behavior; convert to a plain
// `test` the day `LGraph.serialize()`/`addNode()` itself closes the gap.
test.fails('does NOT drop an agent-added node from serialize() when only the ECS store, not LGraph._nodes, has it', ({
expect
}) => {
// The CRDT follower's addNode path
// (`graphMutations.commit()` -> nodeStore/widgetStore/layout, see
// `src/core/graph/graphMutations.ts`) never constructs an LGraphNode and
// never calls `LGraph.add()`, so the node exists in the ECS node-data
// store (and renders on canvas via the store-driven Vue node path) but
// has no adapter in `LGraph._nodes`. `serialiseStoredNodes()` hits the
// adapter/state mismatch branch and silently serializes only the
// (empty) live-adapter set, so the node is dropped from every save.
const graph = new LGraph()
const scope = graphScopeOf(graph)
const createLayout = vi.fn()
const mutations = createGraphMutations({
getScope: () => scope,
layout: { createNode: createLayout, deleteNodes: vi.fn() }
})

mutations.addNode(
{
id: 1,
type: 'dummy',
pos: [0, 0],
size: [100, 80],
inputs: [],
outputs: []
},
{ source: 'agent-remote', actor: 'agent:test', opId: 'op-1' }
)

// The node is real in the ECS store...
expect(
useNodeDataStore().getGraphNodesFor(graph.rootGraph.id, graph.id)
).toHaveLength(1)

const serialized = graph.serialize()

// Desired behavior: the store-only node survives serialize() and no
// mismatch is reported.
expect(serialized.nodes).toHaveLength(1)
expect(mockReportError).not.toHaveBeenCalled()
})

test('rejects additive configuration before mutating a populated graph', ({
expect
}) => {
Expand Down Expand Up @@ -1055,6 +1108,24 @@ describe('node:before-removed event', () => {
expect(node.graph).toBeNull()
})

it('identifies the successor when preserving same-id canonical state', () => {
const graph = new LGraph()
const node = new LGraphNode('test')
graph.add(node)
const successor = new LGraphNode('test')
successor.id = node.id
graph._nodes.push(successor)
graph._nodes_by_id[node.id] = successor

const beforeRemoved = vi.fn()
graph.events.addEventListener('node:before-removed', beforeRemoved)

graph.remove(node, { preserveCanonicalState: true })

expect(beforeRemoved).toHaveBeenCalledOnce()
expect(beforeRemoved.mock.calls[0][0].detail).toEqual({ node, successor })
})

it('does not fire node:before-removed for a node not in the graph', () => {
const graph = new LGraph()
const node = new LGraphNode('test')
Expand Down
85 changes: 58 additions & 27 deletions src/lib/litegraph/src/LGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
detachGroupLayout,
detachNodeLayout,
detachRerouteLayout,
materializeRerouteLayout
materializeRerouteLayout,
releaseNodeLayoutAttachment
} from '@/renderer/core/layout/operations/graphLayoutAttachment'
import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
import { nodesInRenderOrder } from '@/renderer/core/canvas/litegraph/arrangeForLegacyRender'
Expand Down Expand Up @@ -222,6 +223,15 @@ export interface GraphAddOptions {
dragEvent?: MouseEvent
}

/** Options for {@link LGraph.remove} method. */
export interface GraphRemoveOptions {
/**
* Detach an adapter after another authority has reconciled canonical stores.
* Same-id replacement state is left intact.
*/
preserveCanonicalState?: boolean
}

export interface LGraphExtra extends Dictionary<unknown> {
reroutes?: SerialisableReroute[]
linkExtensions?: { id: LinkId; parentId: RerouteId | undefined }[]
Expand Down Expand Up @@ -1380,7 +1390,10 @@ export class LGraph
* Removes a node from the graph
* @param node the instance of the node
*/
remove(node: LGraphNode | LGraphGroup): void {
remove(
node: LGraphNode | LGraphGroup,
options: GraphRemoveOptions = {}
): void {
// LEGACY: This was changed from constructor === LiteGraph.LGraphGroup
if (node instanceof LGraphGroup) {
this.canvasAction((c) => c.deselect(node))
Expand All @@ -1400,12 +1413,12 @@ export class LGraph
if (nodesBeingRemoved.has(node)) return

// not found
if (this._nodes_by_id[node.id] == null) {
if (this._nodes_by_id[node.id] == null && !options.preserveCanonicalState) {
console.warn('LiteGraph: node not found', node)
return
}
// cannot be removed
if (node.ignore_remove) {
if (node.ignore_remove && !options.preserveCanonicalState) {
console.warn('LiteGraph: node cannot be removed', node)
return
}
Expand All @@ -1417,38 +1430,47 @@ export class LGraph

nodesBeingRemoved.add(node)
try {
this.batchVersionUpdates(() => this.removeNode(node))
this.batchVersionUpdates(() => this.removeNode(node, options))
} finally {
nodesBeingRemoved.delete(node)
}
}

private removeNode(node: LGraphNode): void {
private removeNode(node: LGraphNode, options: GraphRemoveOptions): void {
const successor =
options.preserveCanonicalState &&
this._nodes_by_id[node.id] !== node &&
this._nodes_by_id[node.id] != null
? this._nodes_by_id[node.id]
: undefined

// sure? - almost sure is wrong
this.beforeChange()

this.events.dispatch('node:before-removed', { node })
this.events.dispatch('node:before-removed', { node, successor })

const { inputs, outputs } = node
if (!successor) {
const { inputs, outputs } = node

// disconnect inputs
if (inputs) {
for (const [i] of inputs.entries()) {
if (inputHasLink(this, node.id, i)) node.disconnectInput(i, true)
// disconnect inputs
if (inputs) {
for (const [i] of inputs.entries()) {
if (inputHasLink(this, node.id, i)) node.disconnectInput(i, true)
}
}
}

// disconnect outputs
if (outputs) {
for (const i of outputs.keys()) {
if (outputHasLinks(this, node.id, i)) node.disconnectOutput(i)
// disconnect outputs
if (outputs) {
for (const i of outputs.keys()) {
if (outputHasLinks(this, node.id, i)) node.disconnectOutput(i)
}
}
}

// Floating links
for (const link of this.floatingLinks.values()) {
if (link.origin_id === node.id || link.target_id === node.id) {
this.removeFloatingLink(link)
// Floating links
for (const link of this.floatingLinks.values()) {
if (link.origin_id === node.id || link.target_id === node.id) {
this.removeFloatingLink(link)
}
}
}

Expand All @@ -1472,12 +1494,19 @@ export class LGraph

// callback
node.onRemoved?.()
clearNodeOwnedStoreState(node)
if (!successor) clearNodeOwnedStoreState(node)
Comment thread
christian-byrne marked this conversation as resolved.
Resolved

const order = node.order
useExecutionOrderStore().remove(graphScopeOf(this), node.id)
detachNodeFromStores(this, node)
detachNodeLayout(node)
if (!successor) {
useExecutionOrderStore().remove(graphScopeOf(this), node.id)
}
if (options.preserveCanonicalState) {
node._graphScope = undefined
releaseNodeLayoutAttachment(node)
} else {
detachNodeFromStores(this, node)
detachNodeLayout(node)
}

node.graph = null
node.order = order
Expand All @@ -1498,7 +1527,9 @@ export class LGraph
const pos = this._nodes.indexOf(node)
if (pos != -1) this._nodes.splice(pos, 1)

delete this._nodes_by_id[node.id]
if (this._nodes_by_id[node.id] === node) {
delete this._nodes_by_id[node.id]
}
this.onNodeRemoved?.(node)
this.events.dispatch('node:removed', { node })

Expand Down
36 changes: 36 additions & 0 deletions src/lib/litegraph/src/LLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,42 @@ export function resolveLinkTopology(topology: LinkTopology): LLink | undefined {
return linkByTopology.get(toRaw(topology))
}

/**
* Gives a topology that was registered directly by a renderer-free store
* mutation its live LiteGraph facade. The store remains the identity owner;
* this only installs the adapter used by graph lookup, painting, and link
* interactions.
*/
export function materializeLinkAdapter(
graph: Pick<LGraph, 'rootGraph' | 'id'>,
topology: LinkTopology
): LLink | undefined {
const rawTopology = toRaw(topology)
const existing = linkByTopology.get(rawTopology)
if (existing) return existing

const scope = graphScopeOf(graph)
const registered = useLinkStore().getTopology(scope.rootGraphId, topology.id)
if (
registered?.graphId !== scope.owningGraphId ||
toRaw(registered) !== rawTopology
) {
return
}

const link = new LLink(
topology.id,
topology.type,
serializeNodeId(topology.originNodeId),
topology.originSlot,
serializeNodeId(topology.targetNodeId),
topology.targetSlot,
topology.parentId
)
adoptLinkTopology(link, scope, registered)
return link
}

function defineEnumerableTopologyFacade(link: LLink): void {
topologyFacadeDescriptors ??= [
'id',
Expand Down
5 changes: 5 additions & 0 deletions src/lib/litegraph/src/infrastructure/LGraphEventMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface LGraphEventMap {
*/
'node:before-removed': {
node: LGraphNode
successor?: LGraphNode
}

/**
Expand All @@ -92,3 +93,7 @@ export interface LGraphEventMap {
export type NodeLifecycleEvent = CustomEvent<
LGraphEventMap['node:added' | 'node:removed']
>

export type NodeBeforeRemovedEvent = CustomEvent<
LGraphEventMap['node:before-removed']
>
Loading
Loading