Skip to content

Prevent unsafe native PID reuse and signalling - #275

Merged
joshyorko merged 6 commits into
masterfrom
fix/issue-269-native-pid-identity
Oct 29, 2026
Merged

joshyorko merged 6 commits into
masterfrom
fix/issue-269-native-pid-identity

Conversation

@joshyorko

@joshyorko joshyorko commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Closes #269

A stale native PID file could identify an unrelated process as MemoryD and cause down or restart to send it SIGTERM. On Linux, the lifecycle binds a per-launch identity to the runtime and acquires a pidfd before checking identity; shutdown signals and waits through that same handle. Unverifiable legacy or malformed live state fails closed. The repository helper uses the same managed lifecycle and rejects older CLI binaries before invoking lifecycle commands.

The numeric PID file is retained, with a private identity sidecar and lifecycle lock. The daemon removes the launch marker from its inherited environment before acknowledging. Linux kernel sender credentials bind that acknowledgment to the captured process; the selected daemon executable is pinned to the running manager image so a wrapper cannot start an untracked daemon. See the getting-started guide for legacy recovery and compatibility. Managed native lifecycle on macOS and other non-Linux platforms deliberately fails closed; foreground serve and container mode remain available.

Reproductions used temporary homes, unused loopback ports and disposable children only:

  • On baseline 79a279d5f730162ad34be9b6410e666ba878a05c, a sleep PID in a legacy file made status report running and down send SIGTERM to that child (exit -15).
  • Sol High review of e70337b5fd5dbe4f60225b186485d37f8607776f reproduced two issues: (1) a wrapper could cause its child daemon to acknowledge for the wrapper, then down returned success while the daemon still served HTTP; (2) FIFO PID or identity files blocked lifecycle commands. Both were reproduced in the cloud worker and repaired in 752fc47617fc73101497ddf42616208f80d0f586. On that head the same wrapper fails before it executes, and FIFO status promptly returns unverified while preserving the FIFO. The sender-credential regression separately proves a descendant cannot acknowledge for the captured process.

Validation on the exact tested head 752fc47617fc73101497ddf42616208f80d0f586:

export PATH=/workspace/.toolchains/cargo/bin:$PATH
export CARGO_HOME=/workspace/.toolchains/cargo
export RUSTUP_HOME=/workspace/.toolchains/rustup
export TMPDIR=/workspace/scratch/issue-269

python3 scripts/run-with-child-reaper.py cargo test --lib native_runtime::native_process::platform::tests -- --test-threads=1
python3 scripts/run-with-child-reaper.py cargo test --test native_pid_safety -- --test-threads=1
python3 scripts/run-with-child-reaper.py cargo test --test native_instance_isolation -- --test-threads=1
python3 scripts/run-with-child-reaper.py cargo test --test cli_smoke cli_status_source_precedence_matrix_is_deterministic -- --test-threads=1
python3 scripts/run-with-child-reaper.py scripts/v0.1-release-gate.sh --artifact-dir /workspace/scratch/issue-269/release-gate-752fc47

All commands passed. The focused suites passed 5 process-handle/identity tests, 14 PID/helper tests, 4 native-instance tests, and the status-precedence test. They cover descendant acknowledgment, both FIFO paths, preservation of state, surviving disposable children, lock reuse, PID reuse, exit before signal, symlink pinning, and normal lifecycle. The full synthetic gate includes all repository tests, formatting, child-reaper checks, doctor, evals and perf. The live dogfood lane was excluded.

Both current-head PR CI jobs passed: Linux release gate, locked release build and lifecycle smoke; and macOS native lifecycle safety.

Independent Sol High re-review completed for 752fc47617fc73101497ddf42616208f80d0f586 with no unresolved safety findings in the reviewed scope. It independently closed both reported reproductions and passed process-handle, PID/helper and native CLI tests, plus symlink/hard-link and old-binary cases, concurrency, persistence/restart, and separate pidfd syscall-denial probes. FIFO PID, identity, and lock cases with absent and connected peers returned promptly, preserved state, left disposable children alive, and left the lock usable. This is review evidence relayed by the integration owner, not a GitHub approval.

Remaining coverage limits: actual kernel PID recycling, older kernels, restricted procfs and crash injection were not exercised in the independent review. Actual macOS fail-closed execution passed in CI; Linux lifecycle CI passed. The documented same-executable CODEX_MEMORYD_BIN restriction and non-Linux managed-lifecycle limitation remain compatibility changes.

The connector review completed on 752fc47617fc73101497ddf42616208f80d0f586 with no findings; its review receipt confirms the reviewed commit. The operator authorized merging after the checks and reviews passed.

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T17:06:04.952904Z 752fc47 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 Review: Didn't find any major issues. Hooray!

Reviewed commit: 752fc47617

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

@joshyorko
joshyorko marked this pull request as ready for review October 29, 2026 17:00
@joshyorko
joshyorko merged commit fea2689 into master Oct 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(native): stale PID files can terminate unrelated processes

1 participant