Skip to content

[feat] Add auto-refresh on task completion for RemoteWidget nodes #4191

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

Merged
merged 8 commits into from
Jun 23, 2025

Conversation

christian-byrne
Copy link
Contributor

@christian-byrne christian-byrne commented Jun 16, 2025

Implements auto-refresh toggle button for nodes with remote widgets. When enabled, automatically refreshes the widget when the workflow completes execution.

auto-refresh-node-demo.mp4

Implementation Details:

  • Uses WebSocket execution_success event to detect workflow completion
  • Simple toggle widget labeled "Auto-refresh after generation"
  • Proper cleanup when nodes are removed

Test Plan:

  • Won't affect any extensions using remote widgets (via code search)
  • Does not affect saved workflows with remote widgets
  • Runtime-added toggle widget is not serialized in prompts
  • All unit tests passing

Fixes #4153

┆Issue is synchronized with this Notion page by Unito

@christian-byrne christian-byrne requested review from a team as code owners June 16, 2025 00:01
@christian-byrne christian-byrne force-pushed the load-outputs-auto-refresh branch from d2bb38c to d7f8834 Compare June 16, 2025 06:57
Copy link
Contributor

@webfiltered webfiltered left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits.

Overall for the current solution, it feels a little over-engineered. Assuming re-use and that we will add more complex, fine-tuned UX as our app matures in the near future, it feels awesome.

Comment on lines 229 to 232
let taskWatcher: ReturnType<typeof useTaskCompletionWatcher> | null = null

// Initialize task completion watcher
taskWatcher = useTaskCompletionWatcher({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is just immediate reassignment?

Suggested change
let taskWatcher: ReturnType<typeof useTaskCompletionWatcher> | null = null
// Initialize task completion watcher
taskWatcher = useTaskCompletionWatcher({
// Initialize task completion watcher
const taskWatcher = useTaskCompletionWatcher({

Comment on lines 248 to 250
taskWatcher?.start()
} else {
taskWatcher?.stop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
taskWatcher?.start()
} else {
taskWatcher?.stop()
taskWatcher.start()
} else {
taskWatcher.stop()


// Cleanup on node removal
node.onRemoved = useChainCallback(node.onRemoved, function () {
taskWatcher?.stop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
taskWatcher?.stop()
taskWatcher.stop()

Comment on lines 234 to 236
onComplete: () => {
if (widget.refresh) {
widget.refresh()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onComplete: () => {
if (widget.refresh) {
widget.refresh()
}
}
onComplete: () => widget.refresh?.()

start()
}

onUnmounted(() => stop())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onUnmounted(() => stop())
onUnmounted(stop)

nit: perf

Copy link
Contributor Author

@christian-byrne christian-byrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a task completion watcher, let's simplify this PR by just listening for the execution_success WS message.

As an example, look here:

https://github.com/Comfy-Org/ComfyUI_frontend/blob/fix/animated-png-display/src/scripts/app.ts#L643-L662

@webfiltered
Copy link
Contributor

Does this only need to run for output nodes?

@christian-byrne
Copy link
Contributor Author

It should run when the workflow is done executing.

Implements auto-refresh functionality that triggers when tasks complete for any RemoteWidget node. Users can toggle the feature on/off via a boolean widget labeled "Auto-refresh on task completion".

Key components:
- useTaskCompletionWatcher: Reusable composable that watches queue history to detect task completion
- RemoteWidget enhancement: Automatically adds toggle widget to all remote widgets
- Comprehensive test coverage for both composables

Fixes #4153
…ctations

- Changed default value from true to false
- Added 'on' and 'off' labels for the toggle states
- Ensures consistency with existing widget patterns
- Removed expectation for 'on' and 'off' properties in test
- Aligns test with actual implementation after label removal
…vent

- Remove complex task completion watcher composable
- Use WebSocket 'execution_success' event for workflow completion detection
- Much simpler implementation (~35 lines vs ~100+ lines)
- Update widget label to "Auto-refresh after generation"
- Add debug logging for execution success handler
- Update test to expect "Auto-refresh after generation" label
- All tests now passing
@christian-byrne christian-byrne force-pushed the load-outputs-auto-refresh branch from c238abf to 500b84c Compare June 16, 2025 22:27
christian-byrne and others added 3 commits June 20, 2025 16:29
Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
@christian-byrne christian-byrne merged commit 3a1bd18 into main Jun 23, 2025
10 checks passed
@christian-byrne christian-byrne deleted the load-outputs-auto-refresh branch June 23, 2025 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add auto-refresh to Load Image (from Output) node
2 participants