Skip to content

Promote shared Codex entries without replacing the destination - #1860

Merged
mergify[bot] merged 3 commits into
mainfrom
lean178/1541-no-replace-promotion
Nov 26, 2026
Merged

mergify[bot] merged 3 commits into
mainfrom
lean178/1541-no-replace-promotion

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Promote shared Codex entries without replacing the destination

Context and goal

  • Context: Extra Codex homes promote shared entries into the primary home under the account helper lock.
  • Problem: Codex can create the destination after the helper checks it. A plain rename can overwrite that new entry.
  • Goal: Promote files and directories atomically only when the destination is absent.

Closes #1541.

Acceptance

  • Preserve both entries if the destination appears during promotion.
  • Preserve same-filesystem promotion and mirroring when the destination remains absent.
  • Exercise the actual no-replace operation in the existing account test harness.

Validation

Recorded for 0bbcd8fffd98

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

Review

  • primary, claude, 2caa6ac, request_changes

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Architecture-Review: unchanged; account mirroring retains its lock and layout while refusing concurrent destination replacement.
Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics 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.

loopzero primary review by claude on 2caa6acaa6458180e1631a9594fee3903e50464b, 23.6s: request_changes (0 critical, 1 important, 1 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread scripts/ai-accounts/ai-accounts Resolved

def _rename_noreplace(source: Path, target: Path) -> None:
"""Publish a shared entry atomically, including directories."""
libc = ctypes.CDLL(None, use_errno=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: libc handle and renameat2 lookup are repeated for every entry

ctypes.CDLL(None, use_errno=True) and the renameat2 lookup run on every promoted entry. Resolve them once, either lazily at module level or with functools.cache, and set argtypes/restype (c_int, c_char_p, c_int, c_char_p, c_uint) so the call ABI is explicit and does not depend on ctypes' default int conversion. This also gives one place to decide the unsupported-platform behaviour raised in the other finding.

Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics 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.

loopzero delta review by claude on a6a2a19b89ded73aac7d7b4ff3bf51a4c02661a5, 19.5s: approve (0 critical, 0 important, 2 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

_rename_noreplace(entry, target)
except OSError as exc:
# A competing writer or unsupported no-replace operation leaves the source local.
if exc.errno not in {errno.EEXIST, errno.ENOENT, errno.ENOSYS, errno.EINVAL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Unsupported no-replace silently stops promotion with no warning

If renameat2 is missing (ENOSYS) or the filesystem rejects RENAME_NOREPLACE (EINVAL/EOPNOTSUPP), or the homes are on different filesystems (EXDEV), every shared entry created in an extra home stays local on every sync. Nothing tells the user, so the homes can drift apart permanently while sync appears to succeed. Leaving the entry in place is the safe choice. But these errnos mean the setup can't promote, not that another writer got there first. The smallest fix is to keep swallowing EEXIST/ENOENT silently and print a one-line warning to stderr for the unsupported or cross-device errnos.

Comment thread tests/test_ai_accounts.py
def create_destination(entry, target):
if entry == source:
target.mkdir()
if unsupported:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Unsupported-errno cases only run with a destination that already exists

In the ENOSYS/EINVAL cases, the stub creates target and then raises. So the test never covers the main unsupported scenario: the destination is still absent and promotion fails. In that case the source should stay local and unlinked, and other entries should still be mirrored. Add one case where the stub raises before creating the target, then check that source is still a real directory in the extra home, nothing was created in CODEX_MAIN, and notes is still promoted.

@eowca
eowca marked this pull request as ready for review November 26, 2026 12:04
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🚫 Left the queue · conflict with base branch

4 min in the queue, with no time running CI.

So far

Reason

The pull request conflicts with main

Conflicting files: scripts/ai-accounts/ai-accounts, tests/test_ai_accounts.py

Before this, the pull request was held in the queue behind 2 pull requests ahead of it.

To get back in the queue

  • You should update or rebase your pull request. A pull request in a stack is updated by rebasing the stack onto the branch it conflicts with. A pull request queued by a rule comes back to the queue once updated, as long as the rule still matches.
  • If it was queued with a command, update it, then comment @mergifyio queue to queue it again.

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify mergify Bot added dequeued and removed queued labels Nov 26, 2026
Co-Authored-By: Codex <noreply@openai.com>
@mergify mergify Bot removed the dequeued label Nov 26, 2026

@loopzero-feder-positronics loopzero-feder-positronics 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.

loopzero delta review by claude on 0bbcd8fffd989e1527e5fc2482e0e68c81d088c0, 22.7s: approve (0 critical, 0 important, 1 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Findings without a file location:

  • suggestion: No test for a destination that appears during cross-device promotion — The merge now sends the staged cross-device publish through _rename_noreplace. That correctly changes main's silent return on EEXIST into an EEXIST that the outer handler swallows, and the staged copy is cleaned up. No test covers this path, though. test_account_env_moves_shared_entry_across_devices only covers a successful publish and a failed copy. test_sync_preserves_a_shared_directory_created_during_promotion only covers a same-device rename. If a later change stopped _copy_across_devices from raising EEXIST before entry.unlink()/shutil.rmtree(entry) runs, it would delete the local source after losing the race, and no test would fail. Smallest fix: add an "exists" outcome to the cross-device test that creates Path(main) / entry.name inside the patched copy2. Then assert that the local entry is still a regular file with its original content and that the main entry is unchanged.

Native Claude output is retained in the restricted local review receipt.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as ea6f505 at 12:32 UTC

8 min in the queue, 5 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 12:24 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1880
  • ✅ Merged 12:32 · ea6f505 · squash
3 merge conditions met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = checks
    • check-neutral = checks
    • check-skipped = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = Loop-zero Eligibility
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify
mergify Bot merged commit ea6f505 into main Nov 26, 2026
16 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1541-no-replace-promotion branch November 26, 2026 12:34
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.

Keep Codex account sync from overwriting a concurrently created shared entry

1 participant