-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: allow multiple apps to run concurrently with garbage collection #2825
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. 🔴 Singleton proxyWorker is terminated when a second app starts, breaking the first app's preview With the new concurrent app model, multiple apps can run simultaneously. However, Root cause and impactThe proxy worker forwards requests from the preview iframe to each app's local dev server. It is started per-app in proxyWorker = await startProxy(urlMatch[1], { ... });But if (proxyWorker) {
proxyWorker.terminate();
proxyWorker = null;
}Previously this was fine because only one app ran at a time. Now with concurrent apps, this terminates App A's proxy when App B starts, making App A's preview unreachable. The Impact: The core feature of this PR (keeping multiple apps running) is undermined — only the most recently started app will have a working preview. (Refers to lines 177-179) Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,9 @@ import { | |
| removeAppIfCurrentProcess, | ||
| stopAppByInfo, | ||
| removeDockerVolumesForApp, | ||
| setCurrentlySelectedAppId, | ||
| updateAppLastViewed, | ||
| startAppGarbageCollection, | ||
| } from "../utils/process_manager"; | ||
| import { getEnvVar } from "../utils/read_env"; | ||
| import { readSettings } from "../../main/settings"; | ||
|
|
@@ -272,6 +275,7 @@ Details: ${details || "n/a"} | |
| process: spawnedProcess, | ||
| processId: currentProcessId, | ||
| isDocker: false, | ||
| lastViewedAt: Date.now(), | ||
| }); | ||
|
|
||
| listenToProcess({ | ||
|
|
@@ -344,6 +348,12 @@ function listenToProcess({ | |
| if (urlMatch) { | ||
| proxyWorker = await startProxy(urlMatch[1], { | ||
| onStarted: (proxyUrl) => { | ||
| // Store proxy URL in running app info for re-emission on app switch | ||
| const appInfo = runningApps.get(appId); | ||
| if (appInfo) { | ||
| appInfo.proxyUrl = proxyUrl; | ||
| appInfo.originalUrl = urlMatch[1]; | ||
| } | ||
| safeSend(event.sender, "app:output", { | ||
| type: "stdout", | ||
| message: `[dyad-proxy-server]started=[${proxyUrl}] original=[${urlMatch[1]}]`, | ||
|
|
@@ -577,6 +587,7 @@ ${errorOutput || "(empty)"}`, | |
| processId: currentProcessId, | ||
| isDocker: true, | ||
| containerName, | ||
| lastViewedAt: Date.now(), | ||
| }); | ||
|
|
||
| listenToProcess({ | ||
|
|
@@ -1007,6 +1018,15 @@ export function registerAppHandlers() { | |
| // Check if app is already running | ||
| if (runningApps.has(appId)) { | ||
| logger.debug(`App ${appId} is already running.`); | ||
| // Re-emit the proxy URL so the frontend can restore the preview | ||
| const appInfo = runningApps.get(appId); | ||
| if (appInfo?.proxyUrl && appInfo?.originalUrl) { | ||
|
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. P1: Re-emitting a cached proxy URL for already-running apps can emit stale/dead URLs after another app start terminates the previous global proxy worker. Prompt for AI agents |
||
| safeSend(event.sender, "app:output", { | ||
| type: "stdout", | ||
| message: `[dyad-proxy-server]started=[${appInfo.proxyUrl}] original=[${appInfo.originalUrl}]`, | ||
| appId, | ||
|
Comment on lines
+1023
to
+1027
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.
This branch re-emits a cached proxy URL for already-running apps, but after enabling concurrent app processes that URL can be stale: Useful? React with 👍 / 👎. |
||
| }); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -2004,6 +2024,30 @@ export function registerAppHandlers() { | |
| } | ||
| }); | ||
| }); | ||
|
|
||
| // Handler for selecting an app for preview (updates lastViewedAt to prevent GC) | ||
| createTypedHandler(appContracts.selectAppForPreview, async (_, params) => { | ||
| const { appId } = params; | ||
| if (appId !== null) { | ||
| logger.debug(`App ${appId} selected for preview`); | ||
| setCurrentlySelectedAppId(appId); | ||
| // Also update lastViewedAt if the app is running | ||
| updateAppLastViewed(appId); | ||
| } else { | ||
| logger.debug("No app selected for preview"); | ||
| setCurrentlySelectedAppId(null); | ||
| } | ||
| }); | ||
|
|
||
| // Handler for getting list of running apps | ||
| createTypedHandler(appContracts.getRunningApps, async () => { | ||
| const appIds = Array.from(runningApps.keys()); | ||
| logger.debug(`Getting running apps: ${appIds.join(", ") || "none"}`); | ||
| return { appIds }; | ||
| }); | ||
|
|
||
| // Start the garbage collection for idle apps | ||
| startAppGarbageCollection(); | ||
| } | ||
|
|
||
| function getCommand({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.