Skip to content

fix(events): serialize orphan-claim reclamation behind a kernel recovery gate and treat zombie owners as dead - #247

Merged
ScriptedAlchemy merged 3 commits into
mainfrom
fix/pr229-followups
Sep 2, 2026
Merged

fix(events): serialize orphan-claim reclamation behind a kernel recovery gate and treat zombie owners as dead#247
ScriptedAlchemy merged 3 commits into
mainfrom
fix/pr229-followups

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Summary

Addresses the two unresolved post-merge Codex findings on #229 (round 3 of the endpoint-claim hardening from #216/#229):

  • P1 — TOCTOU in orphan reclamation: two contenders could both judge a claim owner dead; after the first unlinked the stale lock and created its replacement, the second's pending pathname-based rm (stale identity snapshot) could unlink the replacement, yielding dual ownership and live-socket removal. On Linux, reclamation is now serialized behind an abstract-namespace socket recovery gate: acquisition is kernel-atomic, the gate is auto-released on process death (it can never itself be orphaned), and the owner re-verification + identity-matched unlink happen under the gate against a fresh snapshot. Under the gate the lock at the path cannot change between verify and unlink — reclamation removals are excluded by the gate, a provably-dead owner cannot be mid-release, and wx creation needs a vacancy only a gate holder can produce — so the dual-contender window is closed, not narrowed. A gate squatter can only force the existing bounded-retry fail-closed error, preserving the "unverifiable claims remain fail-closed rather than stolen" invariant. Non-Linux POSIX keeps the previous identity-checked removal unchanged (documented: Node exposes no auto-released filesystem gate there); win32 never reaches reclamation (named pipes).
  • P2 — zombies classified as live: process.kill(pid, 0) succeeds for zombies and their /proc/<pid>/stat start time is unchanged, so a died-but-unreaped owner pinned its claim until retries exhausted. The liveness check now parses the process-state field (comm-aware) and treats Z/X/x as provably dead alongside the start-time mismatch.

Tests

All #216/#229 transport and reclamation tests pass unchanged, plus three new deterministic tests:

  • serializes concurrent reclamation before either contender can unlink a replacement claim — both contenders freeze on the same dead-claim snapshot; the winner claims; the loser's later attempt leaves the replacement untouched; end-state has one reachable server.
  • excludes a second orphan-claim remover while the recovery gate is held — freezes the first remover inside the gate after its fresh verify and proves a second full reclamation attempt is denied (removed=false, original dead claim's dev/ino still at the path). This test fails if the gate is ever dropped in favor of just re-reading the snapshot.
  • reclaims an endpoint claim owned by a zombie process — creates a real unreaped zombie (sh -c 'true & echo $!; exec sleep 300'), waits for state Z, and proves its claim is reclaimed.

Scoped gates: event-ipc suite (14/14), pnpm typecheck, pnpm lint — all green.

Use an auto-released Linux kernel gate to prevent delayed orphan cleanup from unlinking a replacement claim, and treat zombie owners as provably dead.
Freeze one remover inside the Linux recovery gate and prove a second contender cannot mutate the visible dead claim.
@changeset-bot

changeset-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 849ed67

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agent-bundle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 2, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle@247
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/create-agent-bundle@247
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/@agent-bundle/runtime@247

commit: 849ed67

@chatgpt-codex-connector

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-09-02T00:03:22.810492Z 3c8335d 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.

Delay the background child's exit until its shell parent has exec'd sleep so dash cannot reap it before the zombie assertion.
@ScriptedAlchemy
ScriptedAlchemy merged commit afe54e2 into main Sep 2, 2026
9 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the fix/pr229-followups branch September 2, 2026 01:20
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.

1 participant