Skip to content

bug(state): a successful spec-only run marks the issue ready_for_merge, so a later --phases exec skips it #1233

Closed

Description

@admarble

Tier: mechanical Graph: tracker #1236 (wave 2)

Problem

batch-executor.ts:2234-2241 sets the issue's terminal status from overall success alone:

finalStatus = readyGateResult ? … : success
  ? (qaVerdict === "NEEDS_VERIFICATION" ? "awaiting_verification" : "ready_for_merge")
  : "in_progress"

A successful sequant run N --phases spec, with no exec and no qa, therefore marks #N ready_for_merge. The next sequant run N --phases exec then skips it:

!  #1: already ready_for_merge — skipping (use --force to re-run)
All issues already completed. Use --force to re-run.

Observed 2026-09-30 in the #1138 Phase 0 bench, which splits spec, exec and qa into separate invocations so that each can run with different settings. --force works around it, but it also force-acquires the issue lock, and "run spec now, exec later" is an ordinary workflow.

Acceptance criteria

  • AC-1: A successful run in which no qa phase actually ran (for example --phases spec, --phases exec, or an auto-detected plan without qa) leaves the issue in a non-terminal status (for example in_progress), not ready_for_merge. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts with a spec-only run fixture
  • AC-2: After a spec-only run, sequant run N --phases exec runs without --force. Evidence: npx vitest run src/lib/workflow/run-orchestrator.test.ts
  • AC-3: A run that includes qa and passes still records ready_for_merge or awaiting_verification, as today. Evidence: the existing batch-executor status tests stay green

Relates to #972, #837.

May touch

  • src/lib/workflow/batch-executor.ts
  • src/lib/workflow/batch-executor.test.ts
  • src/lib/workflow/run-orchestrator.test.ts

File overlap: #1223 (batch-executor.ts), so it runs after this merges.

Activity

  1. added
    bug
    graph-2026-09-prerelease
    on Sep 30, 2026
  2. admarble commented on Sep 30, 2026

    @admarble
    ContributorAuthor

    Context for the run (graph tracker #1236, wave 2; re-checked against main after wave 1 merged)

    Current code: src/lib/workflow/batch-executor.ts:2234-2241

    const qaVerdict = phaseResults.find((p) => p.phase === "qa")?.verdict;
    const finalStatus = readyGateResult
      ? readyGateResult.issueStatus
      : success
        ? qaVerdict === "NEEDS_VERIFICATION" ? "awaiting_verification" : "ready_for_merge"
        : "in_progress";

    The skip guard that reads this status is run-orchestrator.ts:927 / :947 ("already ${status} — skipping (use --force to re-run)").

    Shape of the fix:

    • A terminal status (ready_for_merge / awaiting_verification) requires that a qa phase actually ran in this run (it's present in phaseResults) and passed. Read what ran, not what was requested. The body's AC-1 now says so. Otherwise a successful run records in_progress.
    • Keep the ready-gate branch (readyGateResult) exactly as it is.
    • finalStatus has other consumers. It's hoisted because "the checkpoint warning also has to name this status" (fix(chain): --chain --ready-gate resume re-executes already-gated links (COMPLETED_STATUSES misses waiting_for_human_merge/blocked) #837). The chain-mode checkpoint commit "after QA passes" follows right after it, and PR creation may also depend on it. grep -n finalStatus src/lib/workflow/batch-executor.ts, and make sure each consumer still behaves correctly for a spec-only run and an exec-only run. In particular, a spec-only run must not create a checkpoint commit or a PR as if QA had passed.
    • Existing tests at batch-executor.test.ts:838-842 and :2813-2839 pin the status behaviour. Keep them green (AC-3).

    Standard block:

    • No full npm test in exec or in qa. This applies to the qa phase as well as exec. Run targeted suites in the foreground with a timeout: timeout 600 npx vitest run src/lib/workflow/batch-executor.test.ts src/lib/workflow/run-orchestrator.test.ts. Global setup runs npm run build first.
    • Commit WIP early, and always before any mutation.
    • A mutation marker's failedTest starts with the test file path.
    • Before moving or reshaping a code block, grep the tests for a literal from it: some tests regex-scan source files (for example abort-logging.integration.test.ts scans run-orchestrator.ts).
    • PR body: Closes #1233. Use Refs only for the tracker, tracker(graph): pre-release fixes before the next release after 2.18.0 (4 nodes) #1236.
    • Add a CHANGELOG ### Fixed entry under [Unreleased].
  3. admarble commented on Sep 30, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 1 directory)

    AC Quality Check

    AC Issue Note
    AC-1 open_ended: "for example" implies other cases exist False positive — the parenthetical lists concrete illustrations of one well-defined condition ("no qa phase appears in phaseResults"), not an open scope. No AC rewrite needed.
    AC-2 none —
    AC-3 none —

    Scope Assessment

    Non-Goals: ⚠️ Non-Goals section not found. Consider adding scope boundaries.

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

    Verdict: ✅ SCOPE_OK (trivial — assessment skipped)

    Acceptance Criteria

    AC-1: Spec-only / exec-only success leaves the issue in_progress, not ready_for_merge

    Verification: Integration Test
    Scenario: Given a run with phases: ["spec"] (or ["exec"]) and no qa phase in the resolved plan → When runIssueWithLogging completes successfully → Then stateManager.updateIssueStatus is called with "in_progress", never "ready_for_merge" or "awaiting_verification".
    Assumptions: The signal is "a qa PhaseResult is present in phaseResults," not "qa was in the requested phase list" — matches the issue comment's "read what ran, not what was requested."

    AC-2: A spec-only run doesn't cause a later --phases exec to be skipped

    Verification: Integration Test
    Scenario: Given an issue whose persisted status is "in_progress" (post-AC-1 fix) → When sequant run N --phases exec is invoked without --force → Then the non-chain skip guard in run-orchestrator.ts (~line 947) does not log "already … skipping" and the issue proceeds through exec.
    Assumptions: isCompletedIssueStatus / COMPLETED_ISSUE_STATUSES (src/lib/workflow/completed-status.ts) are unchanged — in_progress was already outside the completed set; this AC is regression coverage for the state write, not the predicate.

    AC-3: A run that includes qa and passes still records the current terminal status

    Verification: Integration Test
    Scenario: Given phases: ["qa"] with a NEEDS_VERIFICATION or READY_FOR_MERGE verdict (existing fixtures at batch-executor.test.ts:2813-2839) → When the run completes → Then updateIssueStatus still records "awaiting_verification" / "ready_for_merge" exactly as today.
    Assumptions: None — pure regression guard, no new fixture needed beyond confirming the existing suite stays green after the AC-1 change.

    Implementation Plan

    Phase 1: Fix finalStatus computation (batch-executor.ts:2234-2241)

    1. Change the qa-presence check from "is qaVerdict truthy/matches a value" to "did a qa phase actually appear in phaseResults":
      const qaPhaseResult = phaseResults.find((p) => p.phase === "qa");
      const qaVerdict = qaPhaseResult?.verdict;
      const finalStatus = readyGateResult
        ? readyGateResult.issueStatus
        : success && qaPhaseResult
          ? qaVerdict === "NEEDS_VERIFICATION"
            ? "awaiting_verification"
            : "ready_for_merge"
          : "in_progress";
      This is a one-conjunct change (success → success && qaPhaseResult); the readyGateResult branch, the NEEDS_VERIFICATION branch, and the failure (in_progress) branch are untouched.
    2. grep -n finalStatus src/lib/workflow/batch-executor.ts and confirm every consumer (the updateIssueStatus call, the checkpoint-failure warning string) reads the corrected value with no further edits needed. Per the issue comment's own audit: the checkpoint commit (if (success && chainMode && worktreePath)) and PR creation (hasExecChanges-gated since fix(run): phase-restricted runs without an implementing phase must skip PR creation — spec-only batches always report failed #920) already key off chain-mode/commit-evidence rather than finalStatus directly, so a spec-only run already can't produce a spurious checkpoint or PR — verify this holds, don't add new guards there.
    3. The second, independent qaVerdict binding at ~line 2342 (used only for the PR body) is unaffected — leave it as its own const.

    Phase 2: Test coverage — batch-executor.test.ts

    1. Add a case beside the existing qa-verdict block (~:2813-2839): phases: ["spec"], qualityLoop: false, mock returns success for spec only → assert updateIssueStatus.mock.calls contains "in_progress" and not "ready_for_merge"/"awaiting_verification" (AC-1).
    2. Add a second case for phases: ["exec"] (no qa) with the same assertion — the AC text names this as an explicit example, not just --phases spec.
    3. Re-run the existing NEEDS_VERIFICATION/READY_FOR_MERGE cases unmodified to confirm AC-3 (no new fixture, just a regression run).

    Phase 3: Test coverage — run-orchestrator.test.ts

    1. Add a case exercising the non-chain skip guard (~line 947-960): seed the mocked stateManager.getIssueState to return { status: "in_progress" }, run with --phases exec and no --force, assert the issue is not logged as skipped and is included in the phases actually executed (AC-2). This file currently has zero coverage of the skip guard — it's new, not modified, coverage.

    Phase 4: PR & housekeeping

    1. CHANGELOG.md: add a ### Fixed entry under [Unreleased], per the issue comment's explicit instruction.
    2. PR body: Closes #1233, Refs #1236 (tracker, wave 2).
    3. No ADR — this is a one-conjunct correctness fix with a single correct answer, not a choice between viable designs (see Design Review Q2).

    Design Review

    1. Where does this logic belong? batch-executor.ts's hoisted finalStatus computation — the single site the fix(chain): --chain --ready-gate resume re-executes already-gated links (COMPLETED_STATUSES misses waiting_for_human_merge/blocked) #837 comment already made responsible for this decision. run-orchestrator.ts only reads the persisted status; it needs no change.
    2. What's the simplest correct approach? Gate on phaseResults.find(p => p.phase === "qa") (what ran) rather than inferring "qa was requested" from config.phases / options.autoDetectPhases (what was asked for). Rejected: threading a new ranQa flag through the function signature — the phase-result list already carries this signal, no new state needed.
    3. What existing pattern does this follow? The fix(run): phase-restricted runs without an implementing phase must skip PR creation — spec-only batches always report failed #920 fix to the PR-creation gate (hasExecChanges, evidence-based rather than phase-list-based) already established "trust what happened, not what was requested" in this same function — this fix is the same convention applied to finalStatus.
    4. What would a senior reviewer challenge? "Why not fix isCompletedIssueStatus/COMPLETED_ISSUE_STATUSES instead?" — because the skip predicate is correct (ready_for_merge should mean skip); the bug is that a spec-only run wrote ready_for_merge when it never validated anything. Fixing the predicate would leave the state file recording a false claim that other consumers (e.g. state-cleanup.ts's merge-detection sweep) also read.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • No ## Non-Goals section in the issue (flagged above) — low risk given the tightly scoped 3-file "May touch" list; not blocking.
    • The issue comment already pins the exact existing-test line ranges (:838-842, :2813-2839) new cases should sit beside — exec should follow that placement rather than appending at file end, to keep the qa-verdict scenarios grouped.

    Open Questions

    1. Should AC-2 test the orchestrator's skip guard directly, or just the isCompletedIssueStatus predicate in isolation? Recommendation: the real skip-guard code path in run-orchestrator.test.ts (per Phase 3 above) — the AC's own wording is behavioral ("sequant run N --phases exec runs without --force"), and a predicate-only unit test wouldn't prove the orchestrator path works. Impact if wrong: coverage looks satisfied but doesn't match the AC's Evidence: clause.
    2. Coordination with fix(pr): sequant run PRs double the conventional prefix in the title and ship a placeholder body #1223 (also touches batch-executor.ts, not yet started — no live worktree). No conflict today; the issue itself notes fix(pr): sequant run PRs double the conventional prefix in the title and ship a placeholder body #1223 should run after this merges. No action needed now beyond normal file-overlap awareness during exec.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Issue is explicitly tagged Tier: mechanical — a single-conjunct ternary fix in one function, with the exact test placement already specified in the issue comment. testgen is deliberately not recommended despite AC-1/AC-2 declaring npx vitest run <file> evidence (which would normally trigger it per the declared-evidence rule): both evidence commands point at test files that already exist with an established, pinned pattern for this exact scenario family (qa-verdict branching at :2813-2839) — exec should hand-write the two new cases beside that pattern directly rather than going through stub generation for already-patterned code.

    Label Review

    Current: bug, graph-2026-09-prerelease
    Recommended: no changes to domain labels (no UI/frontend surface, not complex/refactor/breaking — single ternary fix)
    Reason: Current labels already match the mechanical/bug shape of this fix.
    Quality Loop: Won't auto-enable — SCOPE_OK, mechanical tier, no scope warning.

    → gh issue edit 1233 --add-label planned


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

    Plan for #1233

    AC Checklist

    • AC-1: Spec-only/exec-only success → in_progress, not ready_for_merge — Integration Test, batch-executor.test.ts
    • AC-2: Spec-only run doesn't block a later --phases exec — Integration Test, run-orchestrator.test.ts
    • AC-3: A passing qa run still records today's terminal status — Integration Test, existing batch-executor.test.ts fixtures stay green

    Fix: batch-executor.ts:2234-2241 — gate the ready_for_merge/awaiting_verification branch on a qa PhaseResult actually being present in phaseResults, not just on success. One-conjunct change (success → success && qaPhaseResult); readyGateResult, checkpoint-commit, and PR-creation logic are all unaffected (already evidence-gated per #920).

    Tests: two new cases in batch-executor.test.ts (spec-only, exec-only) beside the existing qa-verdict block at :2813-2839; one new case in run-orchestrator.test.ts exercising the non-chain skip guard with a seeded "in_progress" status (currently zero coverage there).

    Key decision: testgen skipped despite declared vitest evidence — both target files already have the exact pattern to extend; stub generation would add ceremony, not value, for a mechanical-tier fix.

    Open questions: test the orchestrator skip-guard path directly (recommended) vs. the predicate in isolation; #1223 coordination noted, not blocking.

    Workflow: exec → qa, quality loop disabled.

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

    @admarble
    ContributorAuthor

    QA Verdict: AC_NOT_MET

    AC coverage: 0/1 met

    Gaps:

    Suggestions:

    • In the new tests, toContain("in_progress") passes trivially if status is set to in_progress at the start of the run. The not.toContain("ready_for_merge") assertions are the ones that actually tell the fixed and broken code apart.
  6. admarble commented on Sep 30, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 3/5 met

    Gaps:

    • AC-1 mutation record not yet in the PR body (the mutation itself passes when run by hand)
    • Checkpoint comment block is stale for runs without qa, which now record in_progress
    • The --resume case where qa completed earlier is untested

    Suggestions:

    • The comment block at batch-executor.ts:~2261-2273 still says that "a completed status was already written above … so a re-run reads this link as a completed prefix". After this change that's only true when qa ran. The comment should mention the in_progress case.
    • The new warning says "a re-run resumes the chain at this link". Chain resume actually starts at the first unfinished link (chain-resume.ts:112-123), so if an earlier link is also in_progress it resumes there. This is a wording nit.
    • A --resume run that skips an earlier, completed qa now records in_progress. That's the safe direction and it's documented in the CHANGELOG and the code comment, but no test covers it.
  7. added 2 commits that reference this issue on Sep 30, 2026
  8. admarble commented on Sep 30, 2026

    @admarble
    ContributorAuthor

    QA Verdict: NEEDS_VERIFICATION

    AC coverage: 3/3 met

    Gaps:

    • Required CI check test has not reported yet
    • Checkpoint comment's 'therefore absent from the branch tip ... computeChainResumePlan detects' now follows the in_progress sentence, though fail-fast only applies to the completed-prefix case; line also overlong
    • batch-executor.ts:2268: the reflowed comment line runs past about 150 characters. Its next sentence, "Its uncommitted work is therefore absent … which computeChainResumePlan detects", now follows the in_progress sentence. But the dirty-worktree fail-fast only applies to the completed-prefix case, so "therefore" now points at the wrong status. Only the comment is affected; the code is correct.
    • The PR says an exec-only run still opens a PR without qa. That is existing behaviour, is outside bug(state): a successful spec-only run marks the issue ready_for_merge, so a later --phases exec skips it #1233's scope, and is disclosed in the PR.
  9. added 2 commits that reference this issue on Sep 30, 2026
  10. added a commit that references this issue on Sep 30, 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

    buggraph-2026-09-prereleaseplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions