Skip to content

fix(run): a ladder halt is recorded nowhere: the halting phase reads success, failureCategory is empty, and the bundle exists only on stdout #1254

Closed

Description

@admarble

Tier: judgment Found: 2026-10-01, QA of #1250 (PR #1253), finding 2: "A spec-divergence halt with a successful spec exit is persisted as spec completed in state, run log and progress."

Problem. A ladder halt (SPEC_DIVERGENCE, DIVERGENCE_SUSPECT, TOP_OF_LADDER) stops the run, but none of the places a reader checks afterwards records why.

  • The halting phase's row says completed / success when the agent exited cleanly. updatePhaseStatus runs before the halt check, and the run log and progress events copy result.success.
  • The issue result is success: false with failureCategory: undefined, because deriveFailureCategory looks for a failed phase and finds none.
  • The evidence bundle only goes to log() (stdout). It reaches the MCP caller only through rawOutput, which the caller may truncate.

So sequant status and the MCP result show "failed, every phase succeeded", with no reason. That is the same shape as the uncommitted-exec case (#879), where only the issue-level status gave it away.

Prior fixes / producers

AC

Graph metadata

May touch

  • src/lib/workflow/batch-executor.ts, batch-executor.test.ts, run-log-schema.ts, state-manager.ts, src/mcp/tools/run.ts (+ test)

Activity

  1. added
    bug
    on Oct 1, 2026
  2. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Upstream cause (research note)

    Same root cause as earlier issues. An issue's outcome is worked out from its phase results. deriveFailureCategory (batch-executor.ts:639) finds a failed phase or nothing. A ladder halt is the orchestrator's decision, not a phase failure, so the data model has no place for it.

    Earlier stops outside a phase hit the same gap and each got its own field:

    Existing field. IssueResult.abortReason (types.ts:508) and the run log's abortReason (run-log-schema.ts:328) already exist. run-orchestrator.ts fills them in (chain-resume abort, skills pre-flight, rebase conflict) and ci/outputs.ts renders them. None of the four halt paths sets them.

    Suggested shape for AC-1. At the single buildBundle owner, set abortReason and a typed reason code. Better: one terminal-reason field on IssueResult that the next stop outside a phase can reuse, instead of a fifth one-off field. Spec should treat this as a recurrence (#1250's Design Review rule).

  3. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Runner context (before sequant run)

  4. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 2 directories)

    AC Quality Check

    • All three ACs are single-line, have checkboxes and carry an Evidence: clause. ✅
    • AC-1 prescribes the field, not the outcome. It names a new haltReason on IssueResult. That is the fifth one-off "stop outside a phase" field (see Design Review Q3), and it would hold the same value twice: once as haltReason and again as bundle.reason. This is the divergence below.
    • Evidence is non-vacuous on main. No halt path sets anything on IssueResult. PhaseStateSchema has no outcome or divergenceAcs; they exist only on PhaseMarkerSchema (state-schema.ts:132,140). RunToolIssueSummary (src/mcp/tools/run.ts:46) has no halt field.

    Scope Assessment

    Non-Goals: ⚠️ No ## Non-Goals section. Suggested: do not change halt behavior (thresholds, when the run stops). Do not refactor the existing capped, prCreationError and locked fields into the new shape.

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

    Verdict: ✅ SCOPE_OK

    Dependencies: #1250 is closed, so its spec-path halt is on main (batch-executor.ts:1474). Conflict risk: none. The worktrees that touch batch-executor.ts or run.ts (#1222, #1223, #1233, #1247, #1248, #1250) all belong to closed issues.


    Acceptance Criteria

    AC-1: every ladder halt is recorded on IssueResult and in the run-log issue entry — ⚠️ DIVERGENCE (wording)

    Verification: Unit Test (batch-executor.test.ts, one case per halt path: spec, loop SPEC_DIVERGENCE, DIVERGENCE_SUSPECT, TOP_OF_LADDER)
    Scenario: Given a phase declares SPEC_DIVERGENCE and exits 0 → When runIssueWithLogging returns → Then IssueResult carries the reason and the bundle, and the run-log issue entry has status: "failure" and records both.
    Note: On main, the run-log issue status is also wrong for a halt. deriveIssueLogStatus derives it from the phases, and recordIssueCompletion (batch-executor.ts:539) only forces failure when there is a prCreationError. So a halt where every phase passed is logged as success. That is the #879 status drift again.

    AC-2: a phase that declared SPEC_DIVERGENCE is stored in state as failed, with outcome and divergenceAcs

    Verification: Unit Test
    Scenario: Given exec (or spec) returns success: true, specDivergence: {acs:"AC-2"} → Then state.issues[N].phases.exec = {status:"failed", outcome:"SPEC_DIVERGENCE", divergenceAcs:"AC-2"}.
    Assumptions: sequant status already draws the failed symbol for failed. MCP sequant_status returns issueState.phases verbatim (src/mcp/tools/status.ts:130), so the new fields reach it without extra work.

    AC-3: the MCP sequant_run per-issue result carries haltReason and the declared ACs

    Verification: Unit Test (run.test.ts → buildStructuredResponse)
    Scenario: Given a run-log issue entry with a halt bundle → Then the summary has haltReason: "SPEC_DIVERGENCE" and declaredAcs: "AC-2". These are read from the bundle in the run log, not stored as a separate field. This works because MCP reads the run log, not IssueResult.


    Implementation Plan (once AC-1 is reworded)

    Phase 1: one terminal record at the halt owner

    1. Add "ladder_halt" to the bounded failure enum. It is mirrored in three places, as fix(run): phase-restricted runs without an implementing phase must skip PR creation — spec-only batches always report failed #920 did for pr_creation: ERROR_CATEGORIES (error-classifier.ts:29), the run-log category enum (run-log-schema.ts:142) and FailureCategorySchema (metrics-schema.ts).
    2. In batch-executor.ts, add one local haltOutcome(bundle) next to buildBundle. It returns { failureCategory: "ladder_halt", abortReason: "ladder halt: <reason> in <phase>[ (<ACs>)]", evidenceBundle }. Spread it into both returns: the spec-path early return (:1505, which needs the bundle kept in a variable instead of built inline) and the final return (:2584, when divergenceBundle is set). This is one owner and all four producers.
    3. Add evidenceBundle?: EvidenceBundle to IssueResult (types.ts). It reuses the existing abortReason?: string (types.ts:508) instead of adding a new reason field.

    Phase 2: run log + state

    1. In recordIssueCompletion, call markIssueFailed whenever !result.success, not only on prCreationError. That closes the class: any failure outside a phase now logs failure. Pass abortReason and evidenceBundle through to completeIssue. In IssueLogSchema, write abortReason without requiring aborted: true (aborted stays signal-only), and add evidenceBundle (zod schema mirroring EvidenceBundle; optional and additive at version: 1).
    2. Add outcome (the same z.enum(["SPEC_DIVERGENCE"])) and divergenceAcs to PhaseStateSchema, and to the updatePhaseStatus options. Add one phaseStateFor(result) helper used by both state writers: spec at :1457 and the phase loop at :2051. A declared divergence gives failed whatever the exit status.

    Phase 3: MCP

    1. Add optional abortReason, haltReason and declaredAcs to RunToolIssueSummary, read from issue.evidenceBundle / issue.abortReason in buildStructuredResponse.

    Design Review

    1. Where does this belong? In the issue-outcome assembly in runIssueWithLogging, at the two return sites, fed by the single buildBundle. Not at the four halt sites.
    2. Simplest correct approach? Reuse the existing abortReason (already shown by run-display.ts:124 and ci/outputs.ts:113) and the existing bounded failureCategory, and add one structured payload. Rejected: a top-level haltReason on IssueResult (it repeats bundle.reason and is a fifth one-off field). Also rejected: a generic terminal: {kind, detail} that rewrites capped, prCreationError and locked (too much scope; it belongs in a Non-Goal or a follow-up). ADR: not required. The plan extends existing fields rather than choosing between designs.
    3. Pattern / re-patch count. The pattern is "an issue's outcome is derived only from phase results, so a stop outside a phase has nowhere to go." Prior fixes: feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739 (capped), Nested phase claude that hangs after its turn is killed at ~106s, taking down the parent sequant run #856 (aborted/abortReason), 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 (markIssueFailed for a PR-only failure), fix(run): phase-restricted runs without an implementing phase must skip PR creation — spec-only batches always report failed #920 (pr_creation category). That is 4 prior fixes, which is ≥2, so stop: fix the class. The class fix is steps 1–4. Use the existing generic reason string and the bounded category, and make recordIssueCompletion honor !result.success for every failure outside a phase, so the next one needs no new field. AC-1's wording prescribes the opposite lever: a new haltReason field. That is the divergence.
    4. Senior reviewer challenge: "Why not just add haltReason as the AC says?" Because it would be the fifth field and would hold bundle.reason twice. "Why does MCP have haltReason then?" It is read from the bundle when the response is built, so it is never stored on its own.
    5. Producers and consumers (whole-repo grep). Producers: buildBundle is called at batch-executor.ts:1483 (spec), :1824 (TOP_OF_LADDER), :1886 (loop SPEC_DIVERGENCE) and :2350 (DIVERGENCE_SUSPECT). There is one builder and two return sites. The state write for a phase happens in two places (:1457, :2051), and step 5 merges them behind one helper. Consumers: IssueResult → recordIssueCompletion → LogWriter.completeIssue → IssueLogSchema → MCP buildStructuredResponse. Also run-display.toIssueSummary (abortReason fallback), ci/outputs.ts, run-orchestrator.recordMetrics (failureCategory), and state → sequant status / MCP sequant_status.

    Feature Quality Planning

    Open Questions

    1. AC-1 wording (blocking). Proposed replacement line:
      - [ ] AC-1: Every ladder halt (spec path, loop SPEC_DIVERGENCE, DIVERGENCE_SUSPECT, TOP_OF_LADDER) returns an IssueResult with failureCategory "ladder_halt", an abortReason naming the LadderHaltReason, phase and declared ACs, and the EvidenceBundle; the run log's issue entry records status "failure", the abortReason and the bundle. Evidence: npx vitest run src/lib/workflow/batch-executor.test.ts with one case per halt path
      Impact if declined: exec adds haltReason as written, and the next stop outside a phase adds a sixth field.
    2. Should the halting phase's run-log row read failure too? Recommendation: yes, for SPEC_DIVERGENCE only, through the same phaseStateFor decision. That keeps the state, the log and the progress output in agreement. Impact if skipped: the run log says "phase success, issue failure (ladder_halt)". That is honest now that abortReason is present, but it is inconsistent with state.

    Recommended Workflow

    Phases: spec → exec → qa (after AC-1 is reworded)
    Quality Loop: disabled
    Reasoning: A bug with a narrow, well-located change. The tests are targeted vitest files, so testgen adds little.

    Label Review

    Current: bug. Recommended: bug. No change. The planned label is held until AC-1 is resolved.

  5. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Owner decision (2026-10-04), on spec's Open Questions: (1) AC-1 is replaced with spec's wording: reuse abortReason, add the ladder_halt category and the EvidenceBundle, and add no new top-level haltReason. (2) Yes: the halting phase's run-log row and progress event read failure too, through the same decision as state; this is folded into AC-2. AC-3 is unchanged: MCP's haltReason and declaredAcs are read from the bundle, not stored. Re-running exec → qa.

  6. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 3/3 met

    Gaps:

    • AC-1's declared evidence command does not reach two of the four halt-path cases; behavior is covered in the sibling ladder test file — dropped: ladder-only halts need that file's configured-ladder harness
    • PR body carries no summary or AC table despite the runner note asking for it in exec's Summary
    • AC-1's Evidence: command runs only batch-executor.test.ts, which covers two of the four halt paths. The other two need a configured ladder and are in batch-executor.model-ladder.test.ts. Behavior is covered; the command named in the AC just doesn't reach it.
    • The PR body is the bare "Automated PR for issue fix(run): a ladder halt is recorded nowhere: the halting phase reads success, failureCategory is empty, and the bundle exists only on stdout #1254" placeholder. The runner note asked for the AC table inside exec's ## Summary.
  7. admarble commented on Oct 4, 2026

    @admarble
    ContributorAuthor

    Runner verification and follow-up ledger (PR #1304)

    Verified by the runner:

    • 7 test files: 434 passed. tsc is clean and CI is green.
    • Mutation check: with phaseRecordFor made to ignore specDivergence, 3 tests fail. Restored afterwards.
    • The code matches the owner decision: one ladderHaltOutcome at both return sites, recordIssueCompletion forcing failure for any failure not explained by a phase, and one phaseRecordFor decision for state, the run-log row and progress.

    Ledger:

    • AC-1's evidence command reaches only two of the four halt paths: dropped. The DIVERGENCE_SUSPECT and TOP_OF_LADDER cases need the configured-ladder harness in batch-executor.model-ladder.test.ts. The runner ran that file too, and the PR body records it.
    • The PR body was the placeholder: fixed in this PR. The body has been rewritten with the summary, the AC table and the mutation record. Released sequant (2.19.0) predates fix(run): PR body falls back to the placeholder when exec writes no "## Summary" heading, dropping exec's mutation markers and AC table #1297's carry-over.
    • Spec's deferred generic terminal: {kind, detail} rewrite of capped, prCreationError and locked: dropped. recordIssueCompletion now records every failure not explained by a phase, using the existing abortReason and failureCategory. The next stop of that kind needs a category value, not a new field, so the rewrite would buy nothing.
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions