Skip to content

fix(events): claim the IPC endpoint atomically before removing stale sockets (#209 follow-up) - #216

Merged
ScriptedAlchemy merged 1 commit into
mainfrom
fix/pr209-followup
Sep 1, 2026
Merged

fix(events): claim the IPC endpoint atomically before removing stale sockets (#209 follow-up)#216
ScriptedAlchemy merged 1 commit into
mainfrom
fix/pr209-followup

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Summary

Addresses the unresolved P1 Codex finding on #209 (ipc.ts:287): two concurrently starting runtime processes could both observe a stale endpoint; after the first removed it and bound, the second's unconditional rm(endpoint) unlinked the first's LIVE socket, leaving a running but unreachable server.

Stale cleanup is now guarded by an atomic endpoint claim:

  • An exclusive lockfile (<endpoint>.lock, open('wx')) serializes competing servers; the stale rm and the bind happen only while holding the claim, after a re-probe under the lock (a re-probed live endpoint fails with the existing live-server error instead of being removed).
  • A held claim is awaited with bounded retries (100 × 10ms); an orphaned lock from a crashed process fails closed with a typed, actionable error rather than being stolen — stealing would recreate the exact unlink race this fixes.
  • Claim release is identity-checked (dev/inode), mirroring removeOwnedEndpoint. The win32 path (no unix sockets) is untouched.

A test-only seam (createEventRuntimeServerForTest with an afterEndpointProbe hook) makes the race deterministic.

Tests

  • does not unlink a concurrent winner after both servers probe a stale endpoint — freezes both racers in the historical probe-then-unlink window, lets one win, then asserts the loser fails with the live-server error and the winner still serves requests over its original socket.

Gates: scoped rstest (event-ipc), pnpm typecheck, pnpm lint, full pnpm build — all green.

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4c68b51

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 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-09-01T21:39:05.758606Z 4c68b51 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.

@ScriptedAlchemy
ScriptedAlchemy merged commit 979789c into main Sep 1, 2026
9 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c68b51c1b

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

Comment thread packages/agent-bundle/src/events/ipc.ts
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