Skip to content

feat(run): pre-flight the skills install — missing .claude/skills/ should fail fast, not flail for 30 minutes as a spec retry #813

Closed

Description

@admarble

Summary

When .claude/skills/ is missing, sequant run provisions a worktree and hands the phase agent a prompt ending "Run the /spec {issue} workflow." (src/lib/workflow/phase-registry.ts:178). The skill does not resolve, the agent spends the whole phase hunting for a command that does not exist, never posts a SEQUANT_PHASE marker, and the runner reports the phase as failed — surfacing as ⟳ Spec phase failed, retrying with 5000ms backoff... (spec retry 1/1).

That message points at transient GitHub flake, which is the registry's own stated reason for spec's retry policy (phase-registry.ts:180-184). The actual cause is a missing directory that doctor already detects in ~5ms.

Field report (downstream project, 2026-07-26)

A project whose .claude/skills/ had been removed — it was never git-tracked there, so an untracked-file cleanup silently deleted it — ran sequant run 115. Observed over ~30 minutes:

  • Phase agent searched ~/.claude/commands/, then find / -path "*commands/exec*", then ToolSearch — never found /exec, never did the work
  • Worktree clean, no commits, no PR
  • sequant doctor in that project reported it plainly: ✖ Skills: Missing .claude/skills/ directory / ✖ Core Skills: Missing skills: spec, exec, qa

Every one of those 30 minutes was spent on a condition detectable before the first worktree was provisioned.

Why the existing global channel does not save you

The sequant plugin was installed at user scope in that environment (the session reached plugin:sequant:sequant for MCP), and the plugin bundles all skills. It still did not resolve /spec for the phase agent. The driver passes settingSources: ["project"] (src/lib/workflow/drivers/claude-code.ts:122, per #19 AC-3), so user-scope and plugin-scope skills are not loaded into the phase session — only .claude/skills/. #711 established the three native discovery scopes; the driver opts into exactly one.

So "install skills globally" is not an available mitigation, and the project-scope directory is a hard runtime dependency for the claude-code driver.

Proposed fix

Reuse the check that already exists. src/commands/doctor.ts:215-234 does precisely this:

const skillsExist = await fileExists(".claude/skills");
// ...
if (!(await fileExists(`.claude/skills/${skill}/SKILL.md`))) {

Run it in run's pre-flight, before worktree provisioning, and fail with the remedy named (sequant sync).

Two constraints worth designing around rather than ignoring:

  1. Driver-scoped. Only the claude-code driver depends on skill resolution. phase-registry.ts carries driverOverrides.aider prompt templates that do the work inline via gh and never invoke a slash command, so the guard must not fire for non-skill drivers.
  2. Check the phases actually being run. Doctor checks the core three. A run with --testgen or --security-review needs those skills too, and a --phases exec,qa run does not need spec.

Acceptance criteria

  • AC-1: sequant run performs a skills pre-flight before any worktree is provisioned, and exits non-zero with a message naming the missing skills and the remedy (sequant sync) instead of proceeding.
  • AC-2: The pre-flight checks the skills required by the phases resolved for that run (including additive phases from --testgen / --security-review), not a hardcoded spec, exec, qa triple.
  • AC-3: The pre-flight is skipped for drivers that do not resolve skills — an aider-driver run with no .claude/skills/ still executes, matching the inline driverOverrides prompts in phase-registry.ts.
  • AC-4: The check reuses doctor's existing logic rather than duplicating the path list, so the two cannot drift.
  • AC-5: A test asserts that a run against a tree with no .claude/skills/ exits non-zero without creating a worktree or writing a state entry.
  • AC-6: Docs note that .claude/skills/ is a runtime dependency and is worth committing, since it is untracked by default in consumer projects.

Related, not in scope

Two further defects surfaced in the same incident. Recording them here so they are not lost; neither belongs in this issue's ACs, and both need confirmation before filing:

  • Runaway self-invocation. 13 extra runs for the same issue were launched 30-60s apart, all phases:["spec"] in an MCP-shaped call rather than the CLI's label auto-detect, all dying at the instant the spec agent was torn down. The shape suggests the flailing agent found the sequant MCP server in its config and began calling sequant_run on itself. This is inference from timing and config shape, not something logged explicitly.
  • False terminal state. .sequant/state.json ended up claiming the issue was ready_for_merge with nextAction: gh pr merge, with no PR in existence.

Both are downstream symptoms of the same root cause, and both would have been prevented by AC-1. If the pre-flight lands first, they may not be independently reachable.

Activity

  1. added
    bug
    cli
    on Jul 26, 2026
  2. admarble commented on Jul 26, 2026

    @admarble
    ContributorAuthor

    Plan (spec) — #813 skills pre-flight for sequant run

    Complexity: Standard (6 ACs, 4 directories)

    Scope Assessment

    Metric Value Status
    Feature count 2 ⚠️
    AC items 6 ⚠️
    Directory spread 3 ⚠️

    Verdict: ⚠️ SCOPE_WARNING (quality loop will be enabled). Non-Goals are effectively present as the "Related, not in scope" section.

    Acceptance Criteria

    • AC-1: Skills pre-flight before worktree provisioning; non-zero exit naming missing skills + sequant sync remedy — Integration Test
      • Given no .claude/skills/ → When sequant run <N> → Then exit 1, message lists missing skills and sequant sync, no worktree created
    • AC-2: Checks skills for the phases resolved for that run (incl. --testgen/--security-review), not a hardcoded triple — Unit Test
      • Given --phases exec,qa → only exec/qa skills required; given --testgen → testgen skill required
    • AC-3: Skipped for non-skill drivers (aider) — Unit Test
      • Given agent: "aider" and no .claude/skills/ → run proceeds past pre-flight
    • AC-4: Reuses doctor's logic (single source for the .claude/skills/<skill>/SKILL.md path check) — Unit Test + code review
    • AC-5: Test: run against a tree with no .claude/skills/ exits non-zero, no worktree, no state entry — Integration Test
    • AC-6: Docs note .claude/skills/ is a runtime dependency worth committing — Manual Test (docs review)

    Implementation Plan

    Phase A — shared check (AC-4)

    1. New src/lib/skills-check.ts: checkSkills(requiredSkills: string[]): Promise<{ skillsDirExists: boolean; missing: string[] }> using fileExists from lib/fs.ts — the one place that knows the .claude/skills/<skill>/SKILL.md layout.
    2. Refactor doctor.ts Checks 2+3 (lines 214–250) to call it, preserving output text.

    Phase B — driver capability (AC-3)
    3. Add resolvesSkills: boolean to the AgentDriver interface (drivers/agent-driver.ts); ClaudeCodeDriver → true, AiderDriver → false. Aider's phases run inline driverOverrides prompts and never invoke slash commands.

    Phase C — pre-flight in the orchestrator (AC-1, AC-2)
    4. In RunOrchestrator.run() after the issueInfoMap fetch and before ensureWorktrees (~line 963–970 today): skip when config.dryRun or !getDriver(config.agent, …).resolvesSkills; otherwise compute the union of per-issue phases:

    • explicit mode: determinePhasesForIssue(config.phases, labels, {testgen, securityReview})
    • auto-detect mode: detectPhasesFromLabels(labels).phases + the same additive flags
    • plus loop when the quality loop is enabled (its skill is invoked the same way)
    1. Map phases → phaseRegistry.get(phase).skill, call checkSkills, and on any missing: print ✖ Missing skills: <list> — run \sequant sync`and return a syntheticRunResultwithexitCode: 1(same pattern as the #762--strict-preflight` abort), before any worktree or per-issue state write.

    Phase D — tests + docs (AC-5, AC-6)
    6. Tests: unit tests for skills-check.ts and phase→skill resolution; integration test asserting exit-non-zero + no worktree + no .sequant/state.json entry on a skills-less tree; aider-driver bypass test.
    7. Docs: README + docs/getting-started/installation.md + docs/troubleshooting.md — .claude/skills/ is a hard runtime dependency of the claude-code driver (settingSources: ["project"], #19/#711), commit it; remedy is sequant sync.

    Design Review

    1. Where does this logic belong? The path-layout check in a new lib/skills-check.ts (shared by doctor + run). The gate itself in RunOrchestrator.run() — so MCP-initiated runs (sequant_run) get the same protection as the CLI, which matters given the incident's runaway MCP self-invocations.
    2. Simplest correct approach? Reuse fileExists checks; no new config. Rejected: duplicating doctor's loop in run.ts (drift, violates AC-4); running full doctor in pre-flight (too broad, pulls version checks into every run).
    3. Existing pattern? The feat: lightweight content pre-flight for --chain (AC presence, dependency-order sanity) #762 chain-content pre-flight: check before provisioning, abort with synthetic RunResult. This one is fatal-by-default (a missing skill can never succeed, unlike chain warnings).
    4. Senior-reviewer challenge? "Auto-detect mode can still pick up a spec-recommended phase (parseRecommendedWorkflow) whose skill is missing." Accepted gap: unknowable pre-run; the realistic failure (whole directory missing) is fully covered because spec/exec/qa are always in the resolvable set.

    Open Questions

    1. Also require loop skill whenever quality loop is enabled? Recommendation: yes (cheap, same failure mode). Impact if wrong: one extra name in the required set for consumers who disabled nothing.

    Recommended Workflow

    Phases: spec → exec → qa
    Quality Loop: enabled (scope warning)
    Reasoning: CLI-only change, no UI labels → no browser test. Testgen skipped: bug label and AC-5 already prescribes the exact test to write.

  3. added
    planned
    on Jul 26, 2026
  4. admarble commented on Jul 26, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #813

    AC Coverage

    AC Description Status Notes
    AC-1 Pre-flight before worktree provisioning; non-zero exit naming missing skills + remedy MET End-to-end smoke in a skills-less repo: ✖ Skills pre-flight failed: missing .claude/skills/ directory (needs: exec, qa) + run \sequant sync`, exit code 1, no worktree, no .sequant/state.json`
    AC-2 Checks skills for the phases resolved for that run, not a hardcoded triple MET resolveRequiredSkills unit-tested: --phases exec,qa requires only exec/qa (smoke confirmed: "needs: exec, qa"); --testgen/--security-review add their skills; UI labels add test; quality loop adds loop; auto-detect resolves per-issue label pipelines
    AC-3 Skipped for non-skill drivers MET AgentDriver.resolvesSkills (claude-code true, aider false). Integration test: aider run on a skills-less tree reaches worktree provisioning and executes; unit test covers the gate
    AC-4 Reuses doctor's logic — no path-list drift MET New shared src/lib/skills-check.ts owns the .claude/skills/<skill>/SKILL.md layout; doctor Checks 2+3 refactored to consume it (doctor.ts no longer contains the path literal); doctor's 34 tests pass unchanged
    AC-5 Test: skills-less tree → non-zero exit, no worktree, no state entry MET skills-preflight.integration.test.ts asserts exitCode 1, ensureWorktrees never called, no ../worktrees/ on disk, no state entry, no phase executed
    AC-6 Docs note .claude/skills/ is a runtime dependency worth committing MET README (install section), docs/getting-started/installation.md (directory structure), docs/troubleshooting.md (new "Skills pre-flight failed" entry with both remedies)

    Coverage: 6/6 AC items fully met

    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 16 (+651/−11) OK — proportional to 6 ACs, ~1.9:1 test:impl ratio
    Security scan 0 critical / 0 warning OK
    Build / Lint Pass / Pass (0 warnings) OK
    Full test suite 198 files, 4120 passed OK

    Execution Evidence

    Test Command Result
    Happy path (fail-fast) sequant run 1 --phases exec,qa in repo with no .claude/skills/ ✅ Exit 1, names missing skills + remedy, no worktree/state
    Remedy loop sequant sync (built CLI) then re-run ✅ Skills installed, pre-flight passes, run proceeds
    Doctor regression doctor test suite (34 tests) ✅ Pass — output text unchanged after refactor

    Evidence status: Complete

    Risk Assessment

    • Likely failure mode: In auto-detect mode, a phase recommended later by /spec output (parseRecommendedWorkflow) isn't knowable at pre-flight time, so a missing skill for a spec-recommended-only phase (e.g. testgen) could still flail. Accepted gap documented in the plan — the motivating incident (whole directory missing) is fully covered since spec/exec/qa are always in the resolvable set.
    • Not tested: --batch multi-issue pre-flight union is covered by unit tests only (no end-to-end batch smoke). Chain mode shares the same single call site before both ensureWorktrees* branches.
    • Sibling sites considered: remaining .claude/skills literals in templates.ts/init.ts (installers), skill-version.ts (version markers), merge-check/types.ts (mirror map) are different concerns, not install-presence checks; no drift risk with doctor/pre-flight. skill-version.ts:51 keeps its own installedDir literal — could adopt SKILLS_DIR as a trivial follow-up, not blocking.
    • Sibling-line audit: single insertion point in run-orchestrator.ts, placed before both the chain and non-chain worktree provisioning branches — no other provisioning paths exist in run().

    Adversarial Re-Read

    Findings: No gaps found because: (1) the issue's verbatim fixture (doctor's fileExists snippet) is now literally the shared code path — doctor imports checkSkillsInstalled rather than the pattern being re-implemented; (2) all evidence above is post-fix validation (smoke of the new failure path AND the sync-remedy loop), not bug reproduction; (3) process state inspected — worktree clean, branch pushed, no divergence; (4) sibling sites cited above; (5) the issue's "Related, not in scope" items (runaway MCP self-invocation, false ready_for_merge state) were kept out of scope — no changes touch state reconciliation or the MCP server. One observation while validating the remedy: running sync from source via tsx resolves getTemplatesDir() one level too high (calibrated for dist/src/lib), so a source-tree sync silently installs nothing — pre-existing, dev-invocation-only, unrelated to this diff; noting rather than filing since consumers run the compiled CLI.

    Status: Clean

    CHANGELOG Verification

    [Unreleased] → ### Added entry present for #813, follows house style. ✅

    CI Status

    No PR exists yet — CI will run on PR creation (fullsolve Phase 5).

    Verdict: READY_FOR_MERGE

    All 6 ACs met with literal verification, execution evidence complete including the full remedy loop, quality gates green (build, lint, 4120 tests), docs and CHANGELOG in place.

  5. admarble commented on Jul 26, 2026

    @admarble
    ContributorAuthor

    /fullsolve Complete

    Issue: #813
    Status: READY_FOR_MERGE

    Summary

    • AC: 6/6 met (see QA review above for literal verification + execution evidence)
    • Tests: 4120 passed across 198 files (17 new tests for this change); build + lint clean
    • QA: READY_FOR_MERGE on first pass — includes an end-to-end smoke of both the fail-fast path and the sequant sync remedy loop

    Key changes

    • src/lib/skills-check.ts — shared .claude/skills/<skill>/SKILL.md check, consumed by both doctor and the new pre-flight
    • src/lib/workflow/skills-preflight.ts — resolves required skills from the run's actual phases; RunOrchestrator.run() aborts with exit 1 + remedy before any worktree/state write
    • AgentDriver.resolvesSkills — claude-code gates on the pre-flight, aider bypasses it
    • Docs: README / installation / troubleshooting now flag .claude/skills/ as a runtime dependency worth committing

    Iterations

    Phase Iterations Status
    Spec 1/1 Complete
    Exec 1/3 Complete
    Test — Skipped (no UI labels)
    QA 1/2 Complete (READY_FOR_MERGE)

    PR: #821


    Ready for human review and merge.

  6. added
    ready-for-review
    on Jul 26, 2026
  7. added a commit that references this issue on Jul 27, 2026
  8. added a commit that references this issue on Jul 27, 2026
  9. added 2 commits that reference this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcliplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions