Skip to content

fix: verify and announce dev-server reuse in make electron-dev#558

Open
Davidnet wants to merge 1 commit into
mainfrom
fix/electron-dev-server-guard
Open

fix: verify and announce dev-server reuse in make electron-dev#558
Davidnet wants to merge 1 commit into
mainfrom
fix/electron-dev-server-guard

Conversation

@Davidnet

Copy link
Copy Markdown
Member

Summary

make electron-dev reused any server answering on :3000, treating a bare HTTP 200 as proof the right server was running. A stale webpack dev server from a deleted git worktree kept serving its last in-memory bundle, so the target silently adopted it and Electron loaded from a zombie whose node_modules were gone — surfacing confusing html-webpack-plugin loader errors with no hint of where they came from.

This moves the orchestration out of the Makefile into src/scripts/electron-dev.js, which supervises both the dev server and Electron in one process:

  • Identifies the process on :3000 via lsof and compares its cwd to this worktree's src/frontend:
    • cwd matches → reuse, announcing pid + cwd
    • cwd differs → refuse with the offending pid/cwd and guidance
    • cwd unverifiable → reuse with a warning
    • FORCE_RESTART=1 → kill the holder, wait for the port, start fresh
  • Only tears down a dev server it spawned (a reused one is left running), killing the process group so webpack dies with it.

Keeping the logic in Node makes the four-way policy readable and unit-testable (classifyHolder) instead of a backslash-continued shell block. Reuse stays the default; killing is opt-in.

The Makefile electron-dev target collapses to @node src/scripts/electron-dev.js.

Follow-up: these scripts aren't in the lint path yet (#557).

electron-dev reused any server answering on :3000, treating a bare HTTP
200 as proof the right server was running. A stale webpack dev server
from a deleted git worktree kept serving its last in-memory bundle, so
the target silently adopted it and Electron loaded from a zombie whose
node_modules were gone — surfacing confusing html-webpack-plugin loader
errors with no hint of where they came from.

Move the orchestration out of the Makefile into src/scripts/electron-dev.js,
which supervises both the dev server and Electron in one process:

- identify the process on :3000 via lsof and compare its cwd to this
  worktree's src/frontend
    cwd matches      -> reuse, announcing pid + cwd
    cwd differs      -> refuse with the offending pid/cwd and guidance
    cwd unverifiable -> reuse with a warning
    FORCE_RESTART=1  -> kill the holder, wait for the port, start fresh
- only tear down a dev server it spawned (a reused one is left running),
  killing the process group so webpack dies with it

Keeping the logic in Node makes the four-way policy readable and unit-
testable (classifyHolder) instead of a backslash-continued shell block.
Reuse stays the default; killing is opt-in.
Copilot AI review requested due to automatic review settings June 26, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

3 participants