Repository navigation
fix(process): re-read unreadable tokens before signaling and name the process - #8553
Conversation
… process Darwin KERN_PROCARGS2 samples a process's argument length and stack top before it reads the address space, and exec publishes the new length before it copies the new strings out (xnu sysctl_procargsx, exec_copyout_strings). A read during exec can return a zero-filled or stale strings area, and exec keeps the PID and start time that bracket the read. The final sweep already re-read such tokens, but the pre-signal group check read each member's token once, so one transient read of a live group member failed the whole cleanup. Move the bounded re-read into one shared fact-reading helper and use it for both the sweep and the pre-signal group check. The group check binds re-reads to the generation it first observed, so a reused PID stays unresolved; the sweep keeps classifying the PID's current process. An unreadable-token failure now carries the native identity read after the token and the summary names the candidate by its native name, parent, group and start identity. The Darwin helper and Linux procfs reader report the short native process name (p_comm/comm) for display. Fixes #8337 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis 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. |
[Medium impact] The changes reach shared process-ownership cleanup workflows. The last refresh can still reject a transient token read without retrying it, so the remaining prior finding should be addressed before merging. SummaryShares bounded token rereads between the ownership sweep and pre-signal group checks. Unreadable-token errors now include native process names and identity facts.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Read identity, token, identity] --> B{Live unreadable token?}
B -->|Yes, attempts remain| C[Wait 40 ms]
C --> D[Reread selected members]
D --> E{Pre-signal check?}
E -->|Yes| F[Keep first-generation binding]
E -->|No| G[Use current PID facts]
F --> B
G --> B
B -->|No, or limit reached| H[Check ownership and current group]
H -->|Uncertain| I[Fail cleanup and retain ownership]
H -->|Verified| J[Allow group signal]
Reviews (3) · Last reviewed commit: "fix(process): keep known identity change..." · Reviewed by Greptile |
…ient-token-read Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pre-signal group check re-read only members whose token was unavailable, so a readable member kept the relation it had before the retry waits. A member that moved to another process group during those waits could be validated on its old group, and the old group signaled while the moved member kept running. After any retry wait, the shared re-read helper now reads every other live pre-signal fact once more with the same generation binding. A moved member then takes the existing changed-group path, which retains its ownership evidence and fails cleanup. An inconclusive refresh replaces the stale fact so it fails closed. Nothing changes when no re-read ran, and the sweep keeps classifying current processes because every group it finds is revalidated before signaling. Also cover PID reuse that happens before the re-read starts, where both re-read identities agree and only the first-read generation rejects the replacement's token. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ient-token-read Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pre-signal re-read treated a first read without a same-generation identity as unbound and replaced it with the re-read. On Linux the first read can already establish PID reuse (an ESRCH token whose exit check sees another generation); the re-read then classified the replacement, so a zombie replacement could let cleanup succeed. A pre-signal check now re-reads only same-generation facts. Changed, exited, exiting and foreign-token facts are final. Each attempt also re-reads the group's owned members instead of one separate refresh after the loop, so a member that moves groups or turns unreadable while another waits is seen within the same bound. The caller's run token selects the owned members, and the sweep keeps classifying current processes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… process (morluto#8553) * fix(process): re-read unreadable tokens before signaling and name the process Darwin KERN_PROCARGS2 samples a process's argument length and stack top before it reads the address space, and exec publishes the new length before it copies the new strings out (xnu sysctl_procargsx, exec_copyout_strings). A read during exec can return a zero-filled or stale strings area, and exec keeps the PID and start time that bracket the read. The final sweep already re-read such tokens, but the pre-signal group check read each member's token once, so one transient read of a live group member failed the whole cleanup. Move the bounded re-read into one shared fact-reading helper and use it for both the sweep and the pre-signal group check. The group check binds re-reads to the generation it first observed, so a reused PID stays unresolved; the sweep keeps classifying the PID's current process. An unreadable-token failure now carries the native identity read after the token and the summary names the candidate by its native name, parent, group and start identity. The Darwin helper and Linux procfs reader report the short native process name (p_comm/comm) for display. Fixes morluto#8337 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(process): refresh other pre-signal members after token re-read waits The pre-signal group check re-read only members whose token was unavailable, so a readable member kept the relation it had before the retry waits. A member that moved to another process group during those waits could be validated on its old group, and the old group signaled while the moved member kept running. After any retry wait, the shared re-read helper now reads every other live pre-signal fact once more with the same generation binding. A moved member then takes the existing changed-group path, which retains its ownership evidence and fails cleanup. An inconclusive refresh replaces the stale fact so it fails closed. Nothing changes when no re-read ran, and the sweep keeps classifying current processes because every group it finds is revalidated before signaling. Also cover PID reuse that happens before the re-read starts, where both re-read identities agree and only the first-read generation rejects the replacement's token. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(process): keep known identity changes final across token re-reads The pre-signal re-read treated a first read without a same-generation identity as unbound and replaced it with the re-read. On Linux the first read can already establish PID reuse (an ESRCH token whose exit check sees another generation); the re-read then classified the replacement, so a zombie replacement could let cleanup succeed. A pre-signal check now re-reads only same-generation facts. Changed, exited, exiting and foreign-token facts are final. Each attempt also re-reads the group's owned members instead of one separate refresh after the loop, so a member that moves groups or turns unreadable while another waits is seen within the same bound. The caller's run token selects the owned members, and the sweep keeps classifying current processes. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
What broke: On macOS, one unreadable
KERN_PROCARGS2token read of a live group member during the pre-signal group check failed the whole owned-command cleanup (malformed_procargs_path_padding). The final sweep already re-reads such tokens, but this check read each token once, and the failure named only a PID.Fix: One shared, bounded re-read (3 × 40 ms, each a full identity/token/identity read) now serves both the sweep and the pre-signal check. In the pre-signal check it is bound to the first observed generation. An unreadable failure now carries the native identity, and the summary names the process (native name, ppid, pgid, start identity).
Risk: Ownership stays fail-closed. A persistently unreadable member still fails, about 150–190 ms later (failure path only). The cleanup summary text gains a per-candidate descriptor, and native identities gain an optional display
name.Summary
Fixes #8337.
npm run verify:packageonNative package baseline (darwin arm64)intermittently failed final cleanup withlive candidates <pid>=malformed_procargs_path_paddingafter a successful command. Cleanup now re-reads a transiently unreadable token before it decides a group. When a member stays unreadable, the failure says which process it is.Problem and expected behavior
sysctl_procargsxcopiesp_argc,p_argslenanduser_stackand then takes the task map. Its own comment says the result can be stale duringexecve.exec_copyout_stringsalso publishesp_argslenbefore it copies the new strings out. So a read during exec can return a zero-filled or stale strings area. Exec keeps the PID and the start time, so the helper's before/after identity check cannot reject that read."executable_path=" + path + NUL, aligned to the pointer size) matchesexec_save_pathandexec_extract_strings. A steady-state scan of 342 local same-user processes found no malformed layouts. Option (a), changing the parser, therefore does not apply.scanWithOwnershipEvidencealready re-read unavailable tokens.processOwnershipFailures(cleanup plan andrevalidateOwnedProcessGroup) took one read, and any unreadable live same-generation member failed cleanup.Change and scope
ProcessOwnershipObservation.reobserveUnavailableTokenFactsis the single re-read owner and replaces the sweep's private loop.current(sweep): classifies whichever process now holds the PID. This is the existing behaviour.first-observed(pre-signal check, given the caller's run token): re-reads only same-generation facts.environment-unreadablefailures carryidentityAfter, the native readable identity. The summary appends(name "…", ppid N, pgid N, identity …)per candidate. Only native facts are shown; process arguments and environment are never included.p_command the Linux procfs reader reportscomm, both as the optional display-onlyname.observeOwnedProcessGroupscapture settlement, which reportsunverifiablerather than failing.com.apple.private.no-read-procargsprocesses (exec path, one NUL, argv[0]). The parser would also reject it aspath_paddingfor 6 of 8 path lengths. No local binary has that entitlement and the macOS 15 source lacks the path, so it is left as a follow-up.Contract and boundary impact
Semantic owner and earliest changed stage: the native identity readers (Darwin helper, Linux procfs) gain
name.ProcessOwnershipObservationowns the token re-reads. Consumers are the sweep and the pre-signal group check inProcessOwnership. The sweep's duplicated loop is removed.Contribution scope fit and linked maintainer decision: not applicable (fix inside existing ownership boundary).
CLI and MCP/tool-catalog contract: no schema or catalog change. The cleanup failure
reasontext gains a per-candidate descriptor. Structuredfailures[]entries gain optionalidentityAfter, which is visible throughprocess_cleanupdetails.Provider, bridge, target-format, or platform compatibility: the Darwin helper response gains optional
name. The helper source digest changes, so the helper cache recompiles once.Evidence, artifact, provenance, or reconstruction contract: none.
Target selection, authority, upstream behavior, and cleanup details: no new signal authority. Every re-read is a full identity/token/identity read. In the pre-signal check a generation change stays unresolved.
Generated metadata, package, or installation impact: none.
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
Tests added or updated:
src/process/ProcessOwnership.tokenReread.test.tscovers:TOKEN_READ_RETRY_ATTEMPTScleaned: truewhile the member runs on)ProcessOwnership.nativeExit(Linux ESRCH): token reads go from 2 to 3. The one extra read happens before exit settles the member.name.name.tests/support/hostCleanup.tsaccepts the descriptor.Base reproduction: with
src/process/ProcessOwnership.tsandsrc/process/ProcessOwnershipObservation.tsrestored fromorigin/main, 7 of 8 original new tests fail. Each review regression fails with only its guard removed, or with the previous helper. The transient case returns exactly the CI summary:process ownership token could not be read for 1 live process(es): malformed_procargs_path_padding=1; live candidates 101=malformed_procargs_path_padding.Root-cause investigation (executed, macOS 26.7.1 arm64):
execvechains and posix_spawned#!/usr/bin/env nodechildren under 8× CPU oversubscription: about 91k execs and 30MKERN_PROCARGS2reads, all parsed by the production parser. It produced transient zero-filled strings (malformed_procargs_executable_path),EIOandEINVAL, each readable again within 17.5 ms. It produced nopath_padding.rea trace <node> fixture --provider hopper --jsonruns (about 670k reads). It saw no malformed reads, and no group members were alive after the leader exited.path_paddingitself is not reproduced locally. CI runs macOS 15.8.2, whose xnu source is not published.User-visible output, from a real Darwin host where a detached
/bin/sleepstays in the group:process ownership token could not be read for 1 live process(es): platform_binary_environment_withheld=1; live candidates 10967=platform_binary_environment_withheld (name "sleep", ppid 1, pgid 10966, identity 1793549013:220807)Lifecycle regressions covered:
Cancellation is not applicable, because cleanup reads run without a caller signal.
Remaining proof gaps: no CI macOS 15.8 kernel behaviour, no
verify:packagerun, no real Linux procfs run (simulated only).Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
npm run test:local -- $(find src/process -name '*.test.ts'): 67 files, 917 passed, 6 skipped (after review fixes).npm run test:local --on the 13 other source tests that use ownership (firmware, apktool, browser, ghidra, application): 218 passed, 9 skipped.npx vitest run --project process-boundarydarwinProcessRunTokenReader,darwinHelperCache,processLineageRetention(real Swift helper compile): 53 passed.ownedCommand,ownedCommandCancellation,processCleanupRetryOwnership,processCaptureLifecycle,processRunTokenEnvironment,verifierCleanup: passed. Rerun after the review fixes together with the Darwin files above: 130 passed, 2 skipped.packageVerifierCommandOwnershipandagentEvaluationCleanup: fail locally on the known Node 26stripTypeScriptTypes(transform) loader crash, before reaching this code.npx vitest run --project process-global(4 ownership and cleanup files): 102 passed.Real-host cleanup timing after the second review round (6 runs, warm helper,
runOwnedCommandwith sweep):Only the failure path costs more. Both versions fail closed; only this PR names the process.
npm run check:fast: pass.npm run format:check: pass.npm run test:local -- tests/conformance/readmeConsistency.test.ts: 9 passed.node scripts/check-doc-facts.mjsandnode scripts/generate-error-schema.mjs --check: exit 0.Not run locally: full
npm run docs:checkandtest:focused, because of the Node 26 crash. CI runs them on Node 24.Compatibility, safety, and release
Author readiness
Human owner: @kaoru0822-kitauji
Before merge
type(scope): outcome.🤖 Generated with Claude Code