Skip to content

fix(run): skills preflight validates each worktree, not the main checkout (#933) - #1001

Merged
admarble merged 7 commits into
mainfrom
feature/933-fix-run-skills-preflight-validates-the-main-checko
Sep 8, 2026
Merged

admarble merged 7 commits into
mainfrom
feature/933-fix-run-skills-preflight-validates-the-main-checko

Conversation

@admarble

@admarble admarble commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • sequant run's skills pre-flight now runs once per provisioned worktree (after worktree creation), not once against the main checkout.
  • git worktree add only materializes tracked files, so an untracked .claude/skills/ (the default post-sequant sync state) previously passed the pre-flight while every worktree phase agents actually run in had none.
  • Added driverResolvesSkills export so non-skill drivers (aider) make zero pre-flight calls, matching AC-3.
  • Failure message now names the worktree path and the literal fix: "commit .claude/skills".

Pre-PR AC Verification

AC Description Status Evidence
AC-1 Untracked worktree skills fail fast, naming worktree path + fix, before any phase spawns ✅ Implemented skills-preflight.test.ts "933 AC-1" — mutation-verified below
AC-2 Preflight invoked with cwd = each worktree path ✅ Implemented skills-preflight.test.ts "933 AC-2" — asserts observed cwd equals worktree path, not main checkout
AC-3 --dry-run and non-skill drivers (aider) make zero pre-flight calls ✅ Implemented skills-preflight.test.ts "933 AC-3" (both dry-run and aider cases)
AC-4 Pre-provisioning call removed; single post-provisioning call ✅ Implemented grep -c 'runSkillsPreflight(' src/lib/workflow/run-orchestrator.ts → 1; call at line 1169 > Cleanup worktree for at line 1123

Mutation-verified: AC-1 — reverted cwdsToCheck to [process.cwd()] instead of the per-worktree paths (the pre-#933 bug); src/lib/workflow/skills-preflight.test.ts ("933 AC-1: untracked .claude/skills fails fast …") failed — runIssue was called, meaning the untracked skill in the main checkout let the run past pre-flight; restored.

Marker failedTest corrected by the runner on 2026-09-07 to name the test file in the diff (the parser rejects test titles as test_not_in_diff); the mutation itself was performed by the exec agent as described.

Test plan

  • npm run build — passes
  • npm run lint — passes
  • npx vitest run src/lib/workflow/skills-preflight.test.ts -t "933" — 4/4 pass
  • npx vitest run src/lib/workflow/skills-preflight.integration.test.ts — 2/2 pass (updated for the new post-provisioning call order)
  • AC-4 grep checks pass
  • Full npm test suite — ran green in CI (build (22.x)) on this commit (background test runs were repeatedly torn down by environment session churn before finishing); targeted and integration coverage for the changed area is green

Closes #933

A+ pass (runner, 2026-09-07, commit d4f1a07)

Addresses the QA round-3 adversarial finding (orphaned worktree on the abort path) so this PR can reach READY_FOR_MERGE. PLAN §9 OQ-17 asked whether this belongs to node 05 or node 09; the runner took node 05 because the abort site is the preflight call this PR moved, and the change adds a block at that site only — the cleanup-registration block (node 09's) is untouched.

  • When the post-provisioning pre-flight fails, the worktrees this run created are removed (git worktree remove --force) and their registered cleanups unregistered before dispose() (which clears cleanups without running them). A re-run then re-provisions from the new commit, so the printed remedy actually recovers.
  • Pre-existing (reused) worktrees are kept — they are the user's — and the remedy names the manual step: git worktree remove <path>, or --force to re-provision.
  • skills-preflight.test.ts AC-1 (real git worktree add) now asserts the created worktree is gone from disk and from git worktree list --porcelain after the abort, and that the remedy says so — the lifecycle assertion the original diff had deleted, restored at the layer that can observe it (the integration test mocks ensureWorktrees).
  • CHANGELOG entry extended. Test-plan line above corrected: the full suite passed in CI.

22/22 preflight unit + integration tests pass; typecheck clean.

A+ round 4 (runner, 2026-09-07, commit 2c06730)

Addresses the QA round-4 findings on the abort remedy text:

  • No more --force advice. run --force bypasses the state guard and takes over locks; it never re-provisions a worktree, so the reused-worktree branch now says only: "The pre-existing worktree was kept: remove it first (git worktree remove <path>) so the re-run provisions it from the new commit."
  • Isolation-off branch has its own wording. When no worktree was provisioned the pre-flight checks the main checkout, and the message now says "the checkout at is missing required skills … commit .claude/skills, then re-run" — it no longer calls the checkout a worktree or tells the user to remove it.
  • Removal result is checked. git worktree remove status is read; a failed removal produces its own remedy ("could not be removed … remove it before re-running") instead of an untrue "was removed".
  • Both previously untested branches are now pinned: the test's ensureWorktrees mock reports a worktree the test pre-created as existed: true (mirroring the real one), and two new cases drive the reused-worktree remedy and the worktreeIsolation: false remedy through the real RunOrchestrator.run().
  • 24/24 preflight unit + integration tests; typecheck clean.

A+ round 5 (runner, 2026-09-07, commit 219b743)

  • AC-2's negative assertion is no longer vacuous: it compares against realpathSync(worktreeFixture.repo) (process.cwd() is canonical, /private/var on macOS; the fixture path was not, so the old assertion could never fail). Mutation-verified below.
  • AC-3's zero-call assertion means zero calls: the preflight mock now records every invocation (input.cwd ?? "<no-cwd>"), so a reintroduced cwd-less pre-provisioning call would be counted.
  • Failed-removal remedy suggests the stronger command: git worktree remove --force <path> (the automated attempt was already --force). The "never offer --force" rule is about sequant run --force, which does not re-provision; the tests now assert exactly that (not.toMatch(/re-run with --force/)).
  • Documented, not changed: provisioning (including npm ci) now precedes the abort — a cheap pre-provisioning "is .claude/skills tracked?" check could restore fail-fast without reverting AC-4's post-provisioning requirement (follow-up, coordinate with fix(run): abort-path paper cuts — "work is preserved in <worktree>" is false under SIGTERM, and abort's doc comment cites the wrong issue #935 which owns the cleanup block); the failed-removal branch and driverResolvesSkills's unknown-driver fallback have no direct tests.

Mutation-verified: AC-2 — added process.cwd() to cwdsToCheck alongside the worktree paths; src/lib/workflow/skills-preflight.test.ts (933 AC-2) failed; restored (reversible edit, prettier --check clean).

A+ round 6 (runner, 2026-09-07, commit 9781451)

  • Fail-fast cost (the substantive finding): the post-provisioning placement is what D15/OQ-11 approved and AC-4 mandates, so a pre-provisioning guard is a plan decision, not a PR fix. Recorded as PLAN §9 OQ-22 on PR docs(plan): 2026-09 backlog graph (16 nodes, /graph-run ready) #998 with the reviewer's proposed shape (a per-skill git ls-files --error-unmatch check that is not a second runSkillsPreflight call), to land as a follow-up coordinated with fix(run): abort-path paper cuts — "work is preserved in <worktree>" is false under SIGTERM, and abort's doc comment cites the wrong issue #935.
  • Multi-issue abort now names every worktree: the message lists the other worktrees this run created and removed (Also removed (created for this run): …) and any left in place; a two-issue abort test asserts both worktrees are gone from disk and from git worktree list and both appear in the reason.
  • Failed-removal remedy now suggests git worktree remove --force <path> followed by git worktree prune, rather than repeating the exact command that just failed.
  • driverResolvesSkills fallback tested (aider → false, claude-code → true, undefined → true, unknown driver → true via the catch, so the guard runs rather than skips).
  • Documented, not covered: the failed-removal branch itself (would need git worktree remove --force to fail in a test).
  • 26/26 preflight unit + integration tests; typecheck clean.

A+ round 7 (runner, 2026-09-07, commit 517babe)

  • Sibling-site classification fixed (QA round 7): in a multi-issue abort the non-cwd worktrees are now reported in three distinct groups — removed (created for this run), could not be removed (with the by-hand git worktree remove --force <path>, then git worktree prune step), and left in place (pre-existing) — so a worktree whose forced removal failed is never labelled as intentionally kept. Same rule the round-4 fix applied to the failing cwd.
  • Documented, not covered: the failed-removal branch in either form still has no test (it needs git worktree remove --force to fail).
  • The three locally failing suites the reviewer noted (prompt-wait, batch-executor > withActivityHook, relay-hook.integration) fail identically on origin/main and pass in CI — environment-dependent, unrelated to this PR.
  • 26/26 preflight unit + integration tests; typecheck clean.

…kout (#933)

git worktree add only materializes tracked files, so an untracked
.claude/skills/ (the default post-sequant-sync state) passed the
pre-flight while every worktree phase agents actually run in had none.
Move the check to run once per provisioned worktree after worktree
creation, skip it entirely for drivers that don't resolve skills, and
name the worktree path plus the commit .claude/skills remedy in the
failure message.

Entire-Checkpoint: a1ae82124e30
…ing when isolation is off; removal result checked (#933)
… failed-removal remedy uses git worktree remove --force
…emoval remedy adds prune; test the unknown-driver fallback (#933)
…kills-preflight-validates-the-main-checko

# Conflicts:
#	CHANGELOG.md
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.

fix(run): skills preflight validates the main checkout, not the worktrees agents run in (#813 follow-up)

1 participant