Skip to content

Review run: retained worktree with unpushed commits fails and emails on every scheduled pass #1780

Closed

Description

@JacobStephens2

This was generated by AI during triage.

Problem

When a Review run fails in delivery (Step 3) after earlier editing steps (code-review or security-review) have already committed repairs onto the local PR branch, thirdshift rightly preserves the worktree and local branch so work is not lost:

thirdshift: 10:44:44 step delivery: 6m 23s failed: codex exited by signal (delivery; worktree review; codex · gpt-6.1-sol · high)
thirdshift: 10:44:44 cleaning up the worktree and local branch marketing/group-signup-email-card
thirdshift: 10:44:45 warning: retaining checkout /tmp/thirdshift-review-Pn08bZ and local branch marketing/group-signup-email-card at 4fc9a72ac439cabcfb5e0313d62701156cef0cfa: the worktree has unpushed commits

However, when thirdshift review runs on a 2-minute cron (thirdshift review --author hlieberman-bit), every subsequent cron tick selects the same PR (Educational-Travel-Adventures/tourbot#2060), immediately fails preflight in 4–5 seconds:

Result:       failed
Command:      Review run
Repository:   Educational-Travel-Adventures/tourbot
Pull request: https://github.com/Educational-Travel-Adventures/tourbot/pull/2060
Cause:        the local branch marketing/group-signup-email-card differs from origin/marketing/group-signup-email-card
...
Occupied checkout /tmp/thirdshift-review-Pn08bZ on refs/heads/marketing/group-signup-email-card.

and sends the identical failure email every 2 minutes (20261105T104602-0500~X9OSYdV9VrrHr0Vm, 20261105T105001-0500~52PXQsoQPVB9mYxb, etc.) while also preventing the scheduled thirdshift review pass from advancing to any other PRs until a human pauses the cron or cleans up the retained worktree.

Options to weigh

  1. Deduplicate notifications and skip unchanged branch/worktree conflicts during scheduled passes:
    • Record the conflict state (pr_number, branch, local_oid, remote_oid, occupied_worktree) when a Review run (or Pickup run) fails preflight because a local branch or retained worktree differs from origin.
    • On subsequent scheduled discovery passes, if local_oid, remote_oid, and the occupied worktree are unchanged, skip that PR without failing the pass or sending duplicate failure emails every cron tick (similar to Tell the Day shift once when Pickup is held at its Claim limit, with each holder's pull request #959 for Pickup Claim holds), and clear the suppression once either ref or the worktree changes.
  2. Resume or finish delivery from a thirdshift-retained Review worktree:
    • When the occupied worktree /tmp/thirdshift-review-* was retained by a previous Review run on the same PR, its working tree is clean, and its local commits sit directly on top of the current origin/<branch> head (8abc3e0a6..4fc9a72ac), thirdshift itself created those commits during Steps 1–2. A subsequent Review run could either resume at delivery (final validation + push + comment) or push the preserved review commits so the normal continuation path can proceed, instead of treating its own retained review commits as an unknown divergence.

Activity

  1. added
    enhancement
    needs-triage
    on Nov 5, 2026
  2. JacobStephens2 commented on Nov 5, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Agent Brief

    Root Cause & Context

    In src/processes/review.rs (run, lines 15–58), thirdshift review --author <author>:

    1. Queries github.waiting_review_pull_requests(&repo, &author, None)?
    2. Takes a Reservation on the first eligible PR and breaks out of the loop
    3. Calls ReviewProcess::execute (line 133), which creates RunNotification (line 181) and then calls SkillWorktree::on_pull_request(&launch, &snapshot.branch, &snapshot.head) (line 239) → acquisition::add_review (src/worktree/acquisition.rs:23).

    When a prior Review run on that PR died in step 3 (delivery) after code-review or security-review committed fixes locally:

    • SkillWorktree's Drop (cleanup_preserving_work in src/worktree/ownership.rs:167) rightly retains /tmp/thirdshift-review-* and local branch refs/heads/<branch> because HEAD has unpushed commits.
    • Currently, Publication::publish in src/worktree/review_recovery.rs (called from src/worktree/acquisition.rs:62) only writes durable ownership evidence (.thirdshift-review-token + thirdshift-review.json) when branch.is_none() (detached checkouts), not for add_review (SkillWorktree::on_pull_request).
    • On the next scheduled thirdshift review --author cron tick (e.g. every 2 minutes), waiting_review_pull_requests returns the same PR first, acquisition::add_review refuses because local refs/heads/<branch> differs from origin/<branch> and /tmp/thirdshift-review-* is still checked out on refs/heads/<branch>, Reservation is released on drop, RunNotification sends a failure email, and every subsequent cron tick repeats the same failure email while starving any other waiting PRs by that author.

    Agreed Design: Auto-Recover Owned Review Worktrees (Option B) with Skip + Notify-Once Fallback (Option A)

    1. Primary path (Option B): Publish durable ownership evidence for Review worktrees and auto-recover clean, fast-forward retained Review worktrees

    • Record Review ownership on acquisition (src/worktree/review_recovery.rs, src/worktree/acquisition.rs):
      • Extend Record / Publication::publish in src/worktree/review_recovery.rs so add_review (SkillWorktree::on_pull_request) also records durable ownership evidence (.thirdshift-review-token in the worktree root + thirdshift-review.json in the worktree admin dir, with root/admin/common (path, dev, ino) records, branch: Some(branch), captured_head: start, and whether the local branch pre-existed).
    • Auto-recover an owned retained Review worktree on retry (src/worktree/skill.rs, src/worktree/acquisition.rs, src/worktree/review_recovery.rs):
      • When SkillWorktree::on_pull_request(launch, branch, start) sees that refs/heads/<branch> already exists locally and/or is checked out in a registered /tmp/thirdshift-review-* worktree, inspect that registered worktree under the launch worktree lock and refs lock:
        1. Verify thirdshift-review.json and .thirdshift-review-token against the checkout's root, admin, and common directory (path, dev, ino) handles (using the same symlink/inode verification as review_recovery::recover).
        2. Verify the record matches branch and captured_head == start (the PR's current origin/<branch> head).
        3. Verify the checkout is not locked, has no unfinished merge/rebase/cherry-pick, and has no uncommitted tracked or staged changes (uncommitted_changes(..., UntrackedFiles::DiscardValidationArtifacts) is false).
        4. Verify start is an ancestor of the worktree's HEAD (git merge-base --is-ancestor <start> HEAD).
      • When all checks pass:
        • Clean any leftover untracked validation artifacts in the worktree (preserving .thirdshift-review-token and thirdshift-review.json) and adopt the verified Checkout (or in Mode::RecommendOnly, reset to start if needed).
        • In src/processes/review.rs (unchanged_checkout, line 675 / line 289), permit HEAD to be a fast-forward descendant of snapshot.head (merge-base --is-ancestor snapshot.head HEAD) when mode == Mode::Address on a recovered Review worktree so ReviewAndAddress, SecurityReview, and Delivery (push_fixes in src/processes/review/delivery.rs:228, which already checks merge-base --is-ancestor snapshot.head HEAD) can complete and publish the preserved + new commits and post the review comment.

    2. Fallback path (Option A): When a PR's local branch/worktree cannot be auto-recovered, skip it in --author discovery and notify at most once per state

    • If local refs/heads/<branch> or an occupied worktree fails the auto-recovery checks above (e.g., it has uncommitted tracked edits, was created/modified outside thirdshift, or is not a fast-forward descendant of origin/<branch>):
      • Explicit PR target (thirdshift review <pr-url>): Fail loudly and send the RunNotification with recovery advice as today.
      • Author pass target (thirdshift review --author <author> in src/processes/review.rs):
        1. Do not block the queue: Check branch/worktree eligibility during the waiting_review_pull_requests loop so that if one PR is blocked by an unrecoverable local branch/worktree conflict, --author continues scanning later waiting PRs by that author instead of aborting the whole pass.
        2. Notify once per state: Persist a small per-repo suppression record under ~/.thirdshift/ (keyed by (repo, pr_number, branch) with fingerprint (local_head, remote_head, occupied_worktree_path)) when sending the failure notification for a blocked PR during an --author pass. On subsequent --author passes where the fingerprint for that PR is unchanged, log a skip/progress message (progress::step / logs::skipped) and suppress duplicate failure emails. As soon as local_head, remote_head, or the occupied worktree state changes (or the conflict is cleared), clear/update the record.

    Verification & Tests

    • Unit / integration tests in src/worktree/review_recovery_tests.rs & src/worktree/acquisition_tests.rs:
      • Verify that a retained SkillWorktree::on_pull_request checkout with clean committed fixes ahead of start (origin/<branch>) and valid .thirdshift-review-token + thirdshift-review.json is automatically recovered on the next SkillWorktree::on_pull_request(launch, branch, start) call.
      • Verify that a retained worktree with uncommitted tracked edits, a mismatched token/inode, a non-ancestor HEAD, or a human-created local branch is not auto-recovered and still returns the preservation advice.
    • Process / pass tests in src/processes/review.rs (or tests/):
  3. added
    ready-for-agent
    in-progress
    and removed
    needs-triage
    ready-for-agent
    on Nov 5, 2026
  4. JacobStephens2 commented on Nov 5, 2026

    @JacobStephens2
    OwnerAuthor

    Closed by #1787, merged into main by a thirdshift Ticket run with Self-merge.

  5. removed
    in-progress
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions