Skip to content

P1: Rematerialize a missing worktree from its preserved branch #1400

Closed

Description

@currentbits

Failure path

On origin/main e2924af, prepareThreadWorktree calls clearMissingWorktree when a recorded directory is gone. That function clears both worktreePath and branch and sets pendingWorktree. ensureWorktree then calls setupWorktree, which creates a new branch from the thread's original lead snapshot (or default start for an independent thread). If the old branch still exists, uniqueCoderBranch picks a suffixed name. The new checkout excludes commits made on the old branch.

This can follow an external git worktree remove or app GC of an archived transient worktree after its grace period. GC deliberately preserves branch refs, but the thread loses the ref needed to resume its work. #843 addressed ghost fields in cleanup, not this resume path.

Change

When a missing worktree's recorded branch still exists, rematerialize that branch at its existing tip. Keep the branch until the new checkout succeeds. If the ref is missing or cannot be checked out safely, fail with an actionable error rather than silently starting from an older snapshot. Preserve current behavior for a never-materialized pendingWorktree thread.

Check

A worker commits a file, its clean worktree directory is removed while the branch remains, and the next run recreates a checkout containing that commit on the same branch. A missing branch fails clearly; a fresh worker still starts from leadSnapshotSha; dirty/uncommitted files are not claimed recoverable.

Activity

  1. added
    plan:todo
    on Oct 1, 2026
  2. currentbits commented on Oct 1, 2026

    @currentbits
    OwnerAuthor

    Scope correction: gcClean also clears branch when it removes a worktree. To cover the app-GC case named above, retain the preserved branch ref as thread metadata (or an explicit resume ref) when GC reclaims the directory, then use that ref during rematerialization. clearMissingWorktree covers only directories removed outside the app. Do not infer a ref from the title or pick the latest matching branch.

  3. currentbits commented on Oct 1, 2026

    @currentbits
    OwnerAuthor

    Live-store audit, 2026-10-01: 42 thread records point to missing worktree directories while retaining a branch name. For 17, that branch ref still exists in the owning repo; all 17 branch tips have commits not reachable from the repo's default ref (56 commits total by rev-list default..branch). This does not prove the changes were not squash-merged, but it does show that the current clear-and-recreate path would detach 17 real branch histories from their threads on the next run. The other 25 refs were missing or could not be resolved, so those need a clear failure/recovery path rather than an assumed restart.

  4. currentbits commented on Oct 1, 2026

    @currentbits
    OwnerAuthor

    Behavior split for the 17 existing refs in the live audit: 6 are ordinary threads, whose current rematerialization can create a fresh branch from the default/base and omit the old commits. The other 11 are older orchestration workers with no leadSnapshotSha; after branch is cleared, resolveWorktreeStart refuses to start them at all (MISSING_START_SNAPSHOT). The ticket should restore the recorded ref for both cases. My earlier comment's 56 commits describe branch history at risk of disconnect, not 17 proven silent restarts.

  5. currentbits commented on Oct 1, 2026

    @currentbits
    OwnerAuthor

    Related retention consequence, filed separately as #1404: after GC clears a worker's worktreePath and branch (while leaving Git refs), runner.sweepCrew can purge a finished worker beyond its 20-worker cap because it guards only on worktreePath. Restoring an existing branch in this issue should include a durable branch/landing receipt that also prevents premature worker-thread purging; #1404 owns the retention behavior and regression.

  6. added
    plan:doing
    and removed
    plan:todo
    on Oct 13, 2026
  7. added
    plan:done
    and removed
    plan:doing
    on Oct 13, 2026
  8. currentbits commented on Oct 13, 2026

    @currentbits
    OwnerAuthor

    Landed from Solenta thread "P1: Rematerialize a missing worktree from its preserved bran" (PR #1622). Closed on merge.

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

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions