Repository navigation
Bound task-state lock acquisition - #1652
Conversation
Architecture-Review: unchanged; task writers keep their existing lock and fail closed if it stays occupied. Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero primary review by claude on 8771095a742f0dc767b26fc275244cebb214f21e, 36.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.
| assert _closed_unmerged_wait(monkeypatch, reads, steps=1) == final | ||
|
|
||
|
|
||
| def test_task_state_lock_times_out_with_a_live_holder(tmp_path, monkeypatch): |
There was a problem hiding this comment.
suggestion: Acceptance items 'expired contender writes no state' and 'PR refresh stays best-effort' are not exercised by a test
The new test drives _lock_task_state directly. It covers contention, expiry at exactly GIT_TIMEOUT and reacquisition with a real flock and a fake clock, but it never goes through a writer. Both behaviours do hold today. TimeoutError is raised before yield, so _save_report (cli.py:403) never reaches _write_json_atomically. TimeoutError is also a subclass of OSError, so _refresh_pr_checks (cli.py:574) and the review-summary append (cli.py:892) catch it and print a note. Nothing in the tests pins either fact, so a later change to the exception type, such as wrapping it in CliError, could make PR refresh fatal or let a write through without any test failing. Smallest fix: while the outer lock is held, call _save_report(tmp_path, report) and assert it raises and that CHECKS_FILE does not exist. Then call _refresh_pr_checks(tmp_path, config) and assert it returns normally and prints the 'could not refresh PR checks' note.
| except BlockingIOError: | ||
| _sleep(min(0.1, remaining)) | ||
| else: | ||
| raise TimeoutError(f"task state is busy in {wt}; retry when the other command finishes") |
There was a problem hiding this comment.
suggestion: A timeout in cmd_pr after the push leaves the PR body out of date, and the message does not name the command to rerun
At cli.py:704 the lock is taken only after _git_push has succeeded. If the lock times out there, the top-level HANDLED handler (OSError) reports 'task state is busy in ; retry when the other command finishes'. The branch has been pushed, but the PR body still shows the old Validation/Review. Rerunning loopzero pr fixes it because the push is idempotent, but the operator is not told the push already happened or which command to rerun. Optional fix: keep the lock helper generic, catch TimeoutError at the cmd_pr call site, and raise CliError(f"pushed {branch}; PR body not updated: {exc}; rerun loopzero pr").
Architecture-Review: unchanged; the same local state guard still owns receipt and PR-body serialization. Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero delta review by claude on 9d17de4361b71af47572e553e045d73a7658f2e0, 28.4s: 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.
| try: | ||
| if lock: | ||
| fcntl.flock(fd, fcntl.LOCK_EX) | ||
| deadline = time.monotonic() + 60 |
There was a problem hiding this comment.
suggestion: Lock budget is a bare 60 instead of a named operation budget
The task says the lock should reuse the existing 60-second operation budget. Before the merge, the code tied it to cli.GIT_TIMEOUT. Now _local_state_directory hardcodes 60, and the test asserts the literal now == 60. If cli.GIT_TIMEOUT (or sandbox.GIT_TIMEOUT) changes, the lock budget will silently stop matching it. worktree cannot import cli, so the smallest fix is a module constant such as LOCK_TIMEOUT = 60.0 in worktree.py, used in both the loop and the test (now == cli.worktree.LOCK_TIMEOUT).
| if lock: | ||
| fcntl.flock(fd, fcntl.LOCK_EX) | ||
| deadline = time.monotonic() + 60 | ||
| while (remaining := deadline - time.monotonic()) > 0: |
There was a problem hiding this comment.
suggestion: Lock retry loop duplicates the poll-until-deadline pattern
This adds another hand-written loop that waits with time.sleep(min(step, remaining)) until a deadline, alongside the ones in cli.py (~1417) and candidate.py (~499). It behaves correctly. On timeout it raises TimeoutError, which is an OSError, so the best-effort paths at cli.py:584 (PR checks refresh) and cli.py:872 (review summary) still just print a note. Publication at cli.py:709 propagates the error to the operator. A guarded write_local_state (where expected_head is set) also writes nothing on timeout. This is non-blocking. Consider moving the loop into a small _flock_with_deadline(fd, budget) helper, so _local_state_directory stays focused on directory validation.
|
@Mergifyio queue |
✅ Merged into
|
|
No description provided. |
Bound task-state lock acquisition
Context and goal
Closes #1651
Acceptance
Base
main @ f9514c4
Validation
Recorded for
9d17de4361b7uv 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.