isolation="worktree" branches from origin/HEAD instead of orchestrator HEAD
Summary
Agent(isolation="worktree", ...) creates new worktrees branched from refs/remotes/origin/HEAD (typically origin/master), not from the orchestrator's current HEAD.
When the orchestrator is on a feature branch ahead of origin/master, every spawned worktree lands on a stale base — commits unique to the feature branch are missing from the worktree's branch ancestry, even though they're reachable in the shared object store.
Reproduction
- Be on a feature branch:
git switch -c my-feature - Make a commit:
touch x && git add x && git commit -m "feature work" - Confirm orchestrator HEAD:
git rev-parse HEAD→<feature-tip> - Dispatch a parallel agent with worktree isolation:
````
Agent(
description="repro",
subagent_type="general-purpose",
isolation="worktree",
prompt="git rev-parse HEAD; git log --oneline -5; git branch --show-current"
)
- Observe agent output:
- Reports HEAD =
origin/mastertip, NOT<feature-tip> feature workcommit is missing fromgit log- Branch name is
worktree-agent-<id>(a new branch, not based on the feature branch)
Expected behavior
The worktree should branch from the orchestrator's current HEAD, so the worktree's branch ancestry includes all commits the orchestrator has made.
Actual behavior
The worktree is branched from whatever git symbolic-ref refs/remotes/origin/HEAD points at — typically origin/master. Feature-branch commits are absent.
Impact
- Forces every consumer (e.g., GSD's
execute-phase.md) to add a remediation block in the agent prompt: capture orchestrator HEAD asEXPECTED_BASE, pass to agent, agent inspects worktree HEAD, hard-resets if mismatch. - The remediation block has subtle bugs of its own — distinguishing "worktree behind orchestrator" (safe to hard-reset) from "truly divergent" (must abort) requires a directional ancestry test (
git merge-base --is-ancestor), not the simplergit merge-base HEAD <SHA>comparison many implementations use. - Even the directional test misclassifies cases where the orchestrator's branch and the worktree's
origin/masterbase have diverged via re-parented or force-pushed history.
A harness-side fix (branch worktrees from orchestrator's HEAD by default) eliminates both classes of consumer bugs.
Workaround
In the consumer's agent prompt, capture orchestrator HEAD before dispatch and have the agent run a directional ancestry test to fast-forward via git reset --hard <orchestrator-HEAD>. Reference implementation: https://github.com/.../get-shit-done/blob/.../workflows/execute-phase.md (post-2026-05-01 <worktree_branch_check> block).
Observed in production
Anthropic GSD M004 autonomous run, 2026-05-01: 4 parallel executors (gsd-executor for plans 50-04, 51-01, 51-02, 51-03) all reported "divergent rebrand lineage" because the orchestrator was 15 commits ahead of origin/master. Without the workaround, each agent fell back to its (stale) HEAD; work landed correctly only because dependency commits happened to be reachable from the older base.
Suggested API
Optionally allow callers to pass an explicit base:
Agent(
isolation="worktree",
worktree_base="HEAD", # default: orchestrator's current HEAD
...
)
Or: branch from orchestrator HEAD by default, with worktree_base="origin/HEAD" as opt-in for the current behavior.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