#6983

fix(process): settle exits during Linux credential observation

Openkwakhyunwants to merge intofrom

Summary

On Linux, a process can exit between the first native identity read and a later credential read. The observer then returned its earlier live identity, even when the later procfs read failed because the process was gone. Route those missing reads through the existing corroborated-absence check so cleanup can settle the exited candidate.

Related: #4322 and the credential-bracket fallback left open in #6220. This does not claim to resolve all of #4322 or reproduce #6220's entire nondumpable-churn workload. The producer defect remains on base 48c203f3567e7b79af562349eecb6720a96de667, which already includes #5270 and #5675.

Problem and expected behavior

A readable /proc/PID/stat followed by ENOENT/ESRCH from /proc/PID/status or the closing /proc/PID/stat must not silently become the old live observation. As with a missing first stat, absence requires a signal-zero probe that itself reports ESRCH. A successful, false, or permission-denied probe remains unavailable.

Change and scope

  • Forward missing status/closing-stat errors to the existing Linux absence classification; share its missing-procfs predicate and generalize its free-form diagnostic prefixes.
  • Retain the existing identity-only fallback for EACCES/EPERM, without attaching unverified credential facts.
  • Add controlled boundary cases and two real Linux child regressions. The latter control when an owned child exits, then use actual procfs reads and the kernel's signal-zero result after reap.

This is an ordinary fix within the existing observation boundary; a new maintainer capability/scope decision is not applicable. No new retries, waits, cleanup policy, or signal authority. At most one existing signal-zero probe is now reached for a missing optional credential read. Performance was not benchmarked.

Contract and boundary impact

  • Semantic owner: createSystemProcessOwnershipHost().processIdentities, before ownership facts and cleanup consume the observation. Existing absent/unavailable consumers need no changes.
  • CLI/MCP schemas, tool catalog, providers, evidence persistence, package/install metadata: unchanged. Free-form missing-procfs diagnostics now describe the broader lookup.
  • Platform: Linux credential observations only. PID alone still grants no termination authority; live/unknown cases remain conservative.
  • Read existing files or captured data (existing procfs observation).
  • Launch or attach to a process (existing cleanup workflows and owned test children).

Evidence and regression coverage

  • With the new tests and unmodified producer at d9660eb03271d0ce1859cf8720ca460701dd3322: six controlled cases fail; both real Linux child cases also fail, returning the first readable identity after the child exited normally with code 0. The producer is unchanged between that revision and the final base.
  • With the fix: both native exit cases and the live/unknown/permission controls pass. Existing ownership, PID-replacement, retained-descendant, cleanup-retry, and finalization regressions are included below.
  • The bounded 100-child ack/exit diagnostic corresponding to #4322 completed with zero first-cleanup, post-exit, or final-cleanup failures. This is one diagnostic run, not a failure-rate estimate or proof that every #4322 path is resolved.
  • Observed results and inferred scope remain distinct; unavailable coverage is explicit.

Validation performed

Toolchain: Node 24.22.1, npm 11.16.0. Linux runs use Debian bookworm arm64, uid 1000, 1 CPU, 1536 MiB, and one Vitest worker. CLI/MCP tests execute the compiled JavaScript runtime with separately installed Linux dependencies.

  • npm run check — passed (typecheck, lint/module boundaries, formatting, knip, metadata, architecture guards).
  • npm run build:cached — passed. The pre-push npm run check:fast also passed; hooks remained enabled.
  • Exact Linux source selection below — 311 passed in 21 files, including both real child regressions.
  • Exact Linux boundary/acceptance selection below — 53 passed, 1 macOS-only skip in 8 files, including compiled CLI/MCP finalization and cleanup retry.
  • node scripts/run-exact-tests.mjs run src/process/ProcessOwnership.procIdentity.test.ts --maxWorkers=1 --no-file-parallelism on macOS — 21 passed, 2 Linux-only skips.
  • node /evidence/issue4322-linux/repro-ack-exit.mjs (local bounded diagnostic using compiled modules) — 100/100 completed, no incomplete first/post-exit/final cleanup; no forced fixture kills. This diagnostic is separate from the committed regression tests.

Final Linux and static results cover commit 81df2d78fcc032ce9f602b670ffd349c1a807149. An initial full check on the earlier base failed in the unrelated releaseProposal.test.ts types; the same failure reproduced on a pristine checkout. Updating to main 48c203f3, which includes the upstream correction, cleared it. No release-related edit is included here.

Executed Linux test selections
node scripts/run-exact-tests.mjs run \
  src/process/ProcessOwnership.baselineAbsence.test.ts \
  src/process/ProcessOwnership.exitScope.test.ts \
  src/process/ProcessOwnership.exiting.test.ts \
  src/process/ProcessOwnership.finalSweep.test.ts \
  src/process/ProcessOwnership.identity.test.ts \
  src/process/ProcessOwnership.lineage.test.ts \
  src/process/ProcessOwnership.nativeExit.test.ts \
  src/process/ProcessOwnership.observation.test.ts \
  src/process/ProcessOwnership.part2.test.ts \
  src/process/ProcessOwnership.part3.test.ts \
  src/process/ProcessOwnership.procIdentity.test.ts \
  src/process/ProcessOwnership.runId.test.ts \
  src/process/ProcessOwnership.sweepExit.test.ts \
  src/process/ProcessOwnership.test.ts \
  src/process/ProcessOwnership.tokenAvailability.test.ts \
  src/process/ProcessOwnership.validation.test.ts \
  src/process/ProcessOwnershipFacts.test.ts \
  src/process/LinuxProcessStat.test.ts \
  src/process/LinuxProcessStatus.test.ts \
  src/process/capture/ProcessCaptureOwnershipEvidence.test.ts \
  src/process/ProviderProcess.launcherExit.test.ts \
  --maxWorkers=1 --no-file-parallelism \
  --reporter=default --reporter=json \
  --outputFile.json=/tmp/issue4322-linux-source.json

node scripts/run-exact-tests.mjs run \
  tests/boundary/process/providerProcess.test.ts \
  tests/boundary/process/processCleanupRetryOwnership.test.ts \
  tests/boundary/process/processLineageRetention.test.ts \
  tests/boundary/process/processBaselineAbsence.test.ts \
  tests/boundary/mcp/processCleanupRetryMcp.test.ts \
  tests/boundary/mcp/reverseEngineeringEnvironmentMcp.test.ts \
  tests/boundary/mcp/reverseEngineeringProviderEnvironmentMcp.test.ts \
  tests/acceptance/process/processFinalization.test.ts \
  --maxWorkers=1 --no-file-parallelism \
  --reporter=default --reporter=json \
  --outputFile.json=/tmp/issue4322-linux-boundary.json

Compatibility, safety, and release

No breaking API or migration. New native tests are Linux-only; macOS runs the controlled cases and skips those two tests. Windows, real Hopper/Ghidra engines, and the nondumpable synthetic-churn workload were not run. The runtime tests use owned fixture processes; they do not establish real-provider coverage.

Latest review and CI evidence

Re-reviewed unchanged head 81df2d78. Greptile's review is 5/5 with no actionable findings; there are no inline review threads. No Codex review is recorded.

CI run 40082480319 is not green:

  • Static checks passed, and the source log explicitly records 23/23 passing tests in ProcessOwnership.procIdentity.test.ts, including the two actual Linux child cases.
  • Build package aborted with free(): invalid next size (normal) / exit 134 in node scripts/ci/portable-build-cache.mjs key, before production build or ownership code executes. The same command succeeds locally on macOS; the runner crash's underlying cause has not been diagnosed.
  • Source tests exited in a Vitest worker running javascriptSemanticAnalysis.reference_lifetimes.test.ts. Running that file alone with one worker reproduced the same unexpected-worker-exit error both on this PR and in a pristine 48c203f3 worktree using the same pinned Node/dependencies. These JavaScript sources, runner configuration and dependency manifests are unchanged by the PR. This establishes a failure independent of this patch, not its underlying cause.
  • Portable-test aggregation then lacked the source/shard reports; the required CI gate failed. Those are downstream failures, not additional failed assertions in this change.

The API refused a failed-job rerun with HTTP 403 (Resource not accessible by integration); a maintainer with Actions write access must rerun it. The local ownership/CLI/MCP evidence above remains valid, but full remote qualification remains open.

Author readiness

Human owner: @kwakhyun

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

AI-assisted contribution. The human owner has reviewed the final diff and evidence, accepts the recorded CI limitations, and has declared 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. (Ordinary fix; no new capability.)
  • 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. (No contract or metadata changes.)
  • Required remote checks are complete.

Activity

9
greptile-apps[bot]1mo ago

Confidence Score: 5/5

[Medium impact] The reviewed code appears safe to merge; no actionable defects were found.

Summary

Linux credential observations now send missing status and closing stat reads through the existing corroborated-absence check instead of returning an earlier live identity.

  • Linux identity checks settle exits during credential reads.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read initial Linux identity] --> B[Read credentials and closing identity]
  B -->|ENOENT or ESRCH| C[Probe with signal zero]
  C -->|ESRCH| D[Report absent]
  C -->|Success, false, or other error| E[Report unavailable]
  B -->|Permission denied| F[Retain identity without credential claims]
  B -->|Successful matching reads| G[Return verified facts]

Reviews (1) · Last reviewed commit: "fix(process): settle exits during Linux ..." · Reviewed by Greptile

chatgpt-codex-connector[bot]1mo ago

Codex Review Summary

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

ReviewStatusCommitReview trigger
📝 Code Review✅ Completed 2026-11-01T11:22:43.552174Z81df2d7Manual request
ℹ️ 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.

kwakhyun1mo ago

@morluto, this PR is now ready for initial review. Author readiness is complete, including acceptance of the recorded CI limitations.

For unchanged head 81df2d78, the final diff review found no blocking issue, Greptile reported 5/5 with no actionable findings, local Linux ownership tests passed 311/311, and CLI/MCP boundary/acceptance tests passed 53 with one macOS-only skip. GitHub CI also passed all 23 tests in the changed proc-identity file and its static checks.

Remote CI is still red: the build job aborted in build-cache key calculation before ownership code ran, and the source job lost a worker in an unchanged JavaScript semantic-analysis test. The latter also reproduces in a pristine 48c203f3 worktree; details and limits are in the updated PR body.

Could you review this change and rerun the failed jobs in run 40082480319? My integration received HTTP 403 for both rerunning Actions and assigning a reviewer, so I am requesting review here. Full remote qualification remains pending.

kwakhyun24d ago

@codex review

Please review the latest commit, 81df2d78fcc032ce9f602b670ffd349c1a807149. The previous review could not complete.

kwakhyun24d ago

Hi @morluto, could you please rerun the failed CI jobs and review this PR when you have a chance? Readiness is passing, and Greptile reported 5/5 on 81df2d78. The CI failure analysis is in the description, and I've requested a fresh Codex review. Thanks for your time!

chatgpt-codex-connector[bot]24d ago

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 81df2d78fc

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

kaoru0822-kitauji23d ago

This PR's fix also covers a failure that reached main today, so here is evidence that may help it land.

Observed on main: run 41416014732, Test shard (7/8) on 93b8b82db. In tests/acceptance/inesContainer.test.ts, the first open_binary returned cleanup_incomplete from ghidra:java: live candidates 7379=environment_errno_EACCES (name "lsb_release", ppid 7377, pgid 1171, identity linux-starttime:31764). The failure's identityAfter has no effectiveUid, while its parent 7377 was recorded as unverified.

Reproduced with scripted procfs reads, not on a runner: I drove cleanupOwnedProcessGroup through the production Linux host. On 93b8b82db, a root-owned process that exits during the credential read of the last bounded token re-read returns that same failure, field for field. An exit during an earlier read passes, because the next re-read sees the process gone. The CI log does not record the errno of the failed credential read, so exit is inferred for that run: an identity without effectiveUid only comes from the fallbacks for a failed or unparsable credential read, and the same read worked for the parent.

With this PR's source change on 93b8b82db: all 31 sweep cases pass, against 9 failures without it. The fail-closed controls still hold: an unreadable related process, denied credentials, a same-user process with no restriction, a reused PID, and signal-zero not reporting ESRCH. Procfs reads on a live sweep are unchanged (46 readFile, 8 stat). With the conflict below resolved, src/process/ProcessOwnership* and LinuxProcessStat* tests give 375 passed, 4 skipped, and npm run check:fast passes. This ran on macOS, so your real Linux child cases did not run here.

What blocks landing: the only conflict with main is in src/process/ProcessOwnership.procIdentity.test.ts. #8553 added name: "fixture" to the identity expectation of the test you replace. To resolve it, keep your tests and add that field to the expectation in "keeps native identity without credential claims". The source change applies cleanly.

Maintainer edits are off on this branch, so I can't push that merge. Could you merge main, or allow edits by maintainers? A new push would also replace the old CI run.

morluto21d ago

Hey @kwakhyun, thanks for the PR! This fix looks good to me. What's left: it has merge conflicts with main in src/process/ProcessOwnership.procIdentity.test.ts (merging main into the branch is fine) and the Portable tests check is failing (failing jobs: Build package and Source tests). Happy to merge once that's sorted.