Repository navigation
fix(process): settle an observed exit in progress before reporting a process present - #10620
Conversation
…process present An exiting process closes its sockets before it becomes a zombie. A caller that reacts to the closed transport could read the captured identity in that window and report it as present, so Hopper cleanup retained the document and private runtime although the application had exited. Wait, within the existing cleanup verification grace, only while the same identity is positively observed exiting. Refs morluto#10556
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; no blocking issues were found. SummaryFixes the Linux close race by waiting for an observed process exit to finish, while preserving checks on the process’s start identity.
No new actionable issues found. The target branch still has the single-read behavior; the merged diagnostics change does not replace this fix. Reviews (4) · Last reviewed commit: "Merge morluto/rea main into hopper-settl..." · Reviewed by Greptile |
Review follow-up for observeProcessStartIdentityExit. The exit check added its own waiting loop beside settleExitingProcessIdentities, with the same deadline, polling interval and same-identity exiting check, so future exit-race fixes would need two changes. The check now hands its first observation to the shared settlement and keeps only the final result choice. The settlement and its identity reader accept PID-only rows, the shape the host identity reader already takes. One liveProcessIdentity helper maps absent and exited identities for both observeProcessStartIdentity and the settled result. Behavior is unchanged: an exiting identity is re-read until it leaves exit in progress or the cleanup grace ends; a replacement, absent or zombie identity is exited, an unreadable one unverified, and one still exiting at the deadline present. Tests: src/process (850), the Hopper cleanup and session tests (15) and 20 Hopper boundary test files (114) pass. check:fast passes.
morluto#10594 added an "exiting" result to observeProcessStartIdentityExit. This branch now waits through the shared exit settlement first, so "exiting" names an exit in progress that outlasted the cleanup grace. The never-settling test now expects "exiting" after more than one read.
Davmunrey
left a comment
There was a problem hiding this comment.
Status since opening:
- Greptile's duplicated exit-wait finding is fixed in 995471b. The exit check now reuses
settleExitingProcessIdentities, so the wait lives in one place. - Merged current main in fa19369, including the
exitingresult from #10594. An exit in progress that outlasts the cleanup grace now reportsexitinginstead ofpresent, and the test expects that. - Validation on the merged branch: src/process and Hopper unit tests (868), 20 Hopper boundary test files (114), architecture-guards, format:check and check:ci:fast.
|
Load re-run on current main (2826592) and on this branch merged with it, Linux x64, Node 24.22.1. The handshake-recovery test ran on CPUs 0-1 shared with busy loops:
I can no longer reproduce #10556 on this machine. My earlier 4/40 was on main before #10594, so these runs do not show this branch fixing the flake. The window is still in the source. |
|
Merged — thank you for tracking this down at the ownership observation itself. This closes #10556. |
Summary
Fixes #10556.
close()on an external-application Hopper session could reportcleanup_incompletealthough the application had already exited, because the exit observation read the process while it was still mid-exit and counted it as present.Related: #10594 adds diagnostics for the same failure. This PR addresses the cause and does not overlap its files; either order of merge works.
Problem and expected behavior
Smallest trigger: the authenticated application exits in response to
shutdown_documentwithout acknowledging it (theexit-without-ackfixture mode). The client sees the transport close and callsobserveProcessStartIdentityExitonce.On Linux an exiting process closes its sockets before it becomes a zombie. In that window
/proc/<pid>/statstill shows the same start identity withPF_EXITINGset, which REA already models as lifecycleexiting.observeProcessStartIdentityExitreturnedpresentfor it, so cleanup recorded:Expected: an application observed exiting is given the existing verification grace to finish, and
close()returnsokonce it is a zombie or gone.Change and scope
observeProcessStartIdentityExit(src/process/ProcessOwnershipObservation.ts) now re-reads the identity while the same generation is positively observedexiting, bounded by the existingPROCESS_CLEANUP_VERIFICATION_GRACE_MS(1 s) atPROCESS_CLEANUP_VERIFICATION_INTERVAL_MS(25 ms). This mirrorssettleExitingProcessIdentities, which applies the same rule to owned process groups.presentafter a single read, with no wait.exitingpast the grace is still reportedpresent, so cleanup still fails closed.unverified; a changed identity is stillexited.Not included: changes to the Hopper fixture or test, and the diagnostics in #10594.
This is not a speculative race: it is the failure reported in #10556 and it reproduces locally (below).
Scope decision: not applicable, ordinary fix within existing boundaries.
Contract and boundary impact
src/process/exit observation (observeProcessStartIdentityExit). Its only production consumer isconfirmExternalApplicationExitinsrc/hopper/HopperCleanup.ts, which is unchanged.close_binarycan now succeed in a case where it previously reportedcleanup_incomplete.exitinglifecycle is produced by the Linux stat parser; hosts that never report it take the previous single-read path.Expected effects:
Evidence and regression coverage
All executed on Linux x64 (kernel 6.18, Node 24.22.1) unless marked otherwise.
src/process/ProcessStartIdentity.test.ts, new block "observed exit in progress" (6 cases): exiting then zombie / absent / replaced identity / unavailable, never leaves exiting, and live non-exiting. On the base revision the four settle cases and the read-count assertions would fail, because the function reads once (source-derived; not run against base).recovers an application exit after the first valid handshake occurs during cleanuprun repeatedly on two CPUs shared with CPU hogs (taskset -c 0,1, 6-10 busy loops). Base failed 2 of 15 runs in one batch and 2 more in a later batch, with the same stack as the issue and the diagnostics quoted above. It also passed 30 of 30 in another batch, so the rate is low and variable.process.exit(0); parent reads/proc/<pid>/statsynchronously onclose) sawzombie288 times andPF_EXITING12 times in 300 runs, and never a non-exiting live process.close()(line 288); locally it appeared at the secondclose()of the same test, which goes through the same path. Not run on macOS or Windows. No real Hopper.Boundary/lifecycle regressions: covers application exit during final cleanup for the external-application lifetime. Cancellation during cleanup and cleanup retry are unchanged and not re-verified here.
For evidence-bearing changes:
(Not an evidence-bearing change.)
Validation performed
npm run test:local -- src/process/ProcessStartIdentity.test.ts src/hopper/HopperCleanup.test.ts— 2 files, 32 tests passed.npm run test:focused -- tests/boundary/providers/hopper/hopperClient.handshakeRecovery.test.ts— 7 passed (run on base before the change; the loaded repetitions above ran the target case with the change).npm run check— typecheck, lint, format:check, knip, metadata:check, verify:architecture-guards and knip:production passed.lint:typedreports 1 error,src/domain/jsonDuplicateMember.ts:44:13 switch-exhaustiveness-check, which is also reported on the unmodified base (79097f5) and is not touched here.npm run docs:check— not run; no contract or generated metadata change.Compatibility, safety, and release
Author readiness
Human owner: @Davmunrey
Before merge
type(scope): outcome.