Skip to content

feat: lightweight content pre-flight for --chain (AC presence, dependency-order sanity) #762

Closed

Description

@admarble

Context

sequant run --chain validates flag combinations only (run.ts: --stacked/--no-chain, --chain/--batch, etc.); there is zero content-level validation of the issues being chained. Issues run in the order given on the CLI with no check that the order matches actual dependencies, that the issues have acceptance criteria at all, or that declared blockers ("blocked by #N") are consistent with the chain order. The #133 incident (chain 114 → 116: QA fixes on the predecessor invalidated the already-built successor) is the historical example of the class this catches cheapest at the front door.

Most of the machinery already exists: src/lib/assess-collision-detect.ts does pairwise file-overlap prediction and ordering for /assess, and /assess's chain detection already parses "depends on #N" / "blocked by #N" markers.

Proposal

A fast pre-flight at chain start, warn-by-default (the #604 philosophy: suggest, never auto-decide — false dependency inference is worse than none):

  • Each issue exists, is open, and has a non-empty Acceptance Criteria section (warn if missing).
  • Declared dependency markers ("blocked by #N", "depends on #N") in issue bodies are checked against the CLI order; warn on contradiction (e.g. run 39 38 --chain when feat: Add MCP browser testing patterns reference #39 says blocked by feat: Create framework gotchas reference #38).
  • Predicted file-overlap ordering (reuse detectFileCollisions) is compared against the CLI order; warn on mismatch.
  • Warnings print before the first worktree is provisioned; a --strict-preflight (or similar) opt-in turns warnings into a hard stop. Naming/UX is /spec's call.

Acceptance Criteria

Out of scope

Spec-completeness scoring or any LLM-based judgment of issue quality; auto-reordering the chain; blocking on unmerged predecessor PRs (chains intentionally branch from local committed work).

References

Activity

  1. added
    enhancement
    cli
    on Jul 14, 2026
  2. admarble commented on Jul 15, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (5 ACs, ~3 directories)

    AC Quality Check

    All 5 ACs are measurable and reference concrete, verifiable markers ("Blocked by #36", "missing/empty AC section", opt-in fatal flag). No vague/unmeasurable language. One soft spot: AC-4 hedges ("notes the #592 in_progress-but-merged gap if not fixed by then") — acceptable, it's a doc-note escape hatch, not an unbounded scope.


    Scope Assessment

    Non-Goals: ✅ Present ("Out of scope": spec-completeness scoring, LLM judgment, auto-reordering, blocking on unmerged predecessor PRs).

    Metric Value Status
    Feature count 1 (chain content pre-flight) ✅
    AC items 5 ✅
    Directory spread src/lib/workflow, bin/, tests ✅

    Verdict: ✅ SCOPE_OK — tightly scoped, warn-only, reuses existing machinery.


    Acceptance Criteria

    AC-1: --chain runs print pre-flight warnings (missing/empty AC · dep-marker contradiction · file-overlap mismatch)

    Verification: Unit Test
    Scenario: Given three chained issue bodies (one lacking an AC section, one with Blocked by #N contradicting CLI order, one sharing a file target) → When the pre-flight runs → Then it returns exactly three warnings, one per class.
    Assumptions: Warnings are computed by a pure function over fetched issue bodies so they're unit-testable without a live run.

    AC-2: Warnings never block by default; opt-in flag makes them fatal before any worktree is provisioned

    Verification: Unit + Integration
    Scenario: Given contradicting issues → When run without the flag → Then run proceeds (non-zero warnings, zero exit); When run with --strict-preflight → Then it exits before ensureWorktreesChain is called.
    Assumptions: Pre-flight is invoked in RunOrchestrator.run() upstream of the worktree-provisioning block (~run-orchestrator.ts:764).

    AC-3: Reuses assess-collision-detect for overlap prediction — no new heuristics

    Verification: Unit Test + code inspection
    Scenario: Given issue bodies naming shared files → When predicting overlap order → Then it calls extractPathsFromIssueBody + detectFileCollisions (not a reimplementation).
    Assumptions: detectFileCollisions returns per-file issues[] in ascending order; pre-flight compares that predicted order to CLI order.

    AC-4: Closed/merged-issue check consistent with the existing #305 guard (+ note #592 gap)

    Verification: Unit Test
    Scenario: Given a chained issue that is CLOSED on GitHub → When pre-flight runs → Then it warns, matching the semantics of the ready_for_merge/merged state guard (run-orchestrator.ts:636–684) and reconcileStateAtStartup.
    Assumptions: Pre-flight fetches state alongside body in the same gh issue view call; the #592 in_progress-but-merged gap is documented, not fixed here.

    AC-5: Unit tests cover each warning against verbatim issue-body fixtures

    Verification: Unit Test (meta)
    Scenario: Given real marker strings copied verbatim (Blocked by #36, real AC headers) → When each warning path is tested individually → Then no synthetic combined fixture is used (per feedback_synthetic_test_fixture_trap).


    Implementation Plan

    Phase 1: Pre-flight module (src/lib/workflow/chain-preflight.ts)

    1. runChainPreflight(cliOrderedIssues: number[]): Promise<PreflightWarning[]> — fetch body, state, title for each issue in one gh issue view … --json call per issue (or batched), then compute warnings.
    2. AC presence — reuse hasAcceptanceCriteria(body) from ac-parser.ts; warn on false.
    3. Dependency-order — parse blocked by #N and depends on #N. ⚠️ parseDependencies (batch-executor.ts:199) matches only "depends on" — extend it or add a sibling marker parser so Blocked by #N (the issue's own motivating example) is caught. Warn when a declared blocker appears after the issue in CLI order.
    4. File-overlap — build Map<number, Set<string>> via extractPathsFromIssueBody, call detectFileCollisions, warn when predicted per-file order ≠ CLI order (AC-3).
    5. Closed/merged — warn when state === "CLOSED" (AC-4).

    Phase 2: Orchestrator wiring (run-orchestrator.ts)

    1. Invoke pre-flight inside run() guarded by mergedOptions.chain, before the worktree block (~line 754–764). Print warnings via chalk.yellow / bracketedConsoleLog.
    2. If mergedOptions.strictPreflight and warnings exist → print, dispose shutdown, return early with exitCode: 1 before ensureWorktreesChain.
    3. Pass the RAW CLI order, not issueNumbers — see Open Questions feat: Complete remaining v1.0 features (AC-10, AC-13, AC-14) #1.

    Phase 3: CLI + types

    1. Add strictPreflight?: boolean to RunOptions (types.ts) and register .option("--strict-preflight", …) in bin/cli.ts — the CLI-wiring gap won't be caught by tsc/build/tests.

    Phase 4: Tests

    1. chain-preflight.test.ts — one test per warning class against verbatim fixtures; assert warn-only vs --strict-preflight fatal.

    Design Review

    1. Where does this belong? A new pure-ish module chain-preflight.ts in src/lib/workflow/ (fetch + compute), invoked once from RunOrchestrator.run(). Keeps orchestrator lean and the warning logic unit-testable.
    2. Simplest correct approach? Warn-only list computed from already-available primitives (hasAcceptanceCriteria, detectFileCollisions, marker regex). Rejected: a scoring/severity system (out of scope, investigate(metrics): chain mode 29% success rate vs 92% single-issue — failure forensics #604 says warn-only).
    3. Existing pattern? Mirrors the existing non-fatal-warning style (logNonFatalWarning, the ready_for_merge skip block) and /assess's collision annotations — same ⚠ #N phrasing for consistency.
    4. What would a senior reviewer challenge? "Why re-fetch issue bodies when getIssueInfo already runs?" — because getIssueInfo fetches only title,labels; pre-flight needs body,state. Consolidating both into one fetch is a reasonable optional optimization but adds coupling; flag as follow-up, don't force it.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Order-source correctness (critical): sortByDependencies runs during resolveConfig (run-orchestrator.ts:504) and silently reorders "depends on" chains. If the pre-flight compares against the post-sort issueNumbers, it can never surface a "depends on" contradiction — the sorter already fixed it. The pre-flight MUST receive the raw issueArgs order. (Open Question feat: Complete remaining v1.0 features (AC-10, AC-13, AC-14) #1.)
    • Marker-parser gap: existing parseDependencies ignores "blocked by" — the exact phrase in the AC-2 example. Extend it once, reused by both the sorter and pre-flight, to avoid drift (feedback_sibling_scan_includes_prose).
    • gh failure handling: if gh issue view fails for an issue, warn-degrade (skip that check) rather than abort — pre-flight must never be the thing that breaks a run.

    Derived ACs (if any)

    Source Derived AC Priority
    Order-source correctness Pre-flight compares against raw CLI order, not dep-sorted order (regression test: run 39 38 --chain where #39 depends-on #38 still warns) High

    Rule Touchpoints

    The behavior-rule detector fired on AC-2 (keywords default, never), but all returned touchpoints are false positives (the detector's own source + unrelated Zod .default() calls). This is a new rule with no pre-existing runtime duplicate — the "warn-by-default, opt-in fatal" behavior lives entirely in the new module + CLI flag. No touchpoint table needed; just ensure the flag semantics live in exactly one place.


    Open Questions

    1. Raw vs dep-sorted order for the comparison. — Recommendation: thread the raw issueArgs-parsed order into the pre-flight. Impact if wrong: the file-overlap and depends-on contradiction checks become dead code (the sorter pre-fixes them), silently passing AC-1/AC-3 while catching nothing.
    2. Flag name. — Recommendation: --strict-preflight (issue says naming is /spec's call). Alternatives: --preflight-strict, --fail-on-warnings. Impact: cosmetic; pick one and register it in bin/cli.ts.
    3. blocked by in sortByDependencies too? — Recommendation: extend parseDependencies to include blocked by, which also improves the sorter. Impact: behavior change to auto-ordering — keep warn-only for now if we want to avoid touching sort semantics; flag as a deliberate decision.

    Recommended Workflow

    Phases: spec → testgen → exec → qa
    Quality Loop: disabled (SCOPE_OK, no complex/refactor label)
    Reasoning: AC-1/AC-3/AC-4 are Unit-Test-verifiable pure logic and AC-5 mandates unit tests → testgen stubs the fixtures before implementation. No UI → no test phase. Not security-sensitive → no security-review.


    Label Review

    Current: enhancement, cli
    Recommended: keep enhancement, cli; add planned
    Reason: Scope is green and single-feature; no complex/breaking warranted. cli is accurate (new --chain sub-behavior + flag).
    Quality Loop: Won't auto-enable — scope is SCOPE_OK, not SCOPE_WARNING.


    --- DRAFT GITHUB ISSUE COMMENT (PLAN) ---

    Plan — content pre-flight for --chain (warn-by-default)

    Build: new src/lib/workflow/chain-preflight.ts (fetch body,state → compute warning list) → invoke in RunOrchestrator.run() before worktree provisioning → add strictPreflight to RunOptions + .option() in bin/cli.ts.

    Two things that will bite if missed:

    1. Compare against the RAW CLI order, not issueNumbers — sortByDependencies already reorders "depends on" chains during config resolution, so comparing post-sort catches nothing.
    2. parseDependencies only matches "depends on" — extend it to also catch blocked by #N (the AC-2 example) so the dependency-contradiction check actually fires.

    Reuses: hasAcceptanceCriteria (ac-parser), detectFileCollisions (assess-collision-detect), the ready_for_merge/merged guard semantics. Warn-degrade on gh failure. Suggested phases: spec → testgen → exec → qa.

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

    @admarble
    ContributorAuthor

    Exec Progress — content pre-flight for --chain (#762)

    Implemented, PR up: #764.

    AC Coverage

    AC Description Status
    AC-1 Warnings for missing AC · dep-order contradiction · file-overlap-order mismatch ✅ Implemented
    AC-2 Warn-only by default; --strict-preflight fatal before any worktree provisioned ✅ Unit / ⚠️ integration gap (see below)
    AC-3 Reuses assess-collision-detect — no new heuristics ✅ Implemented
    AC-4 Closed/merged check consistent with #305; #592 gap noted ✅ Implemented
    AC-5 Unit tests per warning vs verbatim fixtures ✅ Implemented (17 tests)
    Derived Compares raw CLI order, not dep-sorted (run 39 38 --chain still warns) ✅ Implemented

    Key files

    • src/lib/workflow/chain-preflight.ts (new) — pure computePreflightWarnings + gh fetch in runChainPreflight; warn-degrades on fetch failure.
    • src/lib/workflow/run-orchestrator.ts — invoke in run() before worktree setup; new ResolvedRun.rawIssueOrder threads the raw CLI order past sortByDependencies.
    • src/lib/workflow/types.ts + bin/cli.ts — strictPreflight / --strict-preflight.
    • src/lib/workflow/chain-preflight.test.ts (new) — 17 tests.

    Quality Plan Alignment

    Dimension Notes
    Order-source correctness (critical) ✅ Pre-flight receives raw issueArgs order; regression test at [39, 38]
    Marker-parser gap ✅ New parseDeclaredBlockers catches both depends on and blocked by; kept local so sorter semantics are untouched (Open Q #3 → warn-only for now)
    gh failure handling ✅ Warn-degrade (skip that issue's checks), never abort
    AC-section false positives ✅ hasNonEmptyAcSection extends hasAcceptanceCriteria to also accept bare-checkbox AC sections (e.g. this issue's own body) — avoids false "missing AC" warnings

    Checks

    • npm run build ✅ · npm run lint ✅ (0 warnings) · npx vitest run src/lib/workflow/ ✅ 976 pass / 2 skip · new suite ✅ 17 pass · run --help shows --strict-preflight ✅

    Known gap

    • AC-2 integration: strict-abort-before-ensureWorktreesChain is verified by code inspection + type-check, not a full run() integration test (no orchestrator run-harness with gh/state/worktree mocking exists; building one would be brittle for marginal value). Pure warning computation is fully unit-tested.
  5. admarble commented on Jul 15, 2026

    @admarble
    ContributorAuthor

    QA Review — content pre-flight for --chain (#762) · PR #764

    Verdict: AC_MET_BUT_NOT_A_PLUS — all 6 ACs met, CI green, mergeable clean. Two non-blocking improvements below.

    AC Coverage

    AC Source Status Evidence
    AC-1 Original MET All three classes fire; verified against real issue bodies, not just fixtures
    AC-2 Original MET Pre-flight at run-orchestrator.ts:766-805, upstream of the worktree block; --strict-preflight registered in bin/cli.ts and confirmed in run --help
    AC-3 Original MET Calls extractPathsFromIssueBody + detectFileCollisions; no reimplemented overlap heuristics
    AC-4 Original MET CLOSED check fires on real closed issues (#748/#749); message cites the #592 gap
    AC-5 Original MET 17 tests, one class per test, verbatim markers
    AC-6 Derived (order-source) MET ResolvedRun.rawIssueOrder threads raw CLI order past sortByDependencies; [39, 38] regression test present

    Coverage: 6/6 met. CI: 5/5 pass. Type issues: 0. Deleted tests: 0. Diff: +593 / -0 across 6 files.

    Verified, not assumed

    • The overlap check is not dead code. detectFileCollisions explicitly re-sorts [...issues].sort((a,b) => a-b) (assess-collision-detect.ts:208), so collision.issues is genuinely ascending rather than Map-insertion order. Had it preserved insertion order, issuePaths is built in cliOrder order and the contradiction check would have compared CLI order against itself and never fired. The code comment's claim holds.
    • Ascending order really is /assess's suggested order. formatCollisionAnnotations renders Order: A → B and Chain: npx sequant run <ascending ids> --chain off the same ascending array, so the pre-flight warns exactly when CLI order deviates from what /assess itself would recommend. Faithful reuse per AC-3.
    • Locks are not leaked by the strict abort. This is the first early return in run() that fires with locks held, and ShutdownManager.dispose() (shutdown.ts) discards cleanup tasks rather than running them — so the registered "Release issue locks" task never runs. Locks are still released, but only via the process.on("exit") safety net, which survives because its detach task is discarded too. Correct by a two-step accident rather than by design; worth a comment if this path grows.

    Issue 1 — prose mentions parse as real blockers (--strict-preflight interaction)

    parseDeclaredBlockers strips fenced code and HTML comments but still matches the marker anywhere in prose. Run against its own issue body:

    #762 state=OPEN hasAC=true blockers=[38, 36]
    

    Neither is real. They come from #762's own prose:

    • line 12: ...(e.g. `run 39 38 --chain` when #39 says blocked by #38) — an example
    • line 22: ...real markers like "Blocked by #36"... — AC-5's own text naming a marker

    So sequant run 762 38 --chain would print a bogus "blocked by #38" warning. Two mitigating facts: the existing parseDependencies (batch-executor.ts:215) is equally unanchored and actually reorders the chain on it, so this is an inherited class, not a new one; and warn-only default makes it noise rather than breakage.

    The concern is the --strict-preflight interaction: under the new flag a spurious warning becomes a hard abort on a legitimate chain, with no override but dropping the flag. That's in tension with the philosophy the module's own docblock quotes ("false dependency inference is worse than none"). A line-anchored match (marker at line start / list-item start) would fix both hits, but would break the mid-line "This is Blocked by #38 until it lands." test — so it's a deliberate call, not a drive-by.

    Note the file-overlap check has the same shape of false positive — real [762, 760, 761] warns because all three cite docs/reference/chain-mode-analysis-2026-05.md rather than modify it. That one is inherited from extractPathsFromIssueBody and AC-3 mandates reusing it, so it's out of scope here.

    Issue 2 — flag undocumented outside --help

    --strict-preflight is in CHANGELOG and run --help, but the two places every comparable run flag lives don't mention it:

    • docs/reference/run-command.md:55 — flag table (has --qa-gate)
    • docs/reference/cheat-sheet.md:126 — flag table (has --qa-gate)

    No documentation AC in #762, so this isn't an AC miss — but it's a one-row-each fix.

    Test quality

    Behavior-asserting, verbatim markers, one class per test with a separate three-at-once test for AC-1's scenario — correct structure, avoids the synthetic-combined-fixture trap. Two nits: BARE_CHECKBOX_AC_BODY is commented "copied verbatim from #762" but is an abridged paraphrase; and no test covers the prose false positive above (adding one would lock in current behavior — worth doing only alongside a decision on Issue 1).

    Self-Evaluation

    • Verified working: Yes — ran the suite (17/17), built, confirmed --strict-preflight in run --help, and executed the detector against five real issue bodies. The false positive came from that dogfood run, not from reading.
    • Test efficacy: High for the pure computation; the orchestrator wiring (strict abort before provisioning) rests on code inspection only, as exec disclosed.
    • Likely failure mode: A user adopts --strict-preflight, hits a prose false positive on a legitimate chain, and abandons the flag.
    • Verdict confidence: High. Both findings are quality, not correctness; neither blocks merge.

    Next Steps

    1. Decide on Issue 1 — anchor the marker match, or accept prose false positives as consistent with the existing sorter and document the --strict-preflight caveat.
    2. Add --strict-preflight to the two flag tables.
    3. Merge — neither item blocks. Per project policy AC_MET_BUT_NOT_A_PLUS proceeds to PR rather than the quality loop.
  6. added
    needs-improvement
    on Jul 15, 2026
  7. added a commit that references this issue on Jul 15, 2026
  8. admarble commented on Jul 15, 2026

    @admarble
    ContributorAuthor

    QA Gap Fixes — both items resolved (9b984da)

    Both improvements from the QA review above are fixed in PR #764.

    1. Prose mentions no longer parse as blockers

    BLOCKER_MARKER_REGEX is now anchored to line start (still allowing list-item and bold forms), inline code spans are stripped alongside fences and HTML comments, and the # is required so Blocked by 5 days of review can't parse as issue #5.

    Rationale: a declaration is a line about the issue's own dependencies; prose that merely mentions the marker mid-sentence is not. This deliberately diverges from batch-executor.ts:parseDependencies, which stays unanchored — the pre-flight parser is local by design (Open Q #3).

    Verified against the real issue corpus, not just fixtures — scanning 40 real issues that mention a marker:

    Issue Line Parsed Correct?
    #155 - Blocked by: #107 (symlinks improvement) [107] ✅ true positive kept
    #188 - Depends on #187 (project name detection...) [187] ✅ true positive kept
    #223 - Depends on: #219 being merged first [219] ✅ true positive kept
    #31 **Depends on**: #10 inside a ```markdown fence [] ✅ doc example, correctly ignored
    #762 prose mentions only [] ✅ false positive fixed (was [38, 36])

    #31 is the interesting one: it looks like a true-positive regression from a raw-body grep, but the marker sits inside a fenced block as an example of the format — so ignoring it is right. Anchoring cost no real declarations.

    2. --strict-preflight documented

    Added to the two flag tables that list every comparable run flag:

    • docs/reference/run-command.md:56
    • docs/reference/cheat-sheet.md:127

    CHANGELOG updated to describe the line-anchored matching.

    Also addressed

    The BARE_CHECKBOX_AC_BODY comment claimed "copied verbatim from #762" for what is an abridged paraphrase — corrected to "the shape of #762's issue, abridged."

    Checks

    npx vitest run src/lib/workflow/ → 980 pass / 2 skip (42 files) · npm run lint → clean (0 warnings) · npm run build → clean · pre-flight suite 21 pass (4 new, including a regression test built from #762's two verbatim prose lines).

    Two of the new tests replace cases that encoded the mid-line matching being fixed ("This is Blocked by #38 until it lands."), rewritten to line-anchored form.

    Verdict: unchanged at AC_MET_BUT_NOT_A_PLUS → now READY_FOR_MERGE pending CI green on 9b984da. Both open items are closed; no AC status changed (all 6 were already met).

  9. added
    ready-for-review
    and removed
    needs-improvement
    on Jul 15, 2026
  10. added a commit that references this issue on Jul 15, 2026
  11. added 4 commits that reference this issue on Jul 15, 2026
  12. added 3 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

    clienhancementplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions