Skip to content

fix(dev): clean teardown of all bun dev child processes#3982

Merged
Kitenite merged 6 commits intomainfrom
bun-dev-server-cleanup
May 2, 2026
Merged

fix(dev): clean teardown of all bun dev child processes#3982
Kitenite merged 6 commits intomainfrom
bun-dev-server-cleanup

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented May 2, 2026

Summary

After Ctrl-C'ing bun run dev, three categories of child processes were leaking and surviving as orphans (PPID=1):

  • next dev (api, web) and wrangler dev (electric-proxy) — sh -c '<cmd>' doesn't exec the real binary, so on subtask SIGTERM the shell exits without forwarding the signal and the dev server is left bound to its port.
  • host-service (apps/desktop/src/main/lib/host-service-coordinator.ts) — spawned detached: true + child.unref() unconditionally; on bun dev kill no stopAll() runs, so it reparents to init.
  • terminal-host daemon (apps/desktop/src/main/lib/terminal-host/client.ts) — same pattern, same outcome. Used by both v1 and v2 codepaths (settings, tasks OpenInWorkspace/RunInWorkspacePopover, agent hooks).

Changes

  • apps/{api,web,electric-proxy}/package.json — prepend exec inside the sh -c so signals land on next/wrangler directly.
  • apps/desktop/src/main/lib/host-service-coordinator.tsdetached: !isDev + if (!isDev) child.unref(), gated on !app.isPackaged.
  • apps/desktop/src/main/lib/terminal-host/client.ts — same shape.
  • plans/20260502-bun-dev-server-cleanup.md — audit + verification notes.

Prod safety

All changes are dev-only by construction:

  • exec only edits "dev" scripts; prod uses next start / wrangler deploy.
  • detached flips for both daemons are gated on !app.isPackaged. Packaged production builds keep detached: true + unref() exactly as before, preserving manifest-based adoption and PTY survival across Electron restarts (apps/desktop/HOST_SERVICE_LIFECYCLE.md).

Verification

bun run dev > /tmp/bundev.log 2>&1 &
# wait for ports 4980/4981/4993 to listen, +45s to let Electron mount and lazy-spawn host-service/terminal-host
kill -INT -<PGID>

Result within 1s of SIGINT — completely clean:

  • ports 4980 (web), 4981 (api), 4985 (vite), 4990 (caddy), 4992 (electron remote-debug), 4993 (workerd) — all released
  • processes (turbo, electron-vite, Electron, host-service ×2, terminal-host, next dev ×2, wrangler, workerd, caddy, dotenv shells) — all gone
  • no orphaned PPID=1 processes from this worktree

For comparison, sibling worktrees on older code in the same ps snapshot still had host-service.js, terminal-host.js, pty-daemon.js reparented to init — the exact leak this PR fixes.

apps/desktop typecheck clean.

Test plan

  • Reviewer: bun run dev, sign in to an org, open a v2 workspace + spawn a terminal, then Ctrl-C and confirm pgrep -lf 'host-service|terminal-host|pty-daemon|next dev|wrangler|caddy' is empty for your worktree.
  • Verify packaged build (release-desktop canary) still adopts a previously-running host-service on launch (manifest-based adoption unchanged).

Summary by cubic

Fixes leaking dev processes so stopping bun run dev or quitting Electron in dev cleanly shuts down all child servers and daemons, freeing ports with no orphans. Production behavior is unchanged.

  • Bug Fixes

    • apps/{api,web,electric-proxy,admin,docs,marketing} and packages/cli: added exec inside sh -c for next dev/wrangler dev/cli-framework dev so signals reach the real process.
    • apps/desktop: spawn host-service and terminal-host with detached: !isDev and only unref() in production so they exit with Electron in dev.
    • packages/host-service: DaemonSupervisor now spawns the PTY daemon with detached: !isDev and only unref() in production, providing defense-in-depth for crash cases.
    • apps/desktop/src/main/index.ts: dev quit/SIGTERM/parent-exit runs cleanup to stop host-service, shut down terminal-host (kills sessions), dispose the client, then exit; adds a re-entry guard to avoid double handling.
  • Refactors

    • Trimmed spawn-site comments across the coordinator, terminal-host client, and PTY supervisor to clarify prod vs. dev behavior.
    • plans/20260502-bun-dev-server-cleanup.md: tightened to reflect shipped state.

Written for commit 6d2de88. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Dev servers and helper processes now terminate reliably on quit by keeping spawned processes attached in development and detached in production, and by launching dev servers via the shell so they replace the shell process for proper shutdown and port cleanup.
  • Documentation
    • Added a verification-backed plan describing dev-server shutdown issues, root causes, and fixes.

Three sources of zombie procs after Ctrl-C / kill:

- next/wrangler orphaned by `sh -c '<cmd>'` not exec-ing into the real
  binary; sh exits on subtask SIGTERM and leaves them bound to ports.
- host-service spawned `detached: true` + `unref()` even in dev, so it
  reparents to init when Electron dies.
- terminal-host daemon does the same.

Fix:
- prepend `exec ` in api/web/electric-proxy `sh -c` dev scripts.
- gate `detached`/`unref` on `!app.isPackaged` for both host-service
  and terminal-host. Packaged production builds keep detach + manifest
  adoption (PTYs survive Electron restart) — only dev changes.

Verified: `bun run dev` → SIGINT → 1s later all ports released and all
spawned processes (turbo, electron-vite, Electron, host-service ×2,
terminal-host, next/wrangler/caddy) are gone.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Dev npm scripts now run under sh -c 'exec ...' loading ../../.env; Electron-spawned background processes (host-service, pty daemon) are detached/unref'd only in production; Electron dev quit/signal paths now run a coordinated dev-only cleanup. A new plan documents causes and verification steps.

Changes

Dev Process Cleanup

Layer / File(s) Summary
Documentation / Audit
plans/20260502-bun-dev-server-cleanup.md
Adds an audit describing orphaned dev processes, lists root causes (missing exec, unconditional detached/unref, Electron dev shutdown paths), and defines verification steps.
Shell exec wrapper — Next / Wrangler / Others
apps/api/package.json, apps/web/package.json, apps/admin/package.json, apps/docs/package.json, apps/marketing/package.json, apps/electric-proxy/package.json
dev scripts updated to invoke commands via sh -c 'exec ...' while sourcing ../../.env (e.g., exec next dev --port ${API_PORT:-3001}, exec wrangler dev --port ${WRANGLER_PORT:-8787}).
Shell exec wrapper — CLI env handling
packages/cli/package.json
dev script updated to sh -c 'exec env SUPERSET_API_URL=$NEXT_PUBLIC_API_URL cli-framework dev "$@"' --, ensuring exec and explicit env invocation inside the shell wrapper.
Process Lifecycle — host-service coordinator
apps/desktop/src/main/lib/host-service-coordinator.ts
Spawn options changed from unconditional detached: true to detached: !isDev; child.unref() is now conditional (if (!isDev) child.unref()), so dev child processes remain attached.
Process Lifecycle — daemon supervisor
packages/host-service/src/daemon/DaemonSupervisor.ts
DaemonSupervisor.spawn() now uses detached: !isDev and only calls child.unref() in non-dev, aligning daemon lifetime with dev vs production.
Process Lifecycle — terminal-host / pty daemon
apps/desktop/src/main/lib/terminal-host/client.ts
Introduces isDev = !app.isPackaged; daemon spawn uses detached: !isDev and child.unref() only in production, mirroring host-service behavior.
App shutdown wiring (dev-specific cleanup)
apps/desktop/src/main/index.ts
before-quit and termination handlers now run runDevQuitCleanup() in development to stop host services, attempt terminal-host shutdown (with session kill), and dispose terminal-host client; production path retains prior release behavior.

Sequence Diagram

sequenceDiagram
  participant Shell as Dev Shell
  participant DevRunner as Bun/Turbo Dev
  participant Electron as Electron (main)
  participant Host as Host-service / PTY daemon
  Shell->>DevRunner: start dev scripts (`sh -c 'exec ...'`)
  DevRunner->>Electron: start desktop dev
  Electron->>Host: spawn child (detached: !isDev)
  alt Development
    Host-->>Electron: child attached (dies with Electron)
    Electron->>Electron: runDevQuitCleanup() on quit/signals
    Electron->>Host: stop child (kill sessions) and dispose client
  else Production
    Host-->>Electron: child detached + unref (survives)
    Electron->>Host: releaseAll() on quit
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Poem

🐰 I taught the shells to use "exec" and bound the thread,
so dev-time daemons follow when the main hops to bed.
In packing they wander; in sandbox they stay—
ports clear, burrows quiet, I twitch my nose and play.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'fix(dev): clean teardown of all bun dev child processes' directly and concisely describes the main objective of eliminating child-process leakage during bun dev shutdown.
Description check ✅ Passed The PR description comprehensively covers all required template sections: clear summary of the bug and fix, related issues context, type of change (bug fix), detailed testing instructions with manual verification steps, and additional implementation notes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bun-dev-server-cleanup

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
Review rate limit: 2/8 reviews remaining, refill in 42 minutes and 32 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 2, 2026

Greptile Summary

This PR fixes three categories of orphaned child processes left behind after killing bun run dev: shell wrappers that don't forward signals (sh -c without exec), and two Electron-spawned daemons (host-service, terminal-host) that were unconditionally detached and unref'd even in dev mode. The fixes are tightly scoped — exec only touches "dev" npm scripts, and the detached/unref changes are gated on !app.isPackaged so production manifest-based adoption is preserved exactly as before.

The audit notes that live end-to-end verification of the host-service and terminal-host code paths (requiring a logged-in org and an active terminal session) was not performed in the headless test run — the test plan reviewer checklist covers this gap.

Confidence Score: 4/5

Safe to merge — all changes are dev-only by construction and production paths are structurally unchanged.

Only P2 findings (stale comment). The core logic is sound: exec in shell scripts is a well-known POSIX pattern, and gating detach/unref on !app.isPackaged is the standard Electron sentinel. One small caveat: the host-service and terminal-host code paths weren't live-tested in the headless verification run, so the reviewer's manual test plan item remains important.

apps/desktop/src/main/lib/host-service-coordinator.ts and apps/desktop/src/main/lib/terminal-host/client.ts — both need live verification with a logged-in org and active terminal session per the test plan.

Important Files Changed

Filename Overview
apps/api/package.json Prepends exec to the sh -c dev script so SIGTERM lands on next directly instead of the shell wrapper; prod script unchanged.
apps/web/package.json Same exec fix as api/package.json for the Next.js web dev server.
apps/electric-proxy/package.json Prepends exec to the wrangler dev script; deploy script unchanged.
apps/desktop/src/main/lib/host-service-coordinator.ts Gates detached+unref on !app.isPackaged; dev spawns are now attached so Electron exit propagates SIGTERM. Minor stale comment on windowsHide.
apps/desktop/src/main/lib/terminal-host/client.ts Same detached/unref gating as host-service-coordinator, correctly using !app.isPackaged; production PTY-survival path untouched.
plans/20260502-bun-dev-server-cleanup.md Thorough audit doc; explicitly notes host-service and terminal-host were not live-exercised in the headless verification run (no logged-in org, no UI terminal).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["bun run dev (SIGINT)"] --> B[turbo sends SIGTERM to subtasks]
    B --> C["api/web/electric-proxy\ndotenv -- sh -c '...'"]
    C -->|"OLD: sh exits, next/wrangler orphaned"| D1["❌ next/wrangler still bound to port"]
    C -->|"NEW: exec replaces sh\nsignal lands on next/wrangler"| D2["✅ next/wrangler exits cleanly"]
    B --> E[electron-vite → Electron main]
    E -->|"OLD: detached:true + unref()"| F1["❌ host-service orphaned (PPID=1)"]
    E -->|"NEW: detached:false in dev\n(!app.isPackaged)"| F2["✅ host-service dies with Electron"]
    F2 --> G2["✅ pty-daemon cascades via serve.ts handler"]
    E -->|"OLD: detached:true + unref()"| H1["❌ terminal-host orphaned (PPID=1)"]
    E -->|"NEW: detached:false in dev\n(!app.isPackaged)"| H2["✅ terminal-host dies with Electron"]
    subgraph PROD ["Production (app.isPackaged = true)"]
        P1["detached:true + unref() — unchanged\nManifest-based adoption preserved"]
    end
Loading

Comments Outside Diff (1)

  1. apps/desktop/src/main/lib/host-service-coordinator.ts, line 436-437 (link)

    P2 Stale comment after detach flag change

    The inline comment "Avoid a flashing CMD window on Windows for the detached child" still says "detached child", but in dev mode the child is now spawned with detached: false. The option itself is harmless regardless of detach state, but the comment is now misleading.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/desktop/src/main/lib/host-service-coordinator.ts
    Line: 436-437
    
    Comment:
    **Stale comment after detach flag change**
    
    The inline comment `"Avoid a flashing CMD window on Windows for the detached child"` still says "detached child", but in dev mode the child is now spawned with `detached: false`. The option itself is harmless regardless of detach state, but the comment is now misleading.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/desktop/src/main/lib/host-service-coordinator.ts:436-437
**Stale comment after detach flag change**

The inline comment `"Avoid a flashing CMD window on Windows for the detached child"` still says "detached child", but in dev mode the child is now spawned with `detached: false`. The option itself is harmless regardless of detach state, but the comment is now misleading.

```suggestion
			// Avoid a flashing CMD window on Windows.
			windowsHide: true,
```

Reviews (1): Last reviewed commit: "fix(dev): clean teardown of all bun dev ..." | Re-trigger Greptile

Per Greptile review on #3982 — `detached` is now gated on `!app.isPackaged`,
so referring to "the detached child" is misleading. `windowsHide` applies
either way.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 2, 2026

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) View Branch
Vercel API (Vercel) Open Preview
Vercel Web (Vercel) Open Preview
Vercel Marketing (Vercel) Open Preview
Vercel Admin (Vercel) Open Preview
Vercel Docs (Vercel) Open Preview

Preview updates automatically with new commits

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/desktop/src/main/lib/host-service-coordinator.ts (1)

428-477: ⚠️ Potential issue | 🟠 Major

App-quit path needs stopAll() and terminal-host disposal for dev children.

The before-quit handler calls releaseAll() unconditionally, but releaseAll() only stops liveness checks and clears the instance map—it does not kill processes. In dev, host-service children are spawned non-detached (detached: !isDev) and remain ref'd (child.unref() only in production), so they will hang on app exit waiting for an explicit SIGTERM. Similarly, the terminal-host client spawns with the same lifecycle pattern and lacks disposal in the before-quit path. The app-quit flow should call stopAll() instead of releaseAll() for dev, and add explicit terminal-host cleanup, to ensure attached dev children are terminated during normal quit.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/main/lib/host-service-coordinator.ts` around lines 428 -
477, The app quit handler currently calls releaseAll(), which only stops
liveness checks and leaves non-detached dev child processes alive; change the
before-quit flow in HostServiceCoordinator to call stopAll() instead of
releaseAll() when isDev so attached dev children are terminated, and also ensure
any terminal-host client is explicitly cleaned up (e.g., call
terminalHost.dispose() or terminalHost.stop() / terminalHostClient.close()
depending on the terminal-host API) in that same quit path; reference the
existing methods releaseAll(), stopAll(), and the terminal-host
instance/variable used by the coordinator to locate where to make the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/desktop/src/main/lib/host-service-coordinator.ts`:
- Around line 428-477: The app quit handler currently calls releaseAll(), which
only stops liveness checks and leaves non-detached dev child processes alive;
change the before-quit flow in HostServiceCoordinator to call stopAll() instead
of releaseAll() when isDev so attached dev children are terminated, and also
ensure any terminal-host client is explicitly cleaned up (e.g., call
terminalHost.dispose() or terminalHost.stop() / terminalHostClient.close()
depending on the terminal-host API) in that same quit path; reference the
existing methods releaseAll(), stopAll(), and the terminal-host
instance/variable used by the coordinator to locate where to make the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0827a418-8ae1-4f05-82d5-f4f834db4f06

📥 Commits

Reviewing files that changed from the base of the PR and between f7db05c and 96cd89e.

📒 Files selected for processing (6)
  • apps/api/package.json
  • apps/desktop/src/main/lib/host-service-coordinator.ts
  • apps/desktop/src/main/lib/terminal-host/client.ts
  • apps/electric-proxy/package.json
  • apps/web/package.json
  • plans/20260502-bun-dev-server-cleanup.md

Audit found four more `sh -c '<cmd>'` dev scripts missing `exec` (admin,
docs, marketing, packages/cli — all reachable via `bun dev:all` /
`bun dev:docs` / `bun dev:marketing`), and one defense-in-depth gap in
the pty-daemon supervisor.

- apps/{admin,docs,marketing}/package.json — add `exec ` inside `sh -c`.
- packages/cli/package.json — same; uses `exec env VAR=… cli-framework
  dev "$@"` to preserve the inline env var assignment.
- packages/host-service/src/daemon/DaemonSupervisor.ts — gate
  `detached`/`unref` on `isDev` (NODE_ENV-derived). The serve.ts dev
  shutdown handler already calls `supervisor.stop()` on the happy path;
  this protects against host-service crashes that bypass that handler.
Per CodeRabbit on #3982: with `detached: !isDev` + `if (!isDev) child.unref()`,
dev children are now attached & ref'd, so the existing `releaseAll()` /
`app.exit(0)` paths in main/index.ts left them as init-orphans on graceful
quit (Cmd+Q) and on the dev SIGTERM/SIGINT handler.

- before-quit: in dev, call `coordinator.stopAll()` and dispose terminal-host
  via `shutdownIfRunning({ killSessions: true })` + `disposeTerminalHostClient`.
  Production keeps `releaseAll()` (manifest adoption is the survival contract).
- handleTerminationSignal + parent-pid fallback: run the same dev cleanup
  before `app.exit(0)`, with a re-entry guard.

Verified: SIGTERM to Electron-only (simulating Cmd+Q) takes down host-service
×2 and terminal-host while leaving the rest of `bun dev` intact. Full
`bun dev` Ctrl-C still produces zero residual processes.
Remove call-site comments that restated what the function name + docstring
already say; trim the spawn-site comments to a two-line prod/dev summary
each. The unref() lines are obvious from the surrounding `!isDev` branch.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/desktop/src/main/index.ts (1)

190-232: ⚠️ Potential issue | 🟠 Major

Prevent quit before async cleanup completes.

The before-quit handler performs awaited cleanup, but event.preventDefault() is only called conditionally inside the dialog block. In Electron, async event handlers are not awaited by default—the app will proceed with the quit process immediately after the handler returns, causing cleanup operations to race with process exit. Move event.preventDefault() to the top of the handler (after the isQuitting guard) to ensure the quit flow is blocked until all cleanup completes.

Proposed fix
 app.on("before-quit", async (event) => {
 	if (isQuitting) return;
+	event.preventDefault();

 	const isDev = process.env.NODE_ENV === "development";
 	if (!skipQuitConfirmation && !isDev && getConfirmOnQuitSetting()) {
-		event.preventDefault();
-
 		try {
 			const { response } = await dialog.showMessageBox({
 				type: "question",
 				buttons: ["Quit", "Cancel"],
 				defaultId: 0,
 				cancelId: 1,
 				title: "Quit Superset",
 				message: "Are you sure you want to quit?",
 			});

 			if (response === 1) {
 				return;
 			}
 		} catch (error) {
 			console.error("[main] Quit confirmation dialog failed:", error);
 		}
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/main/index.ts` around lines 190 - 232, The before-quit
handler may return before async cleanup finishes because event.preventDefault()
is only called inside the dialog branch; move event.preventDefault() to
immediately after the isQuitting guard in the app.on("before-quit") handler so
the quit is always blocked until cleanup completes, then conditionally show the
dialog (using skipQuitConfirmation and getConfirmOnQuitSetting()) and perform
awaited cleanup via runDevQuitCleanup() or
getHostServiceCoordinator().releaseAll(), followed by
shutdownTanstackDbPersistence() and disposeTray(), and finally call app.exit(0)
once those awaits complete.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/desktop/src/main/index.ts`:
- Around line 190-232: The before-quit handler may return before async cleanup
finishes because event.preventDefault() is only called inside the dialog branch;
move event.preventDefault() to immediately after the isQuitting guard in the
app.on("before-quit") handler so the quit is always blocked until cleanup
completes, then conditionally show the dialog (using skipQuitConfirmation and
getConfirmOnQuitSetting()) and perform awaited cleanup via runDevQuitCleanup()
or getHostServiceCoordinator().releaseAll(), followed by
shutdownTanstackDbPersistence() and disposeTray(), and finally call app.exit(0)
once those awaits complete.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ddebed56-9896-4468-b2ae-156b8593f54c

📥 Commits

Reviewing files that changed from the base of the PR and between d16eacc and cdb3011.

📒 Files selected for processing (1)
  • apps/desktop/src/main/index.ts

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/desktop/src/main/lib/host-service-coordinator.ts (1)

406-409: ⚡ Quick win

Update stale lifecycle comment to match new dev behavior.

Line 406 says host-service “must survive Electron restarts in every environment,” but Line 431 now intentionally keeps it attached in dev. Please align the comment with the new dev/prod split to avoid future confusion.

Suggested comment-only diff
-		// Host-service owns v2 PTYs, so it must survive Electron restarts in
-		// every environment. This mirrors the terminal-host daemon: detach the
-		// child and back stdio with real files so parent teardown cannot close
-		// pipes and take the service down with the app.
+		// Host-service owns v2 PTYs. In production we detach so it survives
+		// Electron restarts; in dev we keep it attached so `bun dev` shutdown
+		// can terminate it cleanly.

Also applies to: 427-431

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/main/lib/host-service-coordinator.ts` around lines 406 -
409, Update the stale lifecycle comment that currently states "host-service owns
v2 PTYs, so it must survive Electron restarts in every environment" to reflect
the new dev/prod split: note that in production the host-service is detached and
stdio is backed by files so it survives Electron restarts, whereas in
development it is intentionally kept attached to aid debugging. Edit the comment
near the "host-service owns v2 PTYs" block and the subsequent lines that discuss
detaching/backing stdio (the same comment region referenced around the
host-service lifecycle handling) to clearly document the differing behavior in
dev vs prod.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/desktop/src/main/lib/host-service-coordinator.ts`:
- Around line 406-409: Update the stale lifecycle comment that currently states
"host-service owns v2 PTYs, so it must survive Electron restarts in every
environment" to reflect the new dev/prod split: note that in production the
host-service is detached and stdio is backed by files so it survives Electron
restarts, whereas in development it is intentionally kept attached to aid
debugging. Edit the comment near the "host-service owns v2 PTYs" block and the
subsequent lines that discuss detaching/backing stdio (the same comment region
referenced around the host-service lifecycle handling) to clearly document the
differing behavior in dev vs prod.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8fba029f-5fd6-4792-9a25-8cc5e97aa9c0

📥 Commits

Reviewing files that changed from the base of the PR and between cdb3011 and 6d2de88.

📒 Files selected for processing (5)
  • apps/desktop/src/main/index.ts
  • apps/desktop/src/main/lib/host-service-coordinator.ts
  • apps/desktop/src/main/lib/terminal-host/client.ts
  • packages/host-service/src/daemon/DaemonSupervisor.ts
  • plans/20260502-bun-dev-server-cleanup.md
✅ Files skipped from review due to trivial changes (1)
  • packages/host-service/src/daemon/DaemonSupervisor.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/desktop/src/main/lib/terminal-host/client.ts
  • apps/desktop/src/main/index.ts

@Kitenite Kitenite merged commit 3925159 into main May 2, 2026
14 checks passed
@Kitenite Kitenite deleted the bun-dev-server-cleanup branch May 2, 2026 17:46
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.

1 participant