Skip to content

Fix Electron single-instance and server recovery lifecycle - #1

Open
kargnas wants to merge 1 commit into
mainfrom
codex/electron-server-lifecycle
Open

Fix Electron single-instance and server recovery lifecycle#1
kargnas wants to merge 1 commit into
mainfrom
codex/electron-server-lifecycle

Conversation

@kargnas

@kargnas kargnas commented Aug 16, 2026

Copy link
Copy Markdown
Owner

Why

A resident LaunchAgent could start a second Electron host. An unexpected embedded-server exit could also leave the host alive without its local server.

Root cause

The app did not own a single-instance lock. The embedded-server exit watcher was registered only after the health response body finished parsing, so a child that exited during that await could be returned as healthy. The Electron test mock also omitted the Linux app.setDesktopName API.

What changed

  • Acquire the single-instance lock and focus the existing window on a second launch.
  • Quit the host when the embedded server exits unexpectedly while preserving intentional shutdown.
  • Recheck the child exit state after parsing the health response and retry the next port.
  • Add the Linux Electron mock method and a regression test for the health-body race.

Verification

  • Node 24.19.0
  • pnpm test: 379 passed, 8 skipped
  • updater node tests: 11 passed
  • pnpm typecheck
  • pnpm check:electron
  • pnpm exec vite build

LaunchAgent가 앱을 상주시킬 때 중복 실행과 내장 서버 단독 종료가 상주 계약을 깨뜨렸습니다. 두 번째 실행은 기존 창을 활성화하고, 내장 서버가 종료되면 호스트도 종료하여 launchd가 전체 프로세스를 다시 시작하도록 변경했습니다.

Constraint: Embedded server lifecycle is owned by the Electron host
Rejected: External server LaunchAgent | packaged app verifies its child PID and switches ports
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep the server exit watcher disabled during intentional shutdown
Tested: pnpm test; pnpm typecheck; pnpm check:electron; signed package; launchd restart and duplicate-launch smoke tests
@kargnas kargnas closed this Aug 16, 2026
@kargnas kargnas reopened this Aug 16, 2026
@kargnas
kargnas marked this pull request as ready for review August 16, 2026 10:29
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