Skip to content

fix(process): settle an observed exit in progress before reporting a process present - #10620

Merged
morluto merged 3 commits into
morluto:mainfrom
Davmunrey:fix/hopper-settle-exiting-application
Nov 15, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
Davmunrey:fix/hopper-settle-exiting-application

Conversation

@Davmunrey

@Davmunrey Davmunrey commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #10556. close() on an external-application Hopper session could report cleanup_incomplete although 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_document without acknowledging it (the exit-without-ack fixture mode). The client sees the transport close and calls observeProcessStartIdentityExit once.

On Linux an exiting process closes its sockets before it becomes a zombie. In that window /proc/<pid>/stat still shows the same start identity with PF_EXITING set, which REA already models as lifecycle exiting. observeProcessStartIdentityExit returned present for it, so cleanup recorded:

"issues":[{"resource":"hopper-document","reason":"authenticated shutdown acknowledgement was not observed"},
          {"resource":"/tmp/rea-33PpH6","reason":"Private runtime retained because process or native document closure was not confirmed"}],
"authenticated_application":"readable"

Expected: an application observed exiting is given the existing verification grace to finish, and close() returns ok once 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 observed exiting, bounded by the existing PROCESS_CLEANUP_VERIFICATION_GRACE_MS (1 s) at PROCESS_CLEANUP_VERIFICATION_INTERVAL_MS (25 ms). This mirrors settleExitingProcessIdentities, which applies the same rule to owned process groups.

  • A live, non-exiting process is still reported present after a single read, with no wait.
  • A process that stays exiting past the grace is still reported present, so cleanup still fails closed.
  • An unavailable read during the wait is still unverified; a changed identity is still exited.

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

  • Semantic owner and earliest changed stage: src/process/ exit observation (observeProcessStartIdentityExit). Its only production consumer is confirmExternalApplicationExit in src/hopper/HopperCleanup.ts, which is unchanged.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none. close_binary can now succeed in a case where it previously reported cleanup_incomplete.
  • Provider, bridge, target-format, or platform compatibility: the exiting lifecycle is produced by the Linux stat parser; hosts that never report it take the previous single-read path.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): read-only identity reads of the already captured PID; no signal is sent. Worst case adds 1 s to a close whose application never finishes exiting.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

All executed on Linux x64 (kernel 6.18, Node 24.22.1) unless marked otherwise.

  • Tests added or updated: 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).
  • Base reproduction: recovers an application exit after the first valid handshake occurs during cleanup run 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.
  • State at socket close: a standalone probe (child connects over a Unix socket, then process.exit(0); parent reads /proc/<pid>/stat synchronously on close) saw zombie 288 times and PF_EXITING 12 times in 300 runs, and never a non-exiting live process.
  • With the fix: 90 loaded runs of the same test, 0 failures. In one of them a temporary trace showed the wait being taken, after which the process was gone and the test passed.
  • User-visible CLI/MCP output: not applicable.
  • Remaining proof gaps: the CI failures themselves were not re-run; the link to them is the identical error, stack and diagnostics. The issue reports the failure at the first close() (line 288); locally it appeared at the second close() 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:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

(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:typed reports 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

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux only, fixture bridge only. No real Hopper, macOS or Windows run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new authority; bounded read-only polling of a captured PID with identity re-validated on every read.

Author readiness

Human owner: @Davmunrey

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

…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
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T18:55:47.775942Z
We couldn’t complete this review. Comment @codex review to try again.
3fa2a6c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Fixes the Linux close race by waiting for an observed process exit to finish, while preserving checks on the process’s start identity.

  • Hopper cleanup waits for an exiting application to finish.

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 Davmunrey left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 exiting result from #10594. An exit in progress that outlasts the cleanup grace now reports exiting instead of present, 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.

@Davmunrey

Copy link
Copy Markdown
Contributor Author

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:

Load (busy loops on 2 CPUs) main this branch
4 0/40 failed 0/40 failed
8 0/40 failed 0/40 failed

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. confirmExternalApplicationExit confirms shutdown only on exited, and observeProcessStartIdentityExit returns exiting as soon as it reads PF_EXITING, so a close that lands in that window still leaves cleanup unconfirmed. This branch waits out the cleanup grace through settleExitingProcessIdentities before it reports exiting, so an exit in progress settles to exited. Treat it as hardening backed by the earlier probe (PF_EXITING seen 12 times in 300 runs), not as a reproduced fix. If you prefer to wait for the flake to recur in CI, I can leave it open.

@morluto
morluto merged commit f270a5c into morluto:main Nov 15, 2026
49 checks passed
@morluto

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Merged — thank you for tracking this down at the ownership observation itself. This closes #10556.

@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Hopper handshake-recovery test fails intermittently on Linux CI during cleanup

2 participants