Skip to content

Make an interrupted worktree checkout retryable - #1934

Merged
mergify[bot] merged 3 commits into
mainfrom
lean178/1417-checkout-recovery
Nov 26, 2026
Merged

mergify[bot] merged 3 commits into
mainfrom
lean178/1417-checkout-recovery

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Make an interrupted worktree checkout retryable

Context and goal

  • Context: Supersedes #1779 (primary review, delta approval, conflict-only approval). The refreshed change keeps main's Unicode path handling.
  • Problem: Interrupted Git checkout can leave a slug occupied before Loop-zero initializes the task.
  • Goal: Let an operator retry the same slug after a checkout interruption and retain the existing refusals for incompatible worktrees.

Closes #1417

Acceptance

  • Retry the same slug after a real checkout interruption.
  • Resume a completed detached checkout before branch handoff and refuse dirty or moved-base checkouts.
  • Preserve legacy-locale Unicode Git path handling.

Validation

Recorded for 98a065f70317

  • 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

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

Review

Architecture-Review: unchanged; the existing Git path and task-state checks still guard checkout recovery.
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 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.

Comment thread src/loopzero/worktree.py
_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)

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: 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.

Comment thread tests/test_worktree.py
@@ -99,7 +101,8 @@ def test_start_retries_after_git_creates_worktree(repo, monkeypatch, state):

def interrupt_after_add(cwd, *args, **kwargs):

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: 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.

Comment thread tests/test_worktree.py
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)]

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: 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.

@eowca
eowca marked this pull request as ready for review November 26, 2026 15:20
Architecture-Review: unchanged; checkout recovery still checks the registered worktree against the fetched base.
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 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.

@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 f47d7a4 at 15:38 UTC

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

So far

  • ✅ Entered the queue Thu 26 Nov, 15:33 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1972
  • ✅ Merged 15:38 · f47d7a4 · 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

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify
mergify Bot merged commit f47d7a4 into main Nov 26, 2026
12 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1417-checkout-recovery branch November 26, 2026 15:39
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.

Let start retry the same slug after an interrupted Git checkout

1 participant