Skip to content

fix(worktree): persist isolation origins for agent restore - #670

Open
HaningZS wants to merge 1 commit into
HarnessMD:mainfrom
HaningZS:fix/worktree-origin-restore-298
Open

HaningZS wants to merge 1 commit into
HarnessMD:mainfrom
HaningZS:fix/worktree-origin-restore-298

Conversation

@HaningZS

@HaningZS HaningZS commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #298 by persisting the original repository alongside the actual isolated checkout, then resolving that durable recipe in the shared main-process spawn path.

  • New isolated hires save worktreePath / worktreeOrigin in registry and roster, including voice/orchestrator hires.
  • Team restore, Command Center restart/continue and sleep revival reuse a valid linked checkout, keeping dirty files intact.
  • A missing checkout or a directory containing only .claude/ falls back to the saved origin, returns that corrected cwd to the renderer and clears stale isolation fields. The floor card says worktree gone — using base repo.
  • Existing legacy linked checkouts can infer their origin. A dead legacy checkout with no saved origin fails explicitly with recovery guidance instead of guessing or provisioning into the dead path.
  • A deliberate move to another cwd is not redirected by an old registry entry. A normal repository cannot be registered as a disposable linked worktree.

This chooses the issue's explicitly suggested origin-cwd fallback, not automatic recreation. It never prunes stale registrations, resets/deletes an agent/<id> branch, or removes a leftover directory. Existing unmerged commits remain available for manual recovery. #297's worktree exit policy and #299's CLI session-id capture remain separate concerns (the latter is in #665).

Before

Same 12 regression scenarios against upstream f44b986a production spawn and Restore Team functions: 1 pass / 11 fail. Images render actual node:test output; they are not GUI screenshots.

Restore failures before

After

12 pass / 0 fail. Real Git subprocesses and temporary repositories with spaces, the real HiveManager and RosterStore, and the production main/renderer functions are exercised. The external CLI spawn and React mount are test boundaries, not real model invocations.

Durable restore tests after

Validation

macOS / Node 24.13.0:

Self-review

Provider-neutral path resolution, Node path helpers, and paths-with-spaces tests; no dependencies or permission escalation for agents. Dirty checkout contents, unmerged branch tips and stale Git registrations are explicitly asserted to survive fallback. The shared resolver is before provisioning, so an unknown/missing origin returns an actionable failure without rewriting registry/identity files. No claim of Windows/Linux GUI or real paid CLI session validation; those remain useful follow-up smoke tests.

Why:
- Restart falls back to the missing checkout because the original repository was only in memory (HarnessMD#298).

What:
- Persist and return origin/path for isolated hires, including main-initiated hires.
- Resolve the saved recipe centrally for team restore, restart and sleep revival.
- Reuse dirty checkouts or safely fall back to the saved origin without pruning branches or files.
- Persist the corrected renderer recipe and show an actionable legacy-origin error.

Risk:
- Already-deleted legacy worktrees with no saved origin cannot be reconstructed safely.
- This does not change worktree exit/deletion policy (HarnessMD#297) or provider session identity (HarnessMD#299).

Tests:
- 12 production-function/Git/registry/renderer/roster regressions: red on upstream, green after.
- Full suite with catalog-test PR HarnessMD#669: 977 passed, 1 skipped, 0 failed.
- Independent full suite retains only the known HarnessMD#652 catalog error.
- npm run typecheck and npm run build passed on macOS, Node 24.13.0.

Live Docs:
- Before/after evidence under docs/pr-evidence/worktree-origin-*.png.

This branch has not been deployed

No deployments
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.

Worktree origin is never persisted, so restore falls back to the dead worktree path and agents stay "restorable" forever

1 participant