Skip to content

feat(apps): tell app pages which build is busy, and let a page report its runs - #2353

Open
PabloWiedemann wants to merge 16 commits into
claude/app-keep-runningfrom
claude/app-busy-builds
Open

PabloWiedemann wants to merge 16 commits into
claude/app-keep-runningfrom
claude/app-busy-builds

Conversation

@PabloWiedemann

@PabloWiedemann PabloWiedemann commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2351 (keep apps running in the background). Split out of #2351 in review, because this is the part the website uses. Related to DESK-588.

What changes

This PR adds two things to the bridge that Comfy pages in the Apps view use.

1. Which build is busy, for the website's Run on menu

  • comfyDesktopLocal.localBuilds() now gives busyWith: { appId, title } for a build that is working on, or has first in its queue, a run from another app in the Apps view. It names the working run first, otherwise the oldest queued one, and never the app that asks. For example, title is "Remove Background". It is absent when Desktop has no name for the app, so the page says "another app" in its own words and language. When a queued run starts working, the pages are told, so busyWith follows the working run.
  • Desktop sees only runs that apps in the Apps view send. busyWith is absent when no other app has a run on the build, but the build can still be busy with a run from its own ComfyUI window or another tool. Reading the build's own queue too is a product question for later.
  • comfyDesktopLocal.onLocalBuildsChanged(callback) is new and optional. It calls back when a run from an app starts or ends on a build. Each page gets the list as it sees it, and nothing is sent once Apps is turned off.
  • Desktop numbers each announcement, so an older answer that arrives late cannot overwrite a newer one.
  • A build runs one workflow at a time, and ComfyUI already queues a second POST /prompt. Desktop does not refuse or reorder runs.

2. A page can report its own runs

  • window.comfyDesktopRuns.reportRun({ running: boolean }) is new.
  • Call it with running: true when the person presses Run, keep the run going through any queue wait, and call it with running: false when the run finishes, fails or is cancelled.
  • Once a page calls it, Desktop uses only these reports for that page. It stops watching the page's run toast. Pages that never call it still work through the toast (.cs-toasts .cs-toast), as in feat(apps): keep apps running in the background when you switch away #2351.
  • Desktop uses this signal to keep a page alive in the background, for the rail spinner and the title bar indicator, and to ask before closing or quitting.

Contract

  • src/types/comfyDesktopBridge.ts documents all of it. @comfyorg/comfyui-desktop-bridge-types is regenerated and bumped from 0.17.1 to 0.18.0, and its README lists window.comfyDesktopRuns.

What the website needs

import type {
  ComfyDesktopHostedLocalBridge,
  ComfyDesktopHostedRunsBridge,
  ComfyDesktopLocalBuild
} from '@comfyorg/comfyui-desktop-bridge-types'

window.comfyDesktopRuns?.reportRun({ running: true })
window.comfyDesktopRuns?.reportRun({ running: false })

const builds: ComfyDesktopLocalBuild[] = (await window.comfyDesktopLocal?.localBuilds?.()) ?? []
const stop = window.comfyDesktopLocal?.onLocalBuildsChanged?.((next) => render(next))
  1. Run on menu: mark a build "Busy" when busyWith is set, and keep it pickable. An absent busyWith does not prove the build is free. Update live with onLocalBuildsChanged. Check that both exist first, because older Desktop builds lack them.
  2. Waiting state: after Run on a busy build, while the run has no execution_start and busyWith is set, show "Waiting for {busyWith.title} to finish", or your own "another app" when title is absent. Then show the normal progress.
  3. Run reports: call reportRun at the start and end of every run, the waiting phase included.
  4. All apps link: inside Desktop, the page's own All apps link must not end the run or its report. Today the page clears its run toast when that link is clicked, even though Desktop blocks the navigation and the run goes on in Cloud.

Tests

  • localAppEvents.test.ts: the working run is named before queued ones, and the oldest queued run when none works yet. The asking app is never named. Names clear when runs end. Watchers hear when runs start or end, when a queued run starts working, and when the oldest of 200 runs is dropped.
  • openInComfy.test.ts: busyWith is given, with no name for an app the catalog lacks. It never names the asking app, several asking apps share one look at the builds, and a build shows as free again once its run ends.
  • registerAppsLocalHandlers.test.ts: builds go to every open app page as that page sees them, are not looked up with no page open or with Apps off, and an older answer that arrives late is dropped.
  • appRunWatcher.test.ts (browser): the toast is followed until the page reports runs itself. It is never watched after a report, and anything but running: true counts as no run.
  • Locally, pnpm run typecheck, pnpm run lint, pnpm run format:check, pnpm run bridge-types:check and the full unit suite pass.

Not checked

This PR has no live check. No website page calls reportRun or onLocalBuildsChanged yet. That comes with the website PR.

… its runs

localBuilds now names the app a build is busy with (busyWith), and the
new onLocalBuildsChanged tells app pages when a build becomes busy or
free, for the website's Run on menu. Announcements are numbered, so a
late answer cannot overwrite a newer one.

The new window.comfyDesktopRuns.reportRun({ running }) lets a page say
when a run starts and ends. Once a page calls it, Desktop stops
following the page's run toast for that page.

The bridge types are regenerated and bumped to 0.18.0.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8a66b215-322c-41e9-b4e1-8d924b2a62cb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…sktop cannot see

busyWith now names the app whose run the build is working on, or the
oldest queued run, and never the app that asks, so a page waiting behind
its own run is not told to wait for itself. Each page gets the builds as
it sees them. An app with no catalog name shows as "another app".

The contract now says that busyWith and onLocalBuildsChanged see only runs
from apps in the Apps view, so a build can still be busy with a run from
its ComfyUI window. Build announcements stop once Apps is turned off. The
bridge types are regenerated.
…Desktop lacks

A queued run that starts working now tells the app pages, so busyWith
moves to the run that is actually working. The builds pull uses the same
caller check as the other local calls, and a broadcast looks up the
builds once for all pages.

busyWith.title is now absent when Desktop has no name for the app, so the
page can say "another app" in its own words and language. The bridge
types are regenerated.
@PabloWiedemann
PabloWiedemann marked this pull request as ready for review November 21, 2026 05:13
@PabloWiedemann
PabloWiedemann requested review from a team as code owners November 21, 2026 05:13
@PabloWiedemann
PabloWiedemann removed the request for review from a team November 21, 2026 05:13
@PabloWiedemann
PabloWiedemann requested review from vqt123 and removed request for a team November 21, 2026 05:13
@vqt123

vqt123 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Starting review at ec8f332.

@vqt123

vqt123 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Holding at ec8f332 on 1 Must: waiting status names an app behind your run.

Must

  • Correctness: While a ComfyUI-window workflow runs, queue Remove Background, then Product Swap. Remove Background receives Product Swap as busyWith, although Swap is behind it. The documented waiting UI therefore names the wrong app. src/main/apps/localAppEvents.ts:238. Evidence: the head removes the asking app before selecting the oldest queued run; the base's src/main/apps/openInComfy.ts:73 returned no blocker and could not produce this false attribution. Preserve the asking run's position when choosing a blocker. Read, not run.

Should fix

  • Resilience: Switching apps during a build lookup can deliver the previous app's personalized list into the replacement page. With the excluded app running in another window, this can incorrectly clear Busy. src/main/lib/ipc/registerAppsLocalHandlers.ts:35. Evidence: an idle page is reused during switching, but after the awaited lookup the announcement checks only generation and destruction. Capture and recheck app/document identity, as callerUnchanged already does.

  • Words: Tell integrators to report running: false only when the page has no outstanding runs. The current per-run instructions let the first of two overlapping runs clear protection for the remaining run. src/types/comfyDesktopBridge.ts:347, repeated in packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts:354. Evidence: explicit reports disable toast observation and replace the entire page's boolean running state. Update both declarations to describe aggregate page state.

Clean: Access, Contract, Vendor, Rules, Cause.

Not covered:

  • Browser reporter execution: pnpm exec vitest run --project browser src/preload/appRunWatcher.test.ts. CI Test reports success.
  • Packaged website integration and switching during a lookup: add scenarios invoking both new APIs to e2e/apps-local.test.ts, then pnpm run test:e2e:macos e2e/apps-local.test.ts.

Checked: Read head/base attribution paths and ComfyUI queue ordering; compared announcement delivery with page identity guards; searched bridge readers in companion clones.

~987k effective tokens for this review (4.8M raw; cache reads weighted 0.1x, cache writes 1.25-2x)

busyWith now looks only at the run the build is working on and the runs queued ahead of the asking app's own runs. Before, it left out the asking app and then named the oldest other run, which could be one queued behind it, so the page said it waited for an app that was waiting for it. An app whose own run is working gets no busyWith.

A builds announcement now goes to a page only when it still shows the app and document the lookup was for, the same check callerUnchanged makes, so a page that switched apps during the lookup does not get the old app's list.

The bridge docs now say reportRun describes the whole page: report running false only when no run is left, since each report replaces the page's state.
@PabloWiedemann

Copy link
Copy Markdown
Contributor Author

Thanks. All three are fixed in a5afc84:

  • Must: busyWith now looks only at the working run and the runs queued ahead of the asking app's own runs, so Remove Background no longer gets Product Swap. An app whose own run is working gets none. Two old tests had encoded the wrong answer and are corrected, and new tests cover your sequence.
  • Announce race: each page's list is sent only if the page still shows the app and document it was looked up for, the same check as callerUnchanged. A new test fails without it.
  • Words: reportRun now describes the whole page's state: report running false only when no run is left. The bridge d.ts is regenerated. The website (comfy-website#694) already reports false only when its last run toast goes.

@vqt123

vqt123 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Starting re-review at a5afc84.

@vqt123

vqt123 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed at a5afc84 (since ec8f332): queue attribution, page identity checks and run-report wording updated.

Fixed: the reported sequential-queue case, delivery across an app switch, and aggregate run-report instructions.

Still open: queue attribution needs one ordering fix covering normal submissions, identical timestamps, and concurrent requests accepted in a different order from their sends.

Must

  • Correctness: Concurrent submissions can still tell Product Swap it is waiting for Remove Background when Remove Background is behind it. src/main/apps/localAppEvents.ts:245. Evidence: localComfy.ts:562-570 records time before sending each request and discards ComfyUI's returned queue number. If Remove Background is sent first but Swap receives queue number 10 and Remove Background 11, the head names Remove Background as Swap's blocker. The base's openInComfy.ts:73-81 returns no busyWith and cannot make that false attribution. Equal timestamps also hide an earlier queued app. Preserve ComfyUI's queue number and choose blockers from an ordered list that retains the asking app's position. Cover all three inputs together. Read, not run.

Clean: Resilience, Access, Words.

Not covered:

  • Browser run reporter execution: pnpm exec vitest run --project browser src/preload/appRunWatcher.test.ts.
  • Two-page mixed queues and navigation during a lookup: add those scenarios to e2e/apps-local.test.ts, then pnpm run test:e2e:macos e2e/apps-local.test.ts.

~470k effective tokens for this review (2.2M raw; cache reads weighted 0.1x, cache writes 1.25-2x)

Each run now keeps the queue number ComfyUI returns for it, and busyWith picks the blocker from the build's runs in that order, keeping the asking app's place. Before, runs were ordered by when Desktop sent them, so two requests that ComfyUI accepted in the other order could name an app behind the asking one, and runs sent at the same moment could hide the one ahead. Runs without a number fall back to send order, then the order they were accepted in.
@PabloWiedemann

Copy link
Copy Markdown
Contributor Author

Thanks. Fixed in d6e3fc7: each run keeps the queue number ComfyUI returns, and busyWith picks the blocker from the build's runs in that order, keeping the asking app's place. Runs with no number fall back to send time, then the order they were accepted in. Tests cover the three inputs together: numbers out of send order, runs sent at the same moment, and normal order. A localComfy test also checks that the number reaches the run through a real /prompt answer. Both fail without the fix.

@vqt123

vqt123 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Starting re-review at d6e3fc7.

@vqt123

vqt123 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed at d6e3fc7 (since a5afc84): queue attribution now follows ComfyUI's queue numbers.
Round 3: the root-cause fix closes the earlier queue-ordering hold.

Fixed: normal queue order, identical send times, and requests accepted in a different order from their sends. Desktop retains the returned number at src/main/apps/localComfy.ts:570 and orders blockers at src/main/apps/localAppEvents.ts:249. The page-switch guard and whole-page run-report instructions remain fixed. Read, not run.

Still open: none.

Clean: Correctness, Resilience, Access.

Not covered:

  • Browser run-reporter behavior: pnpm exec vitest run --project browser src/preload/appRunWatcher.test.ts.
  • Website integration with two app pages: add mixed-queue and navigation scenarios to e2e/apps-local.test.ts, then pnpm run test:e2e:macos e2e/apps-local.test.ts.

Checked: Read the head/main queue paths and ComfyUI's queue implementation.

~359k effective tokens for this review (1.5M raw; cache reads weighted 0.1x, cache writes 1.25-2x)

This branch has not been deployed

No deployments
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.

2 participants