Skip to content

test(process): count zombie descendants as stopped in cleanup checks - #11837

Closed
djrk935 wants to merge 1 commit into
morluto:mainfrom
djrk935:fix/zombie-aware-stop-checks
Closed

djrk935 wants to merge 1 commit into
morluto:mainfrom
djrk935:fix/zombie-aware-stop-checks

Conversation

@djrk935

@djrk935 djrk935 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Where PID 1 does not reap orphans (a container started without an init process), a killed descendant stays a zombie. Signal 0 still reaches a zombie and every process group holding one, and a raw process table still lists it. Twelve boundary tests used one of those to decide a stopped process or group was gone, so they failed in such containers although cleanup had worked.

Fixes #11819

Problem and expected behavior

  • desktopTaskReaderRunner: the cancelled reader's PID check (1 test).
  • mcpDoctor: waitForExit in both outliving-descendant cases (2).
  • kunaVersionProbeOwnership: five cases, through the test launcher's ownedGroupCleanup, which reported "group remains live" for a group holding only zombies (5). The cause is this test-owned cleanup authority, not product cleanup confirmation (the issue's hypothesis).
  • desktopBuildOwnedCommand: packing and setup family PID checks (2).
  • artifactVerifierCleanupOwner: protocol process and descendant (1).
  • ownedCommand: the run-token sweep read the raw process table instead of the product's liveProcesses view, which drops zombie rows (1).

The first eight are the cases reported in #11819; the last four were found by running every suite with a signal-0 stop assertion in the same container.

Change and scope

  • tests/support/process/observePosixProcess.ts: add observePosixProcessGroup (members of one group from one ps table, zombies kept apart from live members) and processHasStopped (a POSIX zombie counts as stopped; Windows keeps signal 0, since it has no zombie state).
  • Use them, the existing observePosixProcess, or the product's liveProcesses filter at each site.
  • docs/development/testing.md names these helpers for stop assertions.

Test-only plus one testing-guide paragraph; no product code changes. Contribution scope: ordinary fix within existing boundaries; maintainer scope decision not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: test support observePosixProcess.ts owns process-stop observation in tests; product liveProcesses remains the product owner.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none; Windows behavior of the touched tests is unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: tests now accept a zombie as stopped; a ps failure is reported instead of being read as absence.
  • Generated metadata, package, or installation impact: none.

Expected effects: test harness only; no product target interaction.

Evidence and regression coverage

  • Tests added or updated: posixProcessObservation.test.ts covers the group helper with a fake ps (members, other groups, malformed rows, diagnostics, exit failure) and a real zombie (Python forks a child that exits and is never reaped) showing that signal 0 still reaches it while processHasStopped reports it stopped. Making the fixture reap its child fails that test at its group assertion.
  • Base reproduction: Linux arm64 container without an init (npm as PID 1, uid 1000), Node 24.22.1, on main: the four originally reported files fail exactly the 8 reported cases (8 failed, 55 passed).
  • Remaining proof gaps: the javascript-recovery suites (wakaruIntegration, wakaruFileOwnership, javascriptRecoveryMcp) skipped in the container, so the signal-0 group check in tests/fixtures/javascript-recovery/provider.ts is unverified there; firmwarePublicationDeadline and macOS-only dmgCancellationReason also skipped. Three firmware resource-limit tests fail in that container with a different cause (ProviderAdapterError instead of AnalysisResourceConstraintError) and are not addressed.

Validation performed

  • Sweep of the 31 files holding a signal-0 stop assertion in the container: 21 passed (including jadxIntegration, jadxJavaLifecycle), 5 skipped, 5 failed (the 4 zombie cases above plus the 3 firmware cases).
  • npm run test:focused -- the 7 affected files, Linux container with this change — 101 passed, none skipped.
  • Same 7 files on macOS arm64 — 101 passed.
  • npm run check:fast — typecheck, lint and architecture guards pass. npm run docs:check — passes.
  • One earlier container run under heavy host CPU load also failed two unrelated mcpDoctor output tests (a 30 s timeout; "write EPIPE" vs "Connection closed"); both passed on rerun on an idle host.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS arm64 and Linux arm64 container; Windows not run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: test-only.

Author readiness

Human owner:

  • 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.

🤖 Generated with Claude Code

Where PID 1 does not reap orphans (a container started without an init
process), a killed descendant stays a zombie. Signal 0 still reaches a
zombie and every process group that holds one, and a raw process table
still lists it. Twelve boundary tests used one of those to decide that a
stopped process or group was gone, so they failed in such containers
although cleanup had worked:

- desktopTaskReaderRunner: the cancelled reader's PID check (1).
- mcpDoctor: waitForExit in both outliving-descendant cases (2).
- kunaVersionProbeOwnership: five cases through the test launcher's
  ownedGroupCleanup, which reported "group remains live" for a group
  that held only zombies (5). The cause is this test-owned cleanup
  authority, not product cleanup confirmation.
- desktopBuildOwnedCommand: the packing and setup family PID checks (2).
- artifactVerifierCleanupOwner: the protocol process and descendant (1).
- ownedCommand: the run-token sweep read the raw process table instead
  of the product's own liveProcesses view, which drops zombie rows (1).

The first eight are the cases reported in morluto#11819; the last four were
found by running every suite with a signal-0 stop assertion in the same
container.

Add observePosixProcessGroup, which lists a group's members from one ps
table and keeps zombies apart from live members, and processHasStopped,
which treats a POSIX zombie as stopped and keeps signal 0 on Windows,
where no zombie state exists. Use them, the existing observePosixProcess,
or the product's liveProcesses filter at each site. The testing guide
now names these helpers for stop assertions.

Validation:
- Linux arm64 container without an init (npm as PID 1, uid 1000), Node
  24.22.1. On main, the four originally reported files fail exactly the
  8 reported cases (8 failed, 55 passed). A sweep of the 31 files that
  hold a signal-0 stop assertion (21 passed, including jadxIntegration
  and jadxJavaLifecycle; 5 skipped entirely) found the 4 further
  failures above plus 3 firmware resource-limit failures with a
  different cause (ProviderAdapterError instead of
  AnalysisResourceConstraintError), which this change does not address.
  With this change, the 7 affected files pass in the container.
- macOS arm64: the 7 affected files pass (101 tests); format, typecheck,
  lint and architecture guards pass.
- The real-zombie regression fails at its group assertion when the
  fixture reaps its child.

Not run: the javascript-recovery suites (wakaruIntegration,
wakaruFileOwnership, javascriptRecoveryMcp) skipped in the container, so
the signal-0 group check in tests/fixtures/javascript-recovery/provider.ts
is unverified there; firmwarePublicationDeadline and the macOS-only
dmgCancellationReason also skipped.

Fixes morluto#11819

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with the existing non-blocking fixture cleanup concern still open.

Findings

  1. P2 The fixture leaves zombies behind ▶
Fix with agent prompt
### Issue 1
tests/boundary/providers/posixProcessObservation.test.ts:186-192
If the container's PID 1 does not reap children, this test leaves one zombie behind on every run. The Python parent never calls `os.waitpid()`, and teardown kills it with `SIGKILL`. Waiting for the parent's `exit` event does not reap its child. Repeated runs consume process slots until the container stops.

Keep the child unreaped during the assertions, then ask the Python parent to reap it and exit. Reserve `SIGKILL` for fallback cleanup.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Updates test cleanup checks so exited zombies count as stopped instead of requiring their process-table rows to disappear.

  • Test cleanup checks count POSIX zombies as stopped.

Reviews (3) · Last reviewed commit: "test(process): count zombie descendants ..." · Reviewed by Greptile

Comment on lines +186 to +192
const exited = once(parent, "exit");
try {
process.kill(-group, "SIGKILL");
} catch {
// The group is already gone.
}
if (parent.exitCode === null && parent.signalCode === null) await exited;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The fixture leaves zombies behind

