Skip to content

fix(run): spec runs in the main checkout, which the skills pre-flight never checks — a stale checkout silently degrades spec (#933 regression) #1193

Closed

Description

@admarble

Epic: field-2026-09-28 (downstream non-Node adoption) Tier: judgment Graph: tracker #1203

Problem. Spec is requiresWorktree: false (phase-registry.ts:173-179, phase-executor.ts:1445), so it runs in process.cwd(). #933 AC-4 moved checkSkillsInstalled to the provisioned worktrees (run-orchestrator.ts:1161-1170). It assumed the main checkout was "the one directory guaranteed to have skills". Worktrees are cut from a freshly fetched origin/<base>, so they pass the check. Meanwhile spec runs in a checkout nobody checked.

Field evidence. A downstream main checkout was 21 commits behind origin/master, and its working tree had no .claude/skills/spec/, though the default branch did. The pre-flight passed. The spec agent could not load /spec, wrote a plan by hand from the phase prompt ("Review GitHub issue #N and create an implementation plan…"), and the phase was recorded as success.

Why it passes silently. mapAgentSuccessCore has output guards for qa (needs a verdict) and exec (needs a diff), but none for spec. Nothing checks that the skill loaded.

Options (not prescribed). (a) Check the skills in cwd for every phase with requiresWorktree: false. (b) Run spec in the worktree the batch executor already passes. (c) Warn or fail when the main checkout is not on the base branch or is behind origin/<base>.

AC

  • AC-1: A run whose main checkout lacks .claude/skills/spec/SKILL.md fails pre-flight before spec starts, naming the missing path. Evidence: npx vitest run src/lib/workflow/skills-preflight.test.ts
  • AC-2: A spec phase that produced no SEQUANT_SPEC marker (the one the spec skill emits, parsed by spec-recommendation.ts) is recorded as failed, not success. Evidence: npx vitest run src/lib/workflow/phase-executor.test.ts
  • AC-3: When the main checkout is behind origin/<base>, run prints a warning naming the commit count before spec starts. Evidence: npx vitest run src/lib/workflow/run-orchestrator.test.ts

Related: #813, #933, #899.

Graph metadata

May touch

  • src/lib/workflow/run-orchestrator.ts
  • src/lib/workflow/skills-preflight.ts
  • src/lib/skills-check.ts
  • src/lib/workflow/phase-executor.ts
  • src/lib/workflow/spec-recommendation.ts

File overlap (don't run in the same wave; merge one first):

Activity

  1. added
    bug
    spec
    graph-2026-09-field
    on Sep 28, 2026
  2. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Runner context (graph-run, tracker #1203, wave 1) — read before planning. Applies to the spec, exec, and qa phases by name.

  3. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 2 directories)

    AC Quality Check

    • ⚠️ The parser extracts 0 ACs from this issue body. The lines are written - AC-1: … with no checkbox. extractAcceptanceCriteria needs - [ ] **AC-1:** …. As written, /qa §6h/§6i see no ACs and enforce no Evidence:. Fix before exec: rewrite the three lines as - [ ] **AC-N:** …. The normalized form parses as 3 ACs (all unit_test) and is stored in .sequant/state.json.
    • ⚠️ All three Evidence: commands are vacuous today. Run on base 713f4f72, they pass: skills-preflight 27/27, phase-executor 181/181, run-orchestrator 5/5. Each one gates only through the new test case it will contain, so every AC needs a SEQUANT_MUTATION record whose failedTest starts with the test file path.

    Scope Assessment

    Non-Goals: ⚠️ No ## Non-Goals section. Proposed: moving spec into the worktree (option b), and changing verify/merger behavior beyond the shared check.

    Metric Value Status
    Feature count 1 ✅
    AC items 3 ✅
    Directory spread 2 (src/lib/workflow, src/lib) ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: Main checkout missing .claude/skills/spec/SKILL.md fails pre-flight, naming the path

    Verification: Unit Test (skills-preflight.test.ts)
    Scenario: Given worktree isolation is on, the worktrees have every skill, and cwd has no .claude/skills/spec/SKILL.md → When the pre-flight runs → Then it returns ok:false with a message containing .claude/skills/spec/SKILL.md, and no spec phase starts.
    Assumptions: Today's cause names skills (missing skills: spec), not paths. It needs a path list.

    AC-2: A spec phase with no SEQUANT_SPEC marker is recorded as failed

    Verification: Unit Test (phase-executor.test.ts, mapAgentSuccessToPhaseResult)
    Scenario: Given a spec agent result with success:true and no marker → When mapped → Then success:false, with an error naming the missing marker.
    Assumptions: ⚠️ Real run logs don't store the chat output, so I couldn't confirm the marker shows up in agentResult.output. Only 3 of the last 20 spec-bearing logs recorded specRecommendation.source at all: 3 marker, 1 label-fallback. See OQ-1.

    AC-3: Warn when the main checkout is behind origin/<base>

    Verification: Unit Test (run-orchestrator.test.ts)
    Scenario: Given the main checkout is N commits behind origin/<base> and the run includes spec → When run starts → Then a warning naming N prints before spec starts.

    Implementation Plan

    Phase 1: Main-checkout skills check (AC-1)

    1. In skills-preflight.ts, have the result carry missingPaths (.claude/skills/<skill>/SKILL.md) alongside missingSkills, and add a phaseFilter/requiresWorktree selector. The main checkout is checked only for resolved phases with requiresWorktree: false (spec, verify, merger). Worktrees keep today's full check.
    2. In run-orchestrator.ts, run the main-checkout check before worktree provisioning (~L1100), so a failure leaves nothing to clean up. Its remedy must differ from the worktree one: git pull / sequant sync in the main checkout, not "commit .claude/skills". If isolation is off, the existing [process.cwd()] path already covers this, so don't check twice.

    Phase 2: Spec output guard (AC-2)

    1. In mapAgentSuccessCore, add a phase === "spec" branch. It fails when no <!-- SEQUANT_SPEC: {…} --> is present, reusing SPEC_MARKER_REGEX exported from spec-recommendation.ts so there's no second regex. Apply it only to skill-resolving drivers: aider's spec promptTemplate never asks for a marker, so this guard would fail every aider spec. Pass a flag from executePhase, or add the marker line to the aider template (OQ-2).
    2. Update the existing spec cases in phase-executor.test.ts whose fixtures lack a marker.

    Phase 3: Behind-base warning (AC-3)

    1. Extract a non-fetching countCommitsBehind(cwd, baseBranch) from checkWorktreeFreshness (worktree-manager.ts:229-300, the merge-base..origin/<base> count). ensureWorktrees has already fetched, so reuse it rather than adding a second 30s fetch.
    2. In run-orchestrator.ts, warn main checkout is N commits behind origin/<base> — spec runs there when N>0 and any resolved phase has requiresWorktree:false. Skip on --dry-run. Warn only, never fail.
    3. Docs: add a line each to docs/reference/run-command.md and docs/troubleshooting.md, next to the existing skills pre-flight text.

    Design Review

    1. Where does this belong? Pre-flight logic goes in skills-preflight.ts, with the orchestrator only wiring it. The output guard goes in mapAgentSuccessCore next to the qa/exec guards.
    2. Simplest correct approach? Options (a) + (c) as the ACs specify. Rejected (b), running spec in the worktree: /spec's Worktree Contract (bug(fullsolve/exec): the worktree is never created and never verified — skill-driven runs execute in the main checkout, or in another repo's worktree #899) plans in the main checkout, and verify/merger share requiresWorktree:false, so (b) fixes one of three phases and still leaves the check gap. This plan picks between designs, so the exec PR includes a short ADR in docs/adr/ (next NNNN).
    3. Existing pattern? The fix(run): skills preflight validates the main checkout, not the worktrees agents run in (#813 follow-up) #933 per-cwd pre-flight loop, and the fix(orchestrator): treat null QA verdict and zero-diff exec as failure, not success #534/fix(run): exec that leaves work uncommitted reports success and the run passes with no PR — #534's empty-branch escape, reopened via a new route #879 "no deliverable ⇒ not success" guards.
    4. Senior pushback: "A marker in a comment is the durable channel (fix(run): spec recommendation handoff parses ephemeral chat text — recommended phases silently dropped; move the contract to a structured comment marker #921). Why check chat output?" Because mapAgentSuccessCore is sync and has no comment timestamps, and a scan of comments would pass on a stale marker left by an earlier spec. See OQ-1.

    Feature Quality Planning

    Open Questions

    1. Marker source for AC-2. Recommendation: pass if the marker is in agentResult.output. Otherwise fall back to the issue's comments, but accept a marker only from a comment created after the phase started (gh api …/comments with created_at). Impact if wrong: output-only could false-fail specs that posted via a body file and ended on a short summary (fix(sync): plain sync overwrites CUSTOMIZABLE_FILES (constitution) — copyDir ignores force and never consults isCustomizableFile #814). Comments-only accepts stale markers.
    2. aider spec. Recommendation: exempt non-skill drivers from the guard, rather than adding a marker line to aider's template. Impact: without an exemption, every aider spec fails.
    3. Main checkout on a non-base branch (option c, first half). Recommendation: out of scope. Counting against merge-base already covers the field case.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Three targeted unit-test ACs in files that already have test suites, so testgen stubs add little. Mutation records are the gating artifact.

    Label Review

    Current: bug, spec, graph-2026-09-field · Recommended: + planned

  4. added
    planned
    on Sep 29, 2026
  5. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    QA Verdict: NEEDS_VERIFICATION

    AC coverage: 3/3 met

    Gaps:

    • Required CI test check has not reported yet
    • A re-run on an already-specced issue where the spec skill self-skips emits no fresh marker; the guard (correctly excluding the stale one) fails spec and halts the run
    • Behind-base warning not tested on the worktree-isolation path
  6. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Runner verification (graph-run #1203, wave 1) — QA verdict was NEEDS_VERIFICATION; this discharges it against PR #1211 @ 418cda11.

    Executed in the worktree:

    • AC-1/2/3 evidence commands: npx vitest run src/lib/workflow/skills-preflight.test.ts src/lib/workflow/phase-executor.test.ts src/lib/workflow/run-orchestrator.test.ts src/lib/workflow/skills-preflight.integration.test.ts → 4 files, 225/225 passed.
    • Mutation, AC-2: disabled the spec-marker guard condition in mapAgentSuccessCore (type-preserving) → exactly phase-executor.test.ts > mapAgentSuccessToPhaseResult > spec phase (#1193) > fails a spec that produced no SEQUANT_SPEC marker… and … > does not accept a marker left by an earlier spec failed (2/186); restored.
    • PR closingIssuesReferences = [fix(run): spec runs in the main checkout, which the skills pre-flight never checks — a stale checkout silently degrades spec (#933 regression) #1193] only. CI: all checks green except test (in progress at time of writing).

    QA's risk gap (spec self-skip on a re-run emits no fresh marker → guard fails spec): latent today, not live. The self-skip in spec/SKILL.md relies on the bracketed --jq '[.comments[].body]' | grep '"phase"' snippet, which never matches (escaped quotes); run against this issue's comments just now it returned empty, so spec never self-skips and always emits a fresh marker. It becomes live the day that grep is fixed. Surfaced for an owner ruling rather than fixed here: either the skip path emits a SEQUANT_SPEC marker restating the prior plan, or the guard accepts a skip message as success.

    Also noted: the diff refactors worktree-manager.ts (new countCommitsBehind), which is outside this issue's May-touch list and overlaps #1196/#1197/#1199; expect a merge round with #1196.

  7. added a commit that references this issue on Sep 29, 2026
  8. admarble commented on Sep 29, 2026

    @admarble
    ContributorAuthor

    Owner ruling on the spec self-skip gap: the skip path emits a marker that restates the prior plan, and the guard stays strict. Filed as #1213 (blocked by this issue). PR #1211 merged as 2a6d58f.

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

    buggraph-2026-09-fieldplannedspec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions