Repository navigation
fix(agent): release minimap graph-activity layer reliably on unmount #20071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import { | |
| defineAsyncComponent, | ||
| nextTick, | ||
| onBeforeUnmount, | ||
| onMounted, | ||
| provide, | ||
| readonly, | ||
| ref, | ||
|
|
@@ -41,6 +42,7 @@ import { AGENT_ATTACH_ACCEPT, isAgentAttachable } from './utils/attachableFiles' | |
| import { getNodeByLocatorId } from '@/utils/graphTraversalUtil' | ||
| // oxlint-disable-next-line comfy/no-restricted-paths | ||
| import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' | ||
| import type { MinimapDecorationLayer } from '@/platform/canvas/minimapDecorationRegistry' | ||
| import { registerMinimapDecorationLayer } from '@/platform/canvas/minimapDecorationRegistry' | ||
| // The composition root injects the renderer-owned layout port; follower core | ||
| // stays independent of renderer and LiteGraph runtime values. | ||
|
|
@@ -409,33 +411,37 @@ watch( | |
| }, | ||
| { immediate: true } | ||
| ) | ||
| const agentMinimapLayer = registerMinimapDecorationLayer('agent.graph-activity') | ||
| watch( | ||
| () => graphActivity.state, | ||
| (activity) => { | ||
| if (activity.phase === 'idle') { | ||
| agentMinimapLayer.replace([]) | ||
| return | ||
| } | ||
| const rootGraphId = toRootGraphId(activity.rootGraphId) | ||
| agentMinimapLayer.replace( | ||
| activity.nodeIds.map((nodeId) => ({ | ||
| target: { | ||
| rootGraphId, | ||
| owningGraphId: toOwningGraphId(activity.rootGraphId), | ||
| nodeId | ||
| }, | ||
| enter: 'pop' | ||
| })) | ||
| ) | ||
| if ( | ||
| activity.phase === 'running' && | ||
| !settingStore.get('Comfy.Minimap.Visible') | ||
| ) | ||
| void settingStore.set('Comfy.Minimap.Visible', true) | ||
| }, | ||
| { immediate: true } | ||
| ) | ||
| // Claimed on mount rather than in setup so a setup failure cannot leave the id | ||
| // registered with no unmount to release it. | ||
| let agentMinimapLayer: MinimapDecorationLayer | undefined | ||
| function syncAgentMinimapLayer(activity: typeof graphActivity.state): void { | ||
| if (activity.phase === 'idle') { | ||
| agentMinimapLayer?.replace([]) | ||
| return | ||
| } | ||
| const rootGraphId = toRootGraphId(activity.rootGraphId) | ||
| agentMinimapLayer?.replace( | ||
| activity.nodeIds.map((nodeId) => ({ | ||
| target: { | ||
| rootGraphId, | ||
| owningGraphId: toOwningGraphId(activity.rootGraphId), | ||
| nodeId | ||
| }, | ||
| enter: 'pop' | ||
| })) | ||
| ) | ||
| if ( | ||
| activity.phase === 'running' && | ||
| !settingStore.get('Comfy.Minimap.Visible') | ||
| ) | ||
| void settingStore.set('Comfy.Minimap.Visible', true) | ||
| } | ||
| watch(() => graphActivity.state, syncAgentMinimapLayer, { immediate: true }) | ||
| onMounted(() => { | ||
| agentMinimapLayer = registerMinimapDecorationLayer('agent.graph-activity') | ||
| syncAgentMinimapLayer(graphActivity.state) | ||
| }) | ||
| onBeforeUnmount(() => agentMinimapLayer?.dispose()) | ||
| const { accepted: consentAccepted } = storeToRefs(useAgentConsentStore()) | ||
| const { withConsent } = useAgentConsent() | ||
| const workspaceStore = useTeamWorkspaceStore() | ||
|
|
@@ -1243,7 +1249,6 @@ onBeforeUnmount(() => { | |
| ++activeTabGeneration | ||
| tabActivity.setEditing(null) | ||
| tabActivity.setCreating(false) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — Pulling only
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed this hazard exists, but it predates this PR: those steps were already unguarded before #17730's layer was added, and wrapping them (as Generated by Claude Code
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reopening this: the follow-up exists now — #20078. Two corrections to the reply above. It does not only predate #20071: #20071 added a dependency on the hazard by putting a step before the hook whose failure it is protecting against, which is why the layer dispose had to move out. And the gate is not merely reset late — it is never reset at all. Arming #20078 runs every step of all three |
||
| agentMinimapLayer.dispose() | ||
| // PM-1575: the store singleton outlives this component. Without resetting | ||
| // the gate here, a remount's own setCanvasSyncGate() call is the only | ||
| // thing standing between the old (now torn-down) follower's gate and a | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.