If the container's PID 1 does not reap children, this test leaves one zombie behind on every run. The Python parent never calls os.waitpid(), and teardown kills it with SIGKILL. Waiting for the parent's exit event does not reap its child. Repeated runs consume process slots until the container stops.

Keep the child unreaped during the assertions, then ask the Python parent to reap it and exit. Reserve SIGKILL for fallback cleanup.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/boundary/providers/posixProcessObservation.test.ts
Line: 186-192

Comment:
**The fixture leaves zombies behind**

If the container's PID 1 does not reap children, this test leaves one zombie behind on every run. The Python parent never calls `os.waitpid()`, and teardown kills it with `SIGKILL`. Waiting for the parent's `exit` event does not reap its child. Repeated runs consume process slots until the container stops.

Keep the child unreaped during the assertions, then ask the Python parent to reap it and exit. Reserve `SIGKILL` for fallback cleanup.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@djrk935
djrk935 marked this pull request as ready for review November 17, 2026 16:01
@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-17T16:01:29.444827Z
We couldn’t complete this review. Comment @codex review to try again.
5b7b5c2 Draft marked ready
ℹ️ 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.

@Davmunrey

Copy link
Copy Markdown
Contributor

This still matters after #12034, and it now conflicts with main, so I ported what remains.

What is left on main. #12034 fixed the eight cases from #11819. In the same kind of environment (Firecracker microVM, PID 1 is process_api, running as root), the built test group on main (23adfc610) still fails three of the four extra cases this PR found:

  • artifactVerifierCleanupOwner › joins an owned protocol process and its descendant before closing
  • desktopBuildOwnedCommand › stops the packing process family before removing its partial archive on timeout
  • desktopBuildOwnedCommand › cancels a running setup process family before removing its partial output

They fail on every run, also alone on an idle machine. Reading /proc/<pid>/stat around transport.close() in the first one shows the cause directly: the direct child is gone (ESRCH), the descendant is in state Z with PPID 1 and still answers signal 0, and it disappears within about 3 seconds.

The port. Branch Davmunrey:fix/process-stop-checks-zombie, one commit on f7849cad3 with you as author: https://github.com/Davmunrey/rea/tree/fix/process-stop-checks-zombie

Checked in that container. The three files run 35 of 35 with the port. node scripts/run-typescript.mjs --noEmit, npm run check:fast, npm run docs:check, the architecture guards and oxfmt --check pass. One gap: the ownedCommand case passed on main here too, because this PID 1 reaps inside that test's 2 second poll, so I could not reproduce that one and kept your change as written.

To take it into this PR:

git fetch https://github.com/Davmunrey/rea fix/process-stop-checks-zombie
git reset --hard FETCH_HEAD
git push --force-with-lease

morluto pushed a commit that referenced this pull request Nov 18, 2026
…12091)

Where PID 1 does not reap orphans promptly, a killed descendant stays a zombie for a while. Signal 0 still reaches a zombie, and a raw process table still lists it, so four boundary tests decided a stopped process was alive although cleanup had worked.

The stop assertions in artifactVerifierCleanupOwner and desktopBuildOwnedCommand now use processHasStopped. The run-token sweep in ownedCommand reads the product's liveProcesses view, which drops zombie rows. The testing guide says to assert a stop this way and not with signal 0.

Ported onto current main from #11837. The helper and the first eight cases landed in #12034, so this keeps the four that remained.

Co-authored-by: Dayan Kijege <[email protected]>
@morluto

morluto commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Closing as superseded. The affected cleanup assertions and testing guidance have landed across #12034 and #12091. #12091 preserves credit for the ported work.

@morluto morluto closed this Nov 18, 2026
@morluto morluto added the area: runtime Process capture and runtime observation label 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Process-cleanup tests count a killed descendant as alive while it waits to be reaped

3 participants