Repository navigation
Use exclusive staging and safe lock opens for account files - #1849
Conversation
Architecture-Review: unchanged; the account helper retains its state format and lock order. Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero primary review by claude on 4cd3faa32247cbcec55eb23a980f4cd245ffe28d, 24.6s: 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.
| @pytest.mark.parametrize("symlink", [False, True]) | ||
| def test_account_staging_preserves_colliding_path(helper, tmp_path, symlink): | ||
| path = helper.STATE / "status.json" | ||
| staged = path.with_name(f"{path.name}.{helper.os.getpid()}.{helper.threading.get_ident()}.tmp") |
There was a problem hiding this comment.
suggestion: Staging test only checks the old temp-file name, which the new code never uses
The test puts a regular file or symlink at the old status.json.<pid>.<tid>.tmp name. write_private now stages through tempfile.mkstemp(prefix='.status.json.'), so it never touches that path. The test would pass even if the new staging were not exclusive. It works as a regression guard against the old naming, but it does not show that a collision with the actual staging name leaves the existing file intact. Smallest fix: monkeypatch helper.tempfile._get_candidate_names (or mkstemp's name sequence) so the first candidate matches a pre-created file or symlink. Then assert that the update still lands and the collided target still reads "preserve". Alternatively, assert that no .status.json.* residue remains after the call.
| with (STATE / name).open("a") as lock: | ||
| fd = os.open(STATE / name, os.O_RDWR | os.O_CREAT | os.O_NOFOLLOW | os.O_NONBLOCK, 0o600) | ||
| with os.fdopen(fd, "rb") as lock: | ||
| if not stat.S_ISREG(os.fstat(lock.fileno()).st_mode): |
There was a problem hiding this comment.
suggestion: Non-regular lock rejection path is untested
The new S_ISREG check, together with O_NONBLOCK, guards against a FIFO or device at the lock path. No test covers it. Add a short case that creates STATE/.lock with os.mkfifo and expects ValueError from helper._locked('.lock'). That way a later refactor can't quietly drop O_NONBLOCK and let a FIFO hang the open.
|
@Mergifyio queue |
✅ Merged into
|
|
No description provided. |
Use exclusive staging and safe lock opens for account files
Context and goal
Closes #1543.
Acceptance
Validation
Recorded for
4cd3faa32247uv run --group dev ruff check src tests: exit 0uv run --group dev tach check: exit 0uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0scripts/size_budget.sh: exit 0uv run --group dev pytest -q: exit 0Review
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.