Skip to content

The agent that grows with you

fix(desktop): hard-exit a lock-losing second instance before ready

YappLeCunt7cc006a2ef4c
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index b7c095ba862..fd72f710d77 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -14105,9 +14105,17 @@ function registerDeepLinkProtocol() {
// second-instance argv. Without the lock a second `hermes://` launch spawns a
// whole new app instead of routing into the running one.
const _gotSingleInstanceLock = app.requestSingleInstanceLock()
-
-if (!_gotSingleInstanceLock) {
- app.quit()
+const isPrimaryInstance = _gotSingleInstanceLock
+
+if (!isPrimaryInstance) {
+ // Hard-exit, not app.quit(): the before-quit teardown coordinator defers a
+ // plain quit (event.preventDefault + async backend shutdown), and in that
+ // window `ready` still fires — the lock-losing instance then runs the full
+ // startup (shortcut registration, createWindow → startHermes), whose
+ // reapOrphans() SIGTERMs the running instance's live backend (#87295).
+ // app.exit() terminates immediately, before `ready`, so a second launch
+ // routes into the running window and never touches backend machinery.
+ app.exit(0)
} else {
app.on('second-instance', (_event, argv) => {
const url = _extractDeepLink(argv)