Skip to content

fix: restore managed worktrees from bare primary repositories - #208922

Merged
vincentkoc merged 2 commits into
mainfrom
fix/worktree-bare-canonical-root
Nov 30, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/worktree-bare-canonical-root

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

When a managed worktree is created from a linked checkout of a bare Git repository, OpenClaw records the bare primary repository as its owner. Cleanup and restore later try to open that recorded path as a checkout. Git rejects it, so a valid worktree can be preserved as a cleanup failure and its snapshot cannot be restored through the same path.

User Impact

Managed worktrees created from these linked checkouts can use the normal removal and snapshot restoration flows. The original registered repository and its fingerprint still have to match where those flows require them.

Why This Change Was Made

Git distinguishes the checkout used to create a worktree from the primary repository that owns it. Resolve stored paths as bare repositories only when the real path equals both Git's primary registration and its common directory. Other registered paths still go through checkout and HEAD validation. Worktree creation continues to require a checkout.

Evidence

  • Reproduced the original failure with a real linked checkout of a bare Git repository and the original resolver.
  • With the changed resolver, the registered bare primary yields the producer's fingerprint. A normal repository keeps its previous identity, a bare creation source is still rejected, and a subdirectory of the bare repository is rejected. The focused fixture exercised real Git with adapters for the surrounding process and timing infrastructure.
  • Added a service regression that creates a managed worktree from the linked checkout, edits a tracked file, removes the worktree, and restores the file through the snapshot.
  • The repository-pinned formatter passed on all eight touched files, and git diff --check passed. The Ubuntu service-test job passed on f19a2a3dea2. The bare-primary recovery regression passed in 5.2 seconds. CI for the published head passed. Its build-artifacts job was skipped. The published revision passed a separate pnpm run build:ci-artifacts build and all 22 canonical-path service tests on macOS.
  • Verified that integrating the current CI repairs leaves the reviewed eight-file patch byte-identical.
  • Independent review and a local ClawSweeper review of the signed range reported no actionable findings. The built CLI created a managed worktree from a linked checkout with a bare primary, removed it without force, and restored its original repository fingerprint and exact edited file contents. The pre-fix CLI reproduced the failure on the same fixture: creation registered the bare primary, then ordinary removal rejected it as not a Git checkout. Both runs used the shipped CLI with isolated state.

Managed worktrees created from a linked checkout record its primary repository. Resolve that registration during inspection, removal, and snapshot restore while keeping new checkout creation strict.
* commit 'c5c1dc278a6f789d739d70afe192c4d1e37058f5': (64 commits)
  fix(ci): include provider rejection text in PR tooling (#208891)
  feat: let plugins bring their own sidebar icon (#208885)
  docs: clarify node pairing and credentials on PostgreSQL gateways (#208850)
  fix(ui): show a confirmed subagent stop once in chat (#208533)
  fix(ui): keep collapsed work close to the reply in long chats (#207843)
  fix(update): finish failed recovery startup records (#208794)
  chore(ci): inventory media worker lifecycles (#208888)
  fix: use the same clock icon for Automations (#208539)
  improve(ci): reduce compiler round trips in database checks (#208878)
  fix(ci): preserve complete adaptive test observations (#208874)
  test(gateway): isolate usage context database fixtures (#208304)
  fix: avoid false worker cleanup failures (#208861)
  fix: let Git upgrade acceptance fetch its missing baseline (#208746)
  fix: isolate scheduled Processes reads in the Control UI config-change test (#208205)
  fix: make plugin hash worker tests independent of runner memory (#208860)
  fix(update): preserve serving state during candidate plugin maintenance (#208776)
  test(ui): preserve exact session keys in older chat links (#208873)
  docs(cli): say what bounds a yielded agent turn's subagent wait without --timeout (#208858)
  test(ui): keep real exports in the channel settings distribution mock (#208855)
  test(normalization): preserve inline code in quoted previews (#208857)
  ...
@vincentkoc vincentkoc self-assigned this Nov 30, 2026
@clawsweeper

clawsweeper Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Pull request received.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Nov 30, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 30, 2026
@clawsweeper

clawsweeper Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR lets managed-worktree recovery resolve a recorded bare primary repository while keeping creation restricted to checkouts.

Example: Create a managed worktree from a linked checkout of remote.git and change README.md to "retained edits\n".

  • Before: Removal or snapshot restoration rejects remote.git because it is not a checkout.
  • After: Recovery accepts the recorded primary repository and restores the saved README.md contents.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, worthwhile repair with distinct regression coverage and no identified defect; available behavioral evidence supports limited runtime confidence.
Proof confidence 🦐 gold shrimp (3/6) This PR is exempt from contributor proof requirements; its body reports a real-Git resolver fixture and adds a service regression, but supplies no inspectable shipped-CLI recovery output.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A valid managed checkout created from a bare repository's linked checkout cannot complete normal cleanup or snapshot restoration.
Reason: Restoring saved work is an existing product contract, and the maintainer-authored repair stays within that contract.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored draft open: it repairs a current repository-resolution mismatch, and no actionable patch defect was found.

Reviewed head: f19a2a3dea241813a3a388e64aebeb651efaf701

Before merge

None.

Findings

None.

Agent review details

How this fits together

The managed-worktree service translates checkout paths and stored repository bindings into Git identities used by creation, cleanup, prewarming, and snapshot recovery.

flowchart TD
  A[Source checkout] --> B[Strict creation resolver]
  B --> C[Managed worktree registry]
  C --> D[Registered repository resolver]
  D --> E[Git primary and common directory]
  E --> F[Cleanup and snapshot recovery]
Loading

Technical review

Best possible solution:

Use the existing repository-path owner to distinguish creation sources from recorded recovery repositories while preserving identity checks.

Do we have a high-confidence way to reproduce the issue?

The producer stores Git's primary root, and current-main recovery passes that root through checkout-only validation; the added real-Git fixture targets this exact path, but no reproduction was executed during this read-only review.

Is this the best way to solve the issue?

The change addresses the shared resolution boundary, updates its registered-path consumers, and preserves strict creation validation without adding state or another identity owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 122cac7d494f.

Provenance checked

  • Repository identity ownership keeps the original intent (6ff24eb: The resolver moved into repository-paths to reduce worker imports while preserving identity results; this PR keeps that owner and calculation.)
  • Checkout validation and paths-only discovery keeps the original intent (ed535c5: Separate paths-only discovery from full identity reads to avoid redundant Git work while retaining fresh identity validation; the repair retains both contracts.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current-main failure boundary: Current main requires --show-toplevel and HEAD validation before resolving repository identity, although creation stores Git's canonical primary root, which can be bare. (src/agents/worktrees/repository-paths.ts:64, 122cac7d494f)
  • Narrow repair and unchanged identity: The introduced resolver accepts the exact primary/common-directory root, otherwise retains checkout validation, and shares the unchanged origin and fingerprint calculation. (src/agents/worktrees/repository-paths.ts:119, f19a2a3dea24)
  • Existing bare-storage support: The source-dependency owner already recognizes a bare primary repository recorded by a linked checkout, so the repaired resolver fits the existing storage contract. (src/infra/git-root.ts:201, f19a2a3dea24)
  • Distinct regression coverage: The added service case creates from a linked checkout of a real bare repository, edits a tracked file, removes the checkout, and checks restored contents and fingerprint. (src/agents/worktrees/service.canonical-paths.test.ts:127, f19a2a3dea24)
  • Existing-state compatibility: The patch changes resolution of existing worktrees.repo_root values without changing their producer, repo_fingerprint calculation, snapshot format, or schema; no data migration is needed. (src/agents/worktrees/repository-paths.ts:69, f19a2a3dea24)
  • Draft and current-head checks: GitHub reports the reviewed head as an open, cleanly mergeable draft; the two named changed-test checks and core lint check succeeded, while other checks remained in progress. (f19a2a3dea24)

Likely related people:

  • Peter Steinberger: Raw commit ed535c5 adds src/agents/worktrees/repository-paths.ts:66 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ed535c56f05d; files: src/agents/worktrees/repository-paths.ts)
  • Vincent Koc: Raw commit b62eec8 adds src/agents/worktrees/service.canonical-paths.test.ts:6 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: b62eec8f6587; files: src/agents/worktrees/service.canonical-paths.test.ts)

PR surface

Source +26, Tests +19. Total +45 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 47 21 +26
Tests 1 19 0 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 66 21 +45

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 30, 2026, 2:04 AM ET / 07:04 UTC.

@vincentkoc
vincentkoc marked this pull request as ready for review November 30, 2026 07:47
@vincentkoc
vincentkoc merged commit a3a38ff into main Nov 30, 2026
319 of 320 checks passed
@vincentkoc
vincentkoc deleted the fix/worktree-bare-canonical-root branch November 30, 2026 08:27
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant