Skip to content

Deepen acquired Worktree execution across Failed run preservation #524

Closed

Description

@JacobStephens2

What to build

A Failed run must preserve work only through the Worktree instance and Issue branch it acquired, including every internal Git retry. When ownership changes after a lock failure, stop before another abort, stage, commit or push can affect that changed checkout. Retain and name the local work through the existing Failed run path.

Deepen the existing private acquired Worktree operation module so ordinary synchronization and Failed run preservation share one execution implementation. Keep the Worktree interface and valid preservation behavior intact.

Acceptance criteria

  • Ordinary synchronization and Failed run preservation use the same private acquired-operation execution implementation. Construction binds matching Git execution, inspection interruption behavior and diagnostic context; preservation no longer orders standalone ownership inspections around raw retrying Git helpers.
  • Inspect acquired checkout, registration, administrative directory, common repository and expected attached Issue branch before and after every preservation subprocess attempt, including internal retries of abort, stage, commit and push. An observed ownership failure prevents further attempts and successful completion. Legitimate commits advancing the acquired branch remain valid.
  • New preservation ownership failures name the acquired checkout and expected Issue branch. Preserve the original Git failure when ownership is still valid, and retain work after an ownership failure even if an earlier action already succeeded.
  • Preserve the existing lock scopes: ordinary operations hold the ownership lock with fetch's internal refs lock; preservation holds ownership then refs locks through the entire salvage sequence and final verification. Waiting after recorded interruption still allows preservation to finish. Release locks on errors and unwinding.
  • Preserve completion behavior without clearing recorded Command interruption. Ordinary synchronization remains interruptible; subsequent ordinary Git still fails after interrupted preservation completes.
  • Preserve merge-abort ordering, staging, last-fetched Base branch comparison without fetching, failure-marker subject and metadata, empty markers for committed work, hook skipping and stored Issue branch push. Boolean probes keep their single-attempt completed-nonzero behavior, including the existing missing-comparison-ref regression.
  • Preserve Worktree's retention transition: arm before salvage and clear only on verified success, including the unchanged-work exit. Errors and unwinding retain the checkout and local Issue branch; a later successful preservation restores cleanup eligibility.
  • Permanent behavior tests reproduce ownership changes after retryable failures at preservation mutations, independently checking abort, stage, commit and push. Assert relevant merge state, index, branch heads, contents, origin refs, diagnostics and retention; verify that valid ownership still permits a retry to succeed. Include recorded-interruption coverage and join every controlled worker by its own handle.
  • Existing Worktree synchronization, preservation, acquisition, cleanup and stale-review regressions remain green. Keep the established Failed run, Merge run and Spec run behavior intact.
  • Clarify the Worktree entry in CONTEXT.md: ordinary synchronization and Failed run preservation share acquired-instance checks through every Git subprocess attempt and retry, and preservation finishes after interruption without clearing it. Retain its acquisition, cleanup, stale-disposal and confirmed Self-merge guarantees. No new domain term or ADR is required.
  • Run focused Worktree and Failed run checks, then formatting, clippy and the full test suite required by the repository. Keep supported Linux and macOS behavior intact.

Blocked by

None (can start immediately).

Decisions

The design tree is settled in four rounds: acquired-instance contract → execution seam and policy → command, probe and failure semantics → tests, documentation and plan size. Each round settles the frontier whose prerequisites the previous rounds supply; no human decision remains.

  1. Round 1 — select this deepening. Recent changes concentrate in Worktree ownership. On main at 535c307, a throwaway regression made the first preservation stage attempt switch to an unrelated branch and return a retryable index-lock failure. Preservation reported an ownership error only after its internal retry had staged both the original work and the unrelated branch's file. The friction is demonstrated through the existing interface, and all open issue titles and bodies were checked: none covers this deepening.
  2. Round 1 — keep the acquired-instance contract. Reuse the existing pinned directory handles, registration/backlink inspection and selected Issue branch; inspect current HEAD rather than the acquisition commit because sessions and Repairs legitimately advance that branch. Scope this change to acquired synchronization and preservation. Acquisition, disposal, stale-review evidence and confirmed Self-merge repository authority retain their existing implementations and policies because they have different lifetime requirements.
  3. Round 2 — deepen the existing private acquired-operation seam. Keep Worktree's caller interface unchanged and move preservation execution behind the same private operation used by synchronization. Raw Git stays inside the execution implementation, with a gated boolean-probe method for preservation. Callers receive neither a reusable validation token nor a raw Git view. This gives locality to authority checks and leverage across both paths. Deletion test: deleting this shared implementation would scatter before/after/per-retry inspection and interruption ordering back across synchronization and salvage commands.
  4. Round 2 — bind execution policy at construction. A private operation's ordinary or preservation purpose selects matching Git execution and inspection behavior plus its contextual ownership diagnostic. Ordinary execution checks Command interruption; preservation uses completion execution for both checkout commands and Launch repository inspection. Binding them together prevents a future change from updating only one and disabling salvage after interruption. The global recorded interruption remains set.
  5. Round 2 — preserve lock ownership and order. Retain pinned-repository checks before locking and full ownership inspection after acquiring the required locks. Ordinary synchronization keeps its ownership lock and fetch's internal refs-lock scope. Preservation keeps ownership then refs locks through abort, stage, comparison, commit, push and final inspection. It never fetches or recursively acquires a lock it already holds. These existing advisory locks coordinate factory operations; the checks do not provide atomic exclusion against arbitrary external writers.
  6. Round 3 — gate each execution attempt. Reuse Git's existing checked run and push helpers so inspection surrounds the first attempt and every lock/ref-contention retry. Gate single-attempt probes before and after execution too. Verify completion even when no commit or push was needed: otherwise a successful no-op could restore cleanup eligibility after ownership changed. The current inspector accepts the new HEAD of a valid failure-marker commit.
  7. Round 3 — retain boolean-probe semantics. The merge-in-progress and cached-diff probes keep their existing single-attempt behavior: completed nonzero is false, while transport or execution failure is an error. A missing comparison ref therefore still produces the failure marker, as its existing regression requires. Use gated single-attempt execution rather than reinterpret a checked command's error as a boolean.
  8. Round 3 — retain preservation policy. Abort an unfinished merge first, stage all work, compare with the last-fetched Base branch, create the same failure marker when required and push the stored Issue branch with hooks skipped. Fetching again or changing marker policy would introduce separate behavior decisions and weaken the existing regression contract.
  9. Round 3 — settle errors and retention. Lost ownership found after a command takes precedence over that command's result, preventing another attempt or successful return; valid ownership preserves the original Git error. Attach preservation context to ownership failures only so established Git diagnostics survive. Worktree keeps its existing retention arm outside private execution and clears it only after verified success. Delivery continues its existing preservation warning and pull request finishing while keeping the original Failed run cause.
  10. Round 4 — keep the interface as the test surface. Tests call Worktree preservation and observe real temporary Git repositories with a local bare origin adapter. The existing isolated Git fault adapter supplies deterministic contention and ownership changes; it already differs from ordinary real Git at this internal seam. No new runtime dependency, remote port or public adapter is needed. Check observable work and authority outcomes rather than private fields, incidental inspection counts or subprocess-read order.
  11. Round 4 — replace duplication while preserving regression coverage. Add focused regressions for ownership changes during retryable abort, stage, commit and push failures and a valid-ownership retry. Existing tests survive because they cross the Worktree interface and cover changed/recreated evidence, successful-push ownership changes, both locks, sibling exclusion, interruption, hooks, no changes and later retry cleanup eligibility. Any helper-only test duplicated by stronger interface coverage can be removed; keep tests that assert a distinct behavior.
  12. Round 4 — record documentation work in this Ticket. Sharpen the existing Worktree definition through the implementation pull request to state the per-attempt preservation guarantee. Introduce no new domain concept. This reversible private refactor implements the existing acquired-instance and completion contracts, contradicts no ADR and needs no new ADR; ADR 0014's review-disposal authority remains separate.
  13. Round 4 — publish one standalone Ticket. The checked execution helpers, inspector, completion mode and local test adapters already exist. The private consolidation and permanent regressions fit one fresh session, with no independent prefactoring slice or blocking edge. The top issue is labelled only needs-triage; thirdshift marks it ready after this review ends.

Review validation: The throwaway regression failed on unmodified main because the preservation retry staged unrelated work. A throwaway prototype routed preservation through the acquired operation with matching completion inspection and Git execution; the regression then passed, and all 138 Worktree tests passed. Both Mermaid diagrams were parsed successfully. Prototype code and its temporary regression are discarded; permanent implementation, tests and documentation are this Ticket's work.

Architecture review

Strength: Strong · Dependencies: local-substitutable

Files: src/worktree/ownership.rs, src/git.rs, src/worktree.rs, src/worktree/preservation_tests.rs, src/worktree/synchronization_tests.rs, CONTEXT.md

Before

flowchart LR
  W[Worktree] --> S[Synchronization]
  W --> P[Failed run preservation]
  S --> O[Acquired Worktree operation]
  O --> I[Ownership inspection]
  O --> G[Git]
  P -. helper checks .-> I
  P -. unguarded retries .-> G
  classDef leak stroke:#dc2626,stroke-width:2px;
  class P,G leak;
Loading

After

flowchart LR
  W[Worktree] --> S[Synchronization]
  W --> P[Failed run preservation]
  S --> O
  P --> O
  subgraph O[Acquired Worktree operation]
    I[Ownership inspection] --> G[Git]
    G --> I
  end
  classDef deep stroke-width:3px;
  class O deep;
Loading

Problem: Failed run preservation duplicates ownership ordering around a shallow Git helper interface whose internal retries bypass inspection.

Solution: Deepen the acquired Worktree operation module so synchronization and preservation share checked execution behind one seam.

Wins

  • Depth: retries stay behind the seam
  • Locality: ownership ordering concentrates
  • Leverage: both paths share execution
  • Tests cross the Worktree interface
  • Existing adapters exercise real retries

Activity

  1. added
    needs-triage
    ready-for-agent
    architect-plan
    in-progress
    and removed
    needs-triage
    ready-for-agent
    on Oct 7, 2026
  2. removed
    in-progress
    on Oct 7, 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

    architect-plan

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions