Skip to content

fix(#899): create the worktree in /fullsolve, verify it in /exec - #902

Merged
admarble merged 2 commits into
mainfrom
feature/899-bug-fullsolve-exec-the-worktree-is-never-creat
Aug 6, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/899-bug-fullsolve-exec-the-worktree-is-never-creat

Conversation

@admarble

@admarble admarble commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Skill-driven /fullsolve has never had worktree isolation. Three links failed together since #111/#112 (2026-01-17):

  1. /fullsolve claimed /spec creates the feature worktree. /spec never has — and said so, until perf(spec): prompt compression and tiered context — reduce spec skill token cost by ~60% #515's compression deleted the line.
  2. /fullsolve exported SEQUANT_WORKTREE=../worktrees/feature/<issue>-*/ — an unexpanded glob, at three sites.
  3. /exec was instructed to cd $SEQUANT_WORKTREE and skip creation without checking anything.

The cd failed, creation was skipped by contract, and the agent implemented in whatever directory it was already in, on whatever branch was checked out. Single-session runs degraded silently — commits landed, a PR opened, nothing errored — which is how this survived seven months.

A second failure mode compounded it. ../worktrees/ is derived from the parent of the git root, so every repository under the same parent shares one flat namespace, and both lookups keyed on the issue number, which is per-repo and collides constantly. Creation was never the exposed surface (git worktree add onto an existing foreign path fails loudly); resolution was.

Design

One repo-scoped resolver instead of six inline snippets. AC-3 through AC-6 all reduce to "given this repo and this issue, which worktree?" — so that question is answered once, in code, and both skills call it.

New sequant worktree command group:

Command Behaviour
resolve <issue> Prints this repository's worktree path for an issue. Bare path on stdout, so WT="$(…)" captures cleanly.
verify <path> [--issue N] Refuses a path that is missing, foreign, or belongs to another issue.

It reuses listWorktrees() (src/lib/workflow/worktree-manager.ts), which ready.ts:136 already used for this same lookup, gaining an optional cwd parameter. Two properties fall out structurally rather than as filters that can be forgotten:

  • git worktree list only ever reports the current repository's worktrees, so a sibling project's worktree cannot appear at all.
  • It reports the branch, which is the real identity. A directory slug can drift from its branch — 578-seo-expand-city-coverage-to-20-cities already holds feature/578-city-expansion-clean — so a name match proves nothing about which branch you'd land on.

Rejected: inline bash in the SKILL.md files (prose is not executable, so AC-11 could not be tested, and it means six copies across 2 skills × 3 mirrors — the drift class from #871); and a new templates/scripts/*.sh (consumer projects receive those at scripts/dev/, so the documented path would be wrong there).

Everything fails closed. SEQUANT_WORKTREE_NOT_FOUND, SEQUANT_WORKTREE_FOREIGN, SEQUANT_WORKTREE_ISSUE_MISMATCH, WORKTREE_NOT_FOUND, WORKTREE_AMBIGUOUS — every one halts. The bug being fixed was a fail-open one; the fix does not replace it with a lenient guard.

The sequant run CLI path is untouched — it always called ensureWorktree before setting SEQUANT_WORKTREE, which is what /exec's skip branch was originally written against.

AC Verification

AC Description Status Evidence
AC-1 /fullsolve creates the worktree via new-feature.sh ✅ New Phase 1.5 in fullsolve/SKILL.md, region worktree-creation (#899)
AC-2 No globbed SEQUANT_WORKTREE export ✅ All 4 export sites carry "$SEQUANT_WORKTREE"; gated by test
AC-3 /exec halts on non-existent path ✅ SEQUANT_WORKTREE_NOT_FOUND; region worktree-existence-guard (#899)
AC-4 /exec halts on foreign/stale path ✅ SEQUANT_WORKTREE_FOREIGN, realpath-compared against this repo's worktree list
AC-5 Standalone lookup resolves through git worktree list ✅ Region worktree-standalone-lookup (#899); glob appears only inside a "Do not" prohibition
AC-6 Selection keys on branch, not slug ✅ listWorktrees() derives the issue from branch refs/heads/…; test uses a deliberately diverged slug
AC-7 No longer claims /spec creates the worktree ✅ Bullet removed, Phase 1 post-state rewritten, workflow diagram updated
AC-8 /spec states its worktree contract ✅ New "Worktree Contract" section, region spec-worktree-contract (#899)
AC-9 Mirrors carry identical changes ✅ npm run lint:skill-sync → 44 synced, 0 diverged. Note: there are three mirrors, not two — skills/ (the published plugin) alongside .claude/skills/ and templates/skills/. All three updated.
AC-10 Region-scoped skill-text regression test ✅ __tests__/integration/worktree-contract-skill.integration.test.ts — 24 tests (8 × 3 roots)
AC-11 Foreign-worktree rejection regression test ✅ src/lib/workflow/worktree-resolver.integration.test.ts — 11 tests over two real git repos

Mutation results (per CLAUDE.md)

Each gate test was verified by deleting what it asserts and confirming exactly that test fails.

# Mutation Result
1 Reintroduced export SEQUANT_WORKTREE=../worktrees/feature/<issue-number>-*/ in .claude/skills/fullsolve/SKILL.md 1 failed / 23 passed — only exports no globbed SEQUANT_WORKTREE value (AC-2), and only for the mutated root
2 Deleted the worktree-existence-guard (#899) region from .claude/skills/exec/SKILL.md, restoring the bare cd $SEQUANT_WORKTREE 2 failed / 22 passed — exactly guards SEQUANT_WORKTREE existence before use (AC-3) and names the foreign-worktree failure mode (AC-4)
3 Reverted resolveIssueWorktree to globbing ../worktrees/feature/<issue>-* on the filesystem 4 failed / 7 passed — including the headline does not select a sibling repository's worktree that matches the issue-number glob; the verifyWorktreePath block correctly stayed green

All restored; 35/35 green afterwards.

Regions are delimited by <!-- BEGIN: … --> / <!-- END: … --> markers and the extractor throws when a region is absent, so deleting the markers fails loudly rather than reducing the assertion to a vacuous match on "". The AC-2 assertion also floors the export count at 3, so renaming the exports away cannot make it pass by finding nothing.

Test plan

  • npm run build — passes
  • npm run lint — passes
  • npm run lint:skill-sync / lint:skill-calls / lint:skill-gates — all clean
  • npx vitest run on both new files — 35/35
  • Manual CLI smoke of all six paths (resolve hit/miss, verify ok/missing/glob/foreign/mismatch)
  • Full suite: 4966 passed, 18 failed

On the 18: all in semgrep.test.ts, mcp-*.integration.test.ts, and prompt-wait.test.ts — no overlap with worktree resolution. Settled by checking out base d90f82ae in the same worktree and re-running those five files: base produced 2 failed files / 4 failed tests, this branch produced the identical 2 failed files / 4 failed tests (semgrep ×3 pre-existing, plus one rotating flake inside mcp-serve.integration.test.ts — SIGTERM at base, health-check on branch). The extra failures in the full-suite run did not reproduce under a targeted run, i.e. they are concurrency-load artifacts. Pre-existing on main; not introduced here.

Known limitation

listWorktrees() extracts the issue from feature/<N>-… only. new-feature.sh always produces that shape, so sequant-created worktrees always resolve. A hand-named branch (fix/issue-023-…) will not — and that case halts with WORKTREE_NOT_FOUND rather than mis-adopting anything, so it fails safe. Broadening the regex would change ready.ts selection semantics and is deliberately out of scope.

Non-goals honoured

Absorbs #900.


Update — the gap this PR's own review found (#904, now fixed here)

The first pass fixed /exec. The QA re-read then asked whether the same pattern
existed elsewhere, and it did — in five more skills. Rather than ship a
partial fix and a follow-up, all of them are closed here and #904 is absorbed.

Unguarded cd $SEQUANT_WORKTREE — the exact line #899 removed from /exec

Skill Consequence
/qa Reviewed the main checkout while reporting on the feature branch
/loop Writes. Applied fixes and committed them in the main checkout

Both now run the same sequant worktree verify gate and halt on a named error.

Globbing the shared ../worktrees/ namespace

/qa, /loop and /testgen all located worktrees by globbing
../worktrees/feature/<issue>-* — the same cross-repo bug. All three now resolve
through sequant worktree resolve. /testgen matters because it writes test
stubs
: a cross-repo match scatters them into an unrelated project.

Prefix matching on the issue number instead of the branch

The sharpest one. /merger had git worktree list | grep "feature/$ISSUE"
with git worktree remove --force on the very next line — so ISSUE=89
matches feature/899-… and force-removes an unrelated issue's worktree.
Also /qa's Phase 0 implementation probe (a bare-number grep -i gating the
"no implementation found" verdict) and /assess's read-only probe.

Two completeness invariants instead of six pinned assertions

The bug reached six skills by being copied, so pinning the known sites would
not have held. The gate test now asserts, across every skill in every mirror:

  1. Every cd $SEQUANT_WORKTREE sits inside a verify-bearing guard region.
  2. No skill globs ../worktrees/ or greps git worktree list for an issue number.

A newly-added skill that reintroduces either pattern fails the build.

Both are scoped to spare legitimate uses — /assess's grep "^worktree"
enumerates every worktree for diff overlap and keys on nothing, so it is not
flagged. Narrowing that exemption is what surfaced the --porcelain variant in
/merger the first regex had missed.

Additional mutation results

# Mutation Result
4 Removed the worktree-existence-guard region from .claude/skills/qa/SKILL.md, restoring the bare cd 2 failed / 49 passed — the per-skill guard test and the completeness invariant both fired
5 Appended ls ../worktrees/feature/<issue-number>-*/ to /docs — a skill in no pinned list 1 failed / 50 passed — the invariant named docs: as the offender, proving it catches future skills, not just known ones
6 Restored /merger's git worktree list | grep "feature/$ISSUE" 1 failed / 50 passed — named merger: as the offender

All restored; 62/62 green afterwards.

Closes #904 in addition to #899.

Closes #899
Closes #904

Skill-driven /fullsolve never had worktree isolation. Three links failed
together since #111/#112 (2026-01-17):

1. /fullsolve claimed /spec creates the feature worktree. /spec never has.
2. /fullsolve exported SEQUANT_WORKTREE as an unexpanded glob, at three sites.
3. /exec was told to `cd $SEQUANT_WORKTREE` and skip creation without checking.

The cd failed, creation was skipped by contract, and the agent implemented in
whatever directory it was already in. Single-session runs degraded silently;
concurrent ones interleaved checkout/reset/commit in one working tree.

A second failure mode compounded it: ../worktrees/ is derived from the parent
of the git root, so every sibling repo shares one flat namespace, and both
lookups keyed on the issue number, which is per-repo. Creation was never the
exposed surface (git worktree add onto a foreign path fails loudly);
resolution was.

Changes:

- New `sequant worktree` command group. `resolve <issue>` prints this repo's
  worktree path; `verify <path> [--issue N]` refuses a missing, foreign, or
  stale one. Both read `git worktree list` in the current repository, so a
  sibling project's worktree structurally cannot appear, and both select on
  the branch git reports rather than the directory slug — the two already
  diverge in practice (578-seo-expand-city-coverage holds
  feature/578-city-expansion-clean).
- /fullsolve gains Phase 1.5: creates the worktree via new-feature.sh
  (idempotent, safe on resume), resolves the absolute path, exports it. All
  three glob exports replaced. The false /spec claim and the Phase 1
  post-state are corrected.
- /exec verifies before it trusts, halting on a named error rather than
  continuing in place; its standalone lookup resolves through git.
- /spec states its worktree contract explicitly again (dropped by #515).
- All three skill mirrors synced.

Every new failure mode halts: SEQUANT_WORKTREE_NOT_FOUND,
SEQUANT_WORKTREE_FOREIGN, SEQUANT_WORKTREE_ISSUE_MISMATCH,
WORKTREE_NOT_FOUND, WORKTREE_AMBIGUOUS. The bug was a fail-open one; the fix
does not replace it with a lenient guard.

The `sequant run` CLI path is unaffected — it always called ensureWorktree
before setting SEQUANT_WORKTREE, which is what /exec's skip branch was
written against.

Absorbs #900.

Fixes #899
…ust /exec

#899 fixed /exec. The same pattern had been copied into five more skills, each
found by widening the search rather than trusting the first fix.

Unguarded `cd $SEQUANT_WORKTREE` (the exact line #899 removed from /exec):
  - /qa  — reviewed the main checkout while reporting on the feature branch
  - /loop — worse: it WRITES, so it applied fixes and committed them there

Filesystem globbing of the shared ../worktrees/ namespace:
  - /qa, /loop, /testgen — /testgen writes test stubs, so a cross-repo match
    scatters them into an unrelated project

Prefix matching on the issue number instead of the branch:
  - /merger ×2 — `git worktree list | grep "feature/$ISSUE"`, and the next
    line is `git worktree remove --force`. With ISSUE=89 that matches
    feature/899-* and force-removes an unrelated issue's worktree.
  - /qa Phase 0 — `grep -i "<issue-number>"` gated the "no implementation
    found" verdict on a bare-number match
  - /assess — read-only probe, corrected for the same reason

All now route through `sequant worktree verify` / `resolve` from #899.

Rather than pin the six known sites, two completeness invariants close the
class: every `cd $SEQUANT_WORKTREE` in ANY skill must sit inside a
verify-bearing guard region, and no skill may glob ../worktrees/ or grep
`git worktree list` for an issue number. A new skill reintroducing either
pattern now fails the build. The bug reached six skills by being copied, so
pinning known sites would not have held.

Both invariants are scoped to spare legitimate uses: /assess's
`grep "^worktree"` enumerates every worktree for diff-overlap and keys on
nothing, so it is not flagged. Narrowing that exemption is what caught the
`--porcelain` variant in /merger that the first regex missed.

Fixes #904
@admarble
admarble merged commit 46ea323 into main Aug 6, 2026
12 of 13 checks passed
@admarble
admarble deleted the feature/899-bug-fullsolve-exec-the-worktree-is-never-creat branch August 6, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant