Skip to content

fix(browser): kill the whole process group during pre-identity cleanup#58

Merged
ElbertePlinio merged 2 commits into
mainfrom
feat/29-cleanup-hardening
Jul 23, 2026
Merged

fix(browser): kill the whole process group during pre-identity cleanup#58
ElbertePlinio merged 2 commits into
mainfrom
feat/29-cleanup-hardening

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Summary

Implements #29 — closes the pre-identity cleanup window for the browser supervisor:

  • stopOwnedBrowserDaemon previously did an individual-process kill (or nothing, if the supervisor had already exited) and reported success — leaving a live orphaned Chrome in the supervisor's process group while the session record claimed clean
  • now signals the whole group by pgid in both branches, confirms via the new portable isProcessGroupAlive primitive (kill-0 group probe, Darwin-safe), and reports gone only once confirmed; failure stays fail-open to the reaper via the existing pending-cleanup meta key
  • kill-safety review round: per-branch pid-reuse guarantees documented honestly (not-yet-exited branch safe by synchronous non-interleaving; already-exited branch is an accepted sub-second-bounded residual risk — Node reaps on SIGCHLD before exitCode goes non-null — now gated by an isProcessGroupAlive pre-check so a vacated group is never blindly signaled)
  • two integration regression tests (identity-never-resolves; supervisor-crashed-with-surviving-Chrome), both verified to fail against pre-fix main

Closes #29. Follow-up filed: #57 (same discipline for the Xvfb daemon, lower risk profile). No feature flag: defensive hardening, no user-facing behavior.

Validation

  • typecheck, build clean; focused suites stable 3×; full suite within the documented 43–45 Darwin baseline band with the new tests green
  • real Linux/KDE behavior exercised implicitly by the ubuntu CI browser suite on this PR

Local review: standard risk class — one independent kill-safety/correctness reviewer; P1 (pid-reuse overclaim + missing pre-check) and P3 (missing exited-supervisor test) both fixed in 1bed6bf per the reviewer's own smallest-fix prescription. KISS keep.

stopOwnedBrowserDaemon only signaled the Chrome supervisor process and
returned cleanup-complete unconditionally, including when the
supervisor had already exited on its own. A pathological /proc
identity-read failure combined with a supervisor crash could leave a
same-process-group Chrome alive while its session record was marked
fully cleaned up.

Signal the whole owned process group by pgid instead (safe without a
captured ProcessIdentity, since the daemon is our own just-spawned,
not-yet-reaped child), and confirm via a new portable isProcessGroupAlive
kill(2) probe that no member survives before reporting the group gone.

Refs #29
The exited-branch doc comment on stopOwnedBrowserDaemon overstated its
pid-reuse safety: Node/libuv can reap a child (making its pid
OS-reusable) before exitCode/signalCode observably go non-null, so
that branch is not provably safe the way the not-yet-exited branch is.
Split the doc comment per branch to state the real guarantee each one
relies on, and add an isProcessGroupAlive pre-check before signaling
in the exited branch so a fully vacated group is never blindly
signaled (this narrows, but does not close, the reuse gap).

Add the missing-supervisor integration regression the issue checklist
asks for: a stand-in supervisor that exits immediately after spawning
Chrome, exercising stopOwnedBrowserDaemon's already-exited branch
end-to-end through createBrowserSession. Captures Chrome's pid
synchronously from its own spawn() return rather than waiting on
Chrome's script to self-report, after the wait-based version proved
flaky under a fully parallel `bun run test`.

Refs #29
@ElbertePlinio
ElbertePlinio merged commit 7913f95 into main Jul 23, 2026
1 check passed
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.

Harden pre-identity browser daemon cleanup

1 participant