Skip to content

fix(main): under npm run dev, change-home and reset exit cleanly instead of relaunching into a blank window - #513

Open
gpechieu wants to merge 2 commits into
chaitanyagiri:mainfrom
gpechieu:fix/dev-relaunch-exit
Open

gpechieu wants to merge 2 commits into
chaitanyagiri:mainfrom
gpechieu:fix/dev-relaunch-exit

Conversation

@gpechieu

@gpechieu gpechieu commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

What & why

changeHome (Settings → change harness home, also the onboarding "create a hive" path) and resetAll both end in app.relaunch() + app.exit(0). Packaged, that is the clean re-bind. Under npm run dev the renderer is served by electron-vite's dev server, which lives in the wrapper process that watches this Electron and exits with it — so the relaunched Electron started against a dead dev server and came up with a blank window that the developer had to hunt down and kill before running npm run dev again. It happens on every hive create/switch in dev.

relaunch.ts decides the plan: 'exit' when ELECTRON_RENDERER_URL is set (electron-vite's dev marker, the one the window loader already keys on), 'relaunch' otherwise. index.ts has one relaunchOrExit(reason) that both handlers go through; in dev it prints a console line saying why and what to run, and exits cleanly. Packaged behaviour is unchanged.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs
  • Build / CI

Evidence

Before

before

On main both handlers call app.relaunch() unconditionally; the sequence that ends in the blank window is spelled out in the capture, and the new test has nothing to load.

After

after

With the fix: the plan is exit under ELECTRON_RENDERER_URL, the console line names the trigger and says to run npm run dev again, and the text pin confirms both handlers use the helper and app.relaunch() appears only inside it.

How I tested it

  • OS: macOS 15 (Darwin 25.6), Node 22, branch cut from main @ 417d8de
  • Steps:
    • node --test test/dev-relaunch-exit.test.cjs → fails on main (no relaunch.ts, no helper), 3/3 pass with the fix.
    • ELECTRON_RENDERER_URL=http://localhost:5173 node -e '…relaunchPlan()…' prints exit and the notice (in the After capture).
    • npm run typecheck clean; npm run test:focused 837/837.

Credit (optional)

Discord:

X:

Checklist

  • Before and after evidence is attached above, under both headings.
  • npm run typecheck passes.
  • npm run test:focused passes.
  • npm run build succeeds.
  • This PR is one change. Unrelated fixes belong in their own PR.
  • I read the diff myself before opening this, and there is no debug output, commented-out code, or unrelated formatting churn in it.
  • Any new UI derives from DESIGN.md / tokens.ts — no ad-hoc colors, spacing, or fonts. (no UI)
  • If I added art, it's my own or compatibly licensed, and listed in ATTRIBUTION.md. (no art)

🤖 Generated with Claude Code

…ead of relaunching into a blank window

Both IPC handlers ended in app.relaunch() + app.exit(0). Packaged, that is
the clean re-bind. Under `npm run dev` the renderer is served by
electron-vite's dev server, which lives in the wrapper that watches this
Electron and exits with it — so the relaunched Electron started against a
dead dev server and came up with a BLANK window the developer had to hunt
down and kill before running `npm run dev` again (every hive create/switch
in dev).

- relaunch.ts: relaunchPlan(env) → 'exit' when ELECTRON_RENDERER_URL is set
  (electron-vite's dev marker, the one the window loader already keys on),
  'relaunch' otherwise; devExitNotice(reason) is the console line that
  replaces the blank window.
- index.ts: relaunchOrExit(reason) is the single place that relaunches;
  changeHome and reset go through it. Packaged behaviour is unchanged.

Test: the plan for packaged / empty marker / dev; the notice; and a text pin
that both handlers use the helper and app.relaunch() appears only inside it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
gpechieu added a commit to gpechieu/munder-difflin that referenced this pull request Sep 14, 2026
…esign, OpenWolf transient), PRs chaitanyagiri#512 aviso a remitente con destinatario archivado y chaitanyagiri#513 exit en dev, 6 fixes integrados (891/891), boot real 11:50 OK - Agente Claude-IMPLEMENTADOR - TESTED

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmYD63qADnKFKjpU1Ar3TF
Self-review (CONTRIBUTING: run your agent over your PR). stderr is asynchronous on pipes and on Windows TTYs, and app.exit() does not wait for it, so the console line that replaces the blank window could be lost. It is now written with a callback that exits once it is out. Packaged branch unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@gpechieu

Copy link
Copy Markdown
Contributor Author

Agent review of this PR (CONTRIBUTING: "run your coding agent over your own PR, and paste what it found"). Claude Code went over 417d8dec..9307e75f for cross-platform behaviour, paths with spaces, provider neutrality, hot paths and security, then hygiene.

  • Cross-platform: clean — it verified in the installed electron-vite 5 that the wrapper sets ELECTRON_RENDERER_URL before spawning Electron with an inherited env (all OSes) and exits on the child's close, so nothing of it remains on Windows; the window loader already keys on the same variable, so dev would be broken anyway if it were unset. Packaged: the variable is undefined, so the plan is relaunch, identical to before this PR. One thing it flagged, fixed in 90bf29f: console.warn followed by an immediate app.exit(0) — stderr is asynchronous on pipes and on Windows TTYs, so the notice could be lost. It is now written with a callback that exits once it is out.
  • Paths with spaces / provider neutrality / hot paths: n/a — no paths handled (the URL is host:port), no provider logic, runs once just before exit.
  • Security: clean — env read only; no renderer-controlled input reaches relaunchPlan; no new IPC or fs.
  • Hygiene: clean — no leftover debug output, no commented code, no reformatting of untouched lines; the renderer callers (HivePicker, SettingsModal) already treat ok as "never resolves" and die with the process; the one-shot skipHivePickerOnce flag is consumed by the next npm run dev, which is the intended landing.
  • Flagged and deliberately not changed: the renderer comments still say "relaunches" (true when packaged); changeHome / reset skipping telemetry.stop / stopAllProxyBridges etc. vs teardownAndQuit is pre-existing on both branches and out of this PR's scope.

Verified after the fix: typecheck clean, the test file 3/3, local suite 837/837.

@gpechieu

Copy link
Copy Markdown
Contributor Author

Housekeeping, no code change: I force-pushed this branch to reword the commit messages (an internal session trailer was dropped; Co-Authored-By stays) and replaced the evidence images with plain test-runner output, since the previous captures included local session data that should not have been published. The diff is byte-identical to what was reviewed (git diff between the old and new heads over src/test is empty); the review comments above cite the previous hashes. Sorry for the noise.

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