Skip to content

fix(codex): preserve shim ownership across APFS reboots - #7061

Merged
lidge-jun merged 2 commits into
devfrom
fix/shim-apfs-persisted-identity
Oct 13, 2026
Merged

lidge-jun merged 2 commits into
devfrom
fix/shim-apfs-persisted-identity

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Fix false ownership refusal after an APFS reboot: compare the private Codex wrapper and shell environment against their persisted inode IDs without requiring the persisted device number to match. Existing schema-2 state remains compatible.
  • Keep device + inode equality for inspection snapshots, namespace checks, PATH activation, staging, publication, rollback and journal binding. Existing private-path, regular-file, owner, permission, wrapper marker/launcher binding, exact environment content and runnable-wrapper checks remain intact.
  • Add regressions for persisted device drift, same-content inode replacement, invalid wrapper/environment content, and device drift during a single inspection. Update the owning runtime contract and English CLI lifecycle documentation; existing translations do not contradict this addition.

Closes #7041

Security review (implementation lane): traced both persisted comparison call sites and their diagnosis/install/auto-repair/uninstall consumers. The only relaxed comparison is saved device versus live device; missing identities, invalid namespaces, different inodes and invalid content still refuse. Journal bindings retain explicit device + inode checks before ownership validation. No credentials, logging, dependencies or execution destinations change. Independent security review remains required before merge under MAINTAINERS.md.

Verification

  • bun install — passed; the changed-test runner installed GUI dependencies on demand.
  • bun test tests/codex-integration/codex-shim-overlay.test.ts --test-name-pattern 'persisted device drift' — before the fix: 4 pass / 1 fail with the reported ownership error; after the fix: 5 pass / 0 fail.
  • bun test tests/codex-integration/codex-shim-overlay.test.ts tests/codex-integration/codex-shim-overlay-transaction.test.ts tests/codex-integration/codex-shim-overlay-readiness.test.ts tests/codex-integration/codex-shim-overlay-candidates.test.ts — 84 pass; the new same-inspection race test reached the correct refusal but expected a narrower error string. Corrected that assertion; all three other files passed.
  • OCX_TEST_NO_QUEUE=1 bun test tests/codex-integration/codex-shim-overlay-transaction.test.ts --test-name-pattern 'device drift within' — 1 pass / 0 fail after the assertion correction.
  • OCX_TEST_NO_QUEUE=1 bun test tests/codex-integration/codex-shim-overlay-transaction.test.ts — 43 pass / 0 fail on the final code.
  • OCX_TEST_NO_QUEUE=1 bun run test:changed — completed against merge base f5f73ff3970b3b238c4e2fade29ba3f64914f637 with the repository's four-worker default: 29,723 pass / 67 skip / 19 fail / 4 errors, exit 1 (327.8 seconds, 1,328 files). The failures are three audio timeouts, one sibling-process timeout, and 15 service-home authority failures; the changed shim regressions passed. The initial bun run test:changed remained queued behind another worktree and was stopped before tests ran. A subsequent OCX_TEST_NO_QUEUE=1 bun run test:changed --parallel=1 was stopped with exit 143 after hitting the Bun isolation performance problem documented in scripts/test.ts; no passing result is claimed for either interrupted attempt.
  • Baseline reproduction on a separate detached worktree at f5f73ff3970b3b238c4e2fade29ba3f64914f637: OCX_TEST_NO_QUEUE=1 bun run scripts/test.ts --parallel=4 tests/cli/cli-access-audio-live.test.ts tests/cli/sibling-home-client-sync.test.ts tests/service/service-sqlite-home.test.ts tests/service/service.test.ts tests/codex-integration/native-codex-toggle.test.ts tests/codex-integration/native-grok-toggle.test.ts — 319 pass / 4 fail / 4 errors, reproducing the same three audio timeouts and sibling-process timeout without this patch.
  • Fresh-process reruns on this PR: OCX_TEST_NO_QUEUE=1 bun test tests/service/service-sqlite-home.test.ts — 5 pass; OCX_TEST_NO_QUEUE=1 bun test tests/service/service.test.ts — 211 pass; OCX_TEST_NO_QUEUE=1 bun test tests/codex-integration/native-codex-toggle.test.ts — 14 pass; OCX_TEST_NO_QUEUE=1 bun test tests/codex-integration/native-grok-toggle.test.ts — 24 pass. Zero failures in all four files. scripts/test.ts already quarantines these files from the parallel full-suite pool because they share default-home service authority; canUseSerialLanes() excludes changed mode, explaining the 15 pool-only service-home failures. No test-runner changes are included here.
  • Additional fresh-process diagnostic reruns: OCX_TEST_NO_QUEUE=1 bun test tests/cli/cli-access-audio-live.test.ts passed; OCX_TEST_NO_QUEUE=1 bun test tests/cli/sibling-home-client-sync.test.ts — 32 pass / 1 fail / 1 error, with the same baseline-reproduced 30-second sibling timeout.
  • bun run typecheck — passed on the final code.
  • bun run structure:check — passed; the owning document remains within its 600-line budget.
  • bun run privacy:scan — passed.
  • cd docs-site && bun install --frozen-lockfile && bun run build — passed: 569 pages, 79,403 internal links checked. Existing unrelated sshconfig highlighting warnings remain.
  • git diff --check — passed. No capped files or new test files were added.

Full bun run test was omitted because multiple concurrent triage worktrees are running tests on this host and changed mode already exercised nearly 30,000 cases. Focused ownership, rollback, replacement, activation and candidate regressions cover this change. The broad changed run is not green: its unrelated failures are documented above with baseline reproduction and fresh-process evidence; required Ubuntu CI remains the broader validation gate. Tests simulate saved device drift rather than performing a physical reboot. This PR is not authorized for merge.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5c03a3b1-833a-4831-ab59-e4c139cb8691
📥 Commits

Reviewing files that changed from the base of the PR and between f5f73ff and 7615a40.

📒 Files selected for processing (5)
  • docs-site/src/content/docs/reference/cli/lifecycle.md
  • src/codex/shim-overlay.ts
  • structure/runtime.md
  • tests/codex-integration/codex-shim-overlay-transaction.test.ts
  • tests/codex-integration/codex-shim-overlay.test.ts
 _________________________________________________________________________________________________
< Question: How does a large software project get to be one year late? Answer: One day at a time! >
 -------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 13, 2026
@lidge-jun

Copy link
Copy Markdown
Owner Author

HOLD: security review required before merge. This PR changes the persisted ownership check for the private Codex PATH shim, which MAINTAINERS.md treats as a security-boundary change, so it is not being merged under the maintainer integration exception.

What it does: the persisted (cross-reboot) wrapper and env ownership check compares the inode without requiring st_dev equality, because APFS renumbers st_dev on reboot (#7041). The path, owner, content and recorded-launcher checks are unchanged, and the snapshot and transaction checks still require device plus inode. CI on head 7615a40 is green.

Reviewer question: is inode plus the content, owner and launcher match strong enough without the volume identity, or should the persisted record use a reboot-stable volume UUID (for example from statfs or getattrlist) instead of dropping the device check?

@lidge-jun
lidge-jun marked this pull request as ready for review October 13, 2026 16:31
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 13, 2026 16:31
@lidge-jun
lidge-jun merged commit 16d36fb into dev Oct 13, 2026
36 checks passed
@lidge-jun
lidge-jun deleted the fix/shim-apfs-persisted-identity branch October 13, 2026 16:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T16:34:24.596425Z 7615a40 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 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: 7615a40a74

ℹ️ 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 src/codex/shim-overlay.ts
Comment on lines +48 to +49
function samePersistedInode(current: OverlayIdentity, recorded: OverlayIdentity | undefined): boolean {
return !!recorded && current.ino === recorded.ino;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain a volume-stable ownership discriminator

When $OPENCODEX_HOME/bin is replaced or mounted from another filesystem after the state was recorded, st_ino is only unique within st_dev, so an unrelated file can have the same numeric inode. This helper now treats that file as persistently owned on every Unix platform; if it contains the shim marker and recorded launcher binding (for example, a copied shim with additional content), install may overwrite it and uninstall may delete it instead of preserving the replacement. Persist and compare a reboot-stable volume/file discriminator, or otherwise scope the device-number relaxation to evidence that cannot collide across filesystems.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant