Repository navigation
Make an interrupted worktree checkout retryable - #1934
Conversation
Architecture-Review: unchanged; the existing Git path and task-state checks still guard checkout recovery. Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero primary review by claude on 09c806671d51f961be8c6367f93a1b60dc7edb79, 58.9s: approve (0 critical, 0 important, 3 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.
| _git(repo_root, "worktree", "add", "--quiet", "--detach", str(wt), base, graceful_interrupt=True) | ||
| if detached: | ||
| with defer_sigterm(): | ||
| _git(wt, "switch", "--quiet", "-c", branch, graceful_interrupt=True) |
There was a problem hiding this comment.
suggestion: An interrupt inside git switch -c can still leave the slug stuck
git switch -c does two separate things: it creates refs/heads/<branch>, then it updates HEAD. defer_sigterm holds back SIGTERM, but not SIGINT or the 5 s SIGKILL fallback. A Ctrl-C that lands between those two steps leaves the worktree detached while the branch already exists. On retry, _resumable_checkout returns None because _branch_exists(repo_root, expected_branch) is true (line 297). The operator then gets the generic "worktree directory already exists" refusal, which is the stuck-slug problem this change is meant to fix. The same state follows a concurrent branch creation between the up-front _branch_exists check and switch -c. Before this change, worktree add -b failed without creating the directory, so this path is new. The window is small. Smallest fix: in the detached case, accept an existing branch when it resolves to the detached HEAD and no other worktree has it checked out, then finish with git switch <branch> instead of -c. Alternatively, give a specific refusal that says how to recover.
| @@ -99,7 +101,8 @@ def test_start_retries_after_git_creates_worktree(repo, monkeypatch, state): | |||
|
|
|||
| def interrupt_after_add(cwd, *args, **kwargs): | |||
There was a problem hiding this comment.
suggestion: Test helper name no longer matches what it interrupts
interrupt_after_add now interrupts after switch --quiet for every state except detached. Renaming it, for example to interrupt_after_step, would keep the test readable. The helper also recomputes interrupted_step on every call; it could be computed once outside the closure.
| f'kill -INT "$(cat {shlex.quote(str(pid_file))})"; exec sleep 30') | ||
| start = ("import os, sys; from pathlib import Path; from loopzero.cli import main; " | ||
| "Path(sys.argv[1]).write_text(str(os.getpid())); sys.exit(main(['start', 'paused']))") | ||
| command = [sys.executable, "-c", start, str(pid_file)] |
There was a problem hiding this comment.
suggestion: End-to-end interrupt test uses tight subprocess timeouts
Each run of loopzero start (ls-remote, fetch, worktree add, plus up to 5 s of graceful wait when interrupted) must finish within timeout=8. On a loaded CI runner this could time out intermittently, and the error would point at subprocess.TimeoutExpired, not at a real regression. A more generous timeout (for example 30 s) would keep the test meaningful while reducing flakiness.
Architecture-Review: unchanged; checkout recovery still checks the registered worktree against the fetched base. Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero delta review by claude on 85b293bf777905714ad554dfabbc0f21b1713531, 8.7s: approve (0 critical, 0 important, 0 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.
|
@Mergifyio queue |
✅ Merged into
|
|
No description provided. |
Make an interrupted worktree checkout retryable
Context and goal
Closes #1417
Acceptance
Validation
Recorded for
98a065f70317uv 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 0Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Review