Skip to content

feat(orchestrator): preserve partial output for turn-capped phases in phase-executor #739

Closed

Description

@admarble

Problem

#733 made ClaudeCodeDriver treat error_max_turns as a soft outcome: it returns { success: false, capped: true, output: <partial> } instead of a hard error (claude-code.ts:233-246). This is fully wired for sub-agent caps (the /qa and /exec skills read it). But at the orchestrator level the flag is dead data:

So #733's AC-1 ("don't fail the phase") holds for sub-agent caps but not for orchestrator-level query caps. This was explicitly carved out of #733 with sign-off in the spec ("confine to driver + skills… file a follow-up. Confirm?") — this issue is that follow-up.

Proposed approach

Mirror the #732 structured-error retry-gating pattern (phase-executor.ts:870-872 gates retry on typedError.isRetryable; MCP fallback at :910):

  1. Add capped?: boolean to PhaseResult (types.ts), additive — same pattern as structuredError?.
  2. In phase-executor.ts:754, propagate capped and the partial output on the failure return (today output is omitted entirely on failure).
  3. Treat a capped phase as incomplete-but-not-hard-failed: skip the cold-start retry and MCP fallback (a retry cannot un-cap a turn limit — same rationale as the billing skip in feat(driver): surface structured rate-limit/credits errors from SDK message stream (replaces #592 fallback noise) #732), and surface a clear "phase capped, partial output preserved" signal.
  4. Decide run-loop semantics (the open design question): does a capped phase auto-continue with partial output, or halt cleanly for the user to resume? (Leaning: surface + halt, since silently continuing on partial work is risky.)
  5. Tests in phase-executor.test.ts for the capped path: partial output preserved, no MCP-fallback retry, correct downstream signal.

Acceptance Criteria

  • AC-1 — PhaseResult carries capped and the partial output when the driver returns a capped result.
  • AC-2 — A capped phase does not trigger the cold-start retry or the MCP fallback.
  • AC-3 — The run loop surfaces the cap clearly and preserves partial work (exact continue-vs-halt semantics decided during design).
  • AC-4 — phase-executor.test.ts covers the capped path end-to-end.

References

Activity

  1. added
    enhancement
    multi-agent
    on Jun 22, 2026
  2. admarble commented on Jun 22, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (4 ACs, 1 directory)

    AC Quality Check

    AC Assessment
    AC-1 ✅ Measurable — capped + output present on PhaseResult when driver caps.
    AC-2 ✅ Measurable — assert no cold-start retry and no MCP-fallback spawn.
    AC-3 ⚠️ Intentionally open — "exact continue-vs-halt semantics decided during design". Resolved in Open Questions below (recommend surface + halt).
    AC-4 ✅ Measurable — phase-executor.test.ts covers the capped path.

    No vague/unmeasurable/open-ended smells beyond the deliberately-deferred AC-3 design decision.


    Scope Assessment

    Non-Goals: ⚠️ No explicit Non-Goals section in the issue, but the body scopes tightly: orchestrator-level (top-level phase query) caps only; sub-agent caps already handled in #733. Implicit non-goal: do not change driver-level (claude-code.ts) or skill-level behavior.

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

    Verdict: ✅ SCOPE_OK — single cohesive change in one module, mirroring the established #732 retry-gating pattern.


    Acceptance Criteria

    AC-1: PhaseResult carries capped + partial output from a capped driver result

    Verification: Unit Test
    Scenario: Given the driver returns { success:false, capped:true, output:<partial> } → When executePhase maps the failure result (phase-executor.ts:754-767) → Then the returned PhaseResult has capped: true and output: <partial>.
    Assumptions: AgentPhaseResult.capped (agent-driver.ts:78) is already set by the driver (#733/#737, confirmed). Today the failure return at :754 omits output entirely and has no capped field.

    AC-2: A capped phase skips the cold-start retry AND the MCP fallback

    Verification: Unit Test
    Scenario: Given a capped result from executePhaseFn → When executePhaseWithRetry runs → Then exactly one phase invocation occurs (no cold-start re-spawn at :844, no no-MCP retry at :919-924, and — for spec — no spec-extra retry at :972).
    Assumptions: A retry cannot un-cap a turn limit, so skipping is correct — same rationale as the BillingError skip (:918). Note capped must skip even cold-start retries, unlike billing which still cold-start-retries in the <60s window — so a flag check alone at the MCP gate is insufficient; an explicit early return is needed (see Implementation Plan).

    AC-3: Run loop surfaces the cap clearly and preserves partial work

    Verification: Integration Test (batch-executor loop) + Manual
    Scenario: Given a phase returns capped → When the batch run loop processes it (batch-executor.ts:867-887, :967-1041) → Then a distinct "capped — partial output preserved" signal is emitted (not a generic failed), the partial output reaches the phase log / state, and the run halts cleanly for user resume (recommended semantics — see Open Questions).
    Assumptions: A capped result is already success:false, so it already hits the break at :1040 (halt). The gap is the signal (currently logged as a plain failure) and the dropped output.

    AC-4: phase-executor.test.ts covers the capped path end-to-end

    Verification: Unit Test
    Scenario: Given the capped-path tests → When the suite runs → Then partial-output preservation, no-retry/no-MCP-fallback, and the downstream signal are all asserted.
    Assumptions: Mirror the existing billing tests at phase-executor.test.ts:649-708 (makeResult + injected executePhaseFn + call-count assertions).


    Implementation Plan

    Phase 1: Type + propagation (AC-1)

    1. src/lib/workflow/types.ts (~:233) — add /** Set when the phase hit its turn cap... */ capped?: boolean; to PhaseResult, additive, same shape as structuredError?.
    2. src/lib/workflow/phase-executor.ts:754-767 — on the failure return, propagate capped: agentResult.capped and output: agentResult.output (today output is dropped on failure).

    Phase 2: Retry gating (AC-2)

    1. phase-executor.ts executePhaseWithRetry — after each executePhaseFn call (both the skipColdStartRetry branch ~:837 and the cold-start loop ~:853), add an explicit short-circuit: if (lastResult.capped) return lastResult;. This skips cold-start retries, the MCP fallback, and the spec-extra retry in one move.
    2. Defense-in-depth (mirror billing): add const failureIsCapped = lastResult!.capped === true; and include !failureIsCapped in the MCP-fallback guard at :919-924, alongside !failureIsBilling. (The early return in step 3 already covers this; the guard documents intent and protects against future code paths.)

    Phase 3: Run-loop signal (AC-3)

    1. src/lib/workflow/batch-executor.ts:879-887 — when result.capped, emit a distinct progress status (e.g. "capped") instead of "failed", and ensure the partial result.output is persisted to the phase log (createPhaseLogFromTiming ~:923, add status "capped" if the log schema allows, else log as failure with a capped note) and/or state. Keep the existing break (halt) at :1040.

    Phase 4: Tests (AC-4)

    1. phase-executor.test.ts — add a describe/it block mirroring :649-708: (a) capped result → result.capped === true and result.output preserved; (b) capped → executePhaseFn called exactly once, no mcp:false call; (c) capped spec phase → no spec-extra retry. Add a batch-executor-level assertion for the distinct signal if feasible.

    Design Review

    1. Where does this logic belong? Propagation in phase-executor.ts (the success/failure mapper at :373/:754), retry-gating in executePhaseWithRetry, and run-loop signalling in batch-executor.ts. Type lives in types.ts. This matches exactly where structuredError/BillingError gating already lives (feat(driver): surface structured rate-limit/credits errors from SDK message stream (replaces #592 fallback noise) #732).
    2. What's the simplest correct approach? One additive field + a single early-return in the retry wrapper + a status branch in the loop. Rejected: a richer CappedResult wrapper type or a new exception — overkill; capped?: boolean parallels structuredError? and keeps the change additive/backward-compatible.
    3. What existing pattern does this follow? The feat(driver): surface structured rate-limit/credits errors from SDK message stream (replaces #592 fallback noise) #732 structured-error retry-skip pattern (failureIsBilling → skip MCP fallback). Capped is the second member of that "soft, non-retryable outcome" family.
    4. What would a senior reviewer challenge? "Why an explicit early-return instead of just a guard flag like billing?" — because billing still runs cold-start retries in the <60s window; capped must skip all retries, so a guard only at the MCP gate would still allow cold-start re-spawns. Document this in a code comment. Also: "Does the phase-log schema accept a capped/new status?" — verify before adding; fall back to logging as failure + note if not.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Sibling sites (same root cause): the three retry gates — cold-start loop (:844), MCP fallback (:919), spec-extra retry (:972) — must all respect capped. The single early-return in step 3 covers all three; the !failureIsCapped guard (step 4) is belt-and-suspenders. Don't fix only the MCP gate and leave the spec retry live (the bug the issue calls out for spec).
    • Backward compatibility: capped? is optional/additive — no existing consumer breaks. output now present on capped failures where it was previously absent; verify no consumer assumes output === undefined implies failure.
    • Log-schema check: adding a "capped" status to createPhaseLogFromTiming may require a run-log-schema change; if so, keep it minimal or log-as-failure-with-note to stay in scope.

    Open Questions

    1. AC-3 continue-vs-halt semantics — Recommendation: surface + halt (the issue's leaning, and the current de-facto behavior since capped is success:false → break). Auto-continuing on partial work risks downstream phases acting on incomplete output. Impact if wrong: minimal — halt is reversible (user resumes); auto-continue is not. Decision is reversible later via the capped flag now being first-class.
    2. Phase-log status — Does createPhaseLogFromTiming / the run-log schema accept a new "capped" status, or should capped log as "failure" with a capped marker? Recommendation: reuse "failure" + a capped boolean in the log entry if the schema is rigid; add "capped" only if trivially additive.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled (SCOPE_OK, single module, well-bounded)
    Reasoning: Tight, pattern-mirroring change in one already-well-tested module. AC-4 is the test work and the billing tests give a verbatim template, so a separate testgen phase is redundant — fold test authoring into exec. No UI (no browser test), no new security surface.


    Label Review

    Current: enhancement, multi-agent
    Recommended: keep enhancement, multi-agent; add planned
    Reason: Orchestrator turn-cap handling for multi-agent runs — multi-agent fits. No complex/breaking warranted (additive, single module).
    Quality Loop: Won't auto-enable (SCOPE_OK, no SCOPE_WARNING).


  3. added
    planned
    on Jun 22, 2026
  4. admarble commented on Jun 22, 2026

    @admarble
    ContributorAuthor

    Exec Progress Update

    Implementation complete. PR: #741

    AC Coverage

    AC Description Status
    AC-1 PhaseResult carries capped + partial output ✅ Implemented
    AC-2 Capped phase skips cold-start retry, MCP fallback, spec-extra retry ✅ Implemented
    AC-3 Run loop surfaces the cap clearly, preserves partial work, halts cleanly ✅ Implemented
    AC-4 phase-executor.test.ts covers the capped path end-to-end ✅ Implemented

    Key files changed

    • src/lib/workflow/types.ts — additive capped?: boolean on PhaseResult
    • src/lib/workflow/phase-executor.ts — propagate capped + partial output on failure; early-return retry gating + !failureIsCapped MCP guard
    • src/lib/workflow/batch-executor.ts — distinct capped progress signal, capped log marker, skip inner /loop + outer quality-loop (surface + halt)
    • src/lib/workflow/run-log-schema.ts — additive optional capped on PhaseLogSchema (status stays "failure")
    • src/lib/workflow/log-writer.ts — thread capped through createPhaseLogFromTiming
    • phase-executor.test.ts / batch-executor.test.ts — capped-path coverage
    • CHANGELOG.md — [Unreleased] > Changed entry

    Design decisions (resolving spec Open Questions)

    1. AC-3 continue-vs-halt: chose surface + halt (spec recommendation). A capped phase skips both the inner /loop spawn and the outer quality-loop retry — re-running can't un-cap, and acting on partial work is the risk this path avoids. Reversible later via the now-first-class capped flag.
    2. Phase-log status: reused "failure" + an additive capped boolean rather than a new PhaseStatus enum value, keeping the persisted-log schema stable.

    Checks

    • npm run build ✅ · npm run lint ✅ (0 warnings)
    • npx vitest run src/lib/workflow/ → 943 passed, 2 skipped
    • __tests__/run-orchestrator*.test.ts → 48 passed

    Quality Plan Alignment

    Quality Dimension Status Notes
    Sibling sites (all 3 retry gates) ✅ Single early-return covers cold-start loop, MCP fallback, spec-extra retry; !failureIsCapped guard documents intent
    Backward compatibility ✅ capped? additive/optional; output now present on capped failures — audited consumers, none assume output===undefined implies failure
    Log-schema check ✅ Additive optional boolean, no enum change; run-log-schema.test.ts green

    Notes

    • Excluded a pre-existing unrelated package-lock.json churn (npm libc field artifact) from the commit.
    • One gap caught in self-review beyond the spec's AC-3 plan: the spec assumed capped already halts via success:false → break, but the quality-loop branch precedes that break. Added explicit skips for both the inner /loop and the outer quality-loop while so a capped phase truly halts.
  5. admarble commented on Jun 22, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #739

    PR: #741 · Commit: cb16422b74c34531baf6d2fe535152dd276e3e68 · Reviewer: /qa (inline review — diff < 600 LOC)

    AC Coverage

    AC Description Status Notes
    AC-1 PhaseResult carries capped + partial output from a capped driver result ✅ MET types.ts adds capped?: boolean; phase-executor.ts:764-766 propagates capped and output on the failure return (output was previously dropped). Test asserts both.
    AC-2 Capped phase skips cold-start retry AND MCP fallback ✅ MET Explicit early returns in both retry branches (phase-executor.ts:851,880) + !failureIsCapped guard at the MCP gate (:946). Tests prove single invocation, no mcp:false call, no spec-extra retry.
    AC-3 Run loop surfaces the cap clearly + preserves partial work (continue-vs-halt decided in design) ✅ MET (main loop); ⚠️ sibling gap (spec phase) Surface + halt chosen per spec. Main phase loop: distinct signal, capped log marker, skips inner /loop + outer quality-loop, halts. Gap: the spec-phase block (:589-639) preserves output + halts but does not emit the distinct signal or log marker — see Adversarial Re-Read.
    AC-4 phase-executor.test.ts covers the capped path end-to-end ✅ MET 3 capped cases in phase-executor.test.ts (flag+output, no MCP fallback, no spec-extra retry) + 2 integration cases in batch-executor.test.ts (distinct signal/log marker/halt, quality-loop skip).

    Coverage: 4/4 AC items met (one with a non-blocking sibling-site consistency gap).


    CI Status

    Check State Impact
    build (22.x) ✅ pass (2m13s) MET
    typecheck ✅ pass MET
    validate-skills ✅ pass MET
    validate-plugin ✅ pass MET
    node-floor-guard ✅ pass MET

    CI Summary: 5 passed, 0 pending, 0 failed. mergeable: MERGEABLE.


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 8 (1 module dir) OK
    Lines added / deleted +264 / -4 OK
    Build / Lint / Tests ✅ / ✅ / ✅ (274 affected pass) OK

    Test Coverage Analysis

    Changed file Tier Has Tests?
    phase-executor.ts Standard ✅ phase-executor.test.ts (3 new capped cases)
    batch-executor.ts Standard ✅ batch-executor.test.ts (2 new AC-3 cases)
    run-log-schema.ts Optional (schema) ✅ run-log-schema.test.ts green
    log-writer.ts Optional (type Pick) ✅ log-writer.test.ts green
    types.ts Optional (types only) —

    Coverage: runtime-behavior files (phase-executor, batch-executor) both have dedicated capped-path tests. New tests invoke the real functions with injected executePhaseFn and assert call-counts + result fields — not tautological.


    Code Review

    Strengths:

    • Faithfully mirrors the established feat(driver): surface structured rate-limit/credits errors from SDK message stream (replaces #592 fallback noise) #732 BillingError retry-skip pattern; capped? is additive/optional, same shape as structuredError? — backward-compatible.
    • Correctly uses an explicit early return (not just an MCP-gate guard) because capped must skip cold-start retries too — the one subtlety vs. the billing case is called out in a precise code comment.
    • Reuses "failure" phase-log status + an additive capped boolean rather than expanding the PhaseStatus enum — keeps the persisted run-log schema stable (no migration).
    • AC-3 goes beyond the spec plan: also skips the outer quality-loop while, not just the inner /loop spawn — without this a capped phase under quality-loop would re-run 3× and act on partial work. Good catch, well-tested.

    Issues:

    • Sibling-site consistency (non-blocking): the spec phase's dedicated failure handling (batch-executor.ts:589-639) was not updated alongside the main phase loop. See Adversarial Re-Read for specifics + fix.

    Suggestions:

    • Fold the spec-phase signal/log-marker fix into this PR (≈4 lines + 1 test) rather than a follow-up — it's the same root cause in the same file.

    Risk Assessment

    • Likely failure mode: A capped spec phase halts with a generic "unknown" progress message (the driver returns no error string on a cap), so the user can't tell a turn cap from a real failure for that one phase. Partial spec output is still preserved and the run still halts — so no data loss or wrong-continuation; the impact is observability only.
    • Not tested: No test exercises a capped spec phase at the batch-executor level (the spec block is a separate code path from the tested main-loop path).
    • Sibling sites considered: none cross-file — capped propagation lives in phase-agnostic phase-executor.ts, so AC-1/AC-2 cover every phase uniformly. The only sibling is intra-file (below).
    • Sibling-line audit: ⚠️ The spec-phase failure branch (:598 signal, :637 log) is an intra-file sibling of the main-loop failure branch (:891 signal, :952 log) that was updated. The main loop now emits the distinct capped signal + capped log marker; the spec block does not. Confirmed by reading both branches.

    Adversarial Re-Read

    Findings: Surfaced one gap by tracing the capped path through both failure-handling sites in batch-executor.ts. The spec phase runs in its own block (:530-690), distinct from the main phase loop (:809-1059) where the AC-3 distinct-signal + capped log-marker changes were applied. For a capped spec phase:

    • ✅ partial output preserved (phaseResults.push(specResult) at :582)
    • ✅ halts cleanly (early return at :669, before parseRecommendedWorkflow at :679 — so partial spec output is never mis-parsed as a workflow)
    • ❌ progress signal is specResult.error ?? "unknown" (:598), not the distinct "turn cap reached — partial output preserved" message
    • ❌ spec phase log omits capped (:637 passes only { error, errorContext })

    Checked and cleared other concerns: (1) output now present on capped failures does not mislead any consumer — buildLoopContext (:126) is only reached via the quality loop, which capped now skips; parseRecommendedWorkflow (:679) is only reached on spec success (after the :654 early return). (2) capped ⟹ success:false invariant holds (driver sets it only on the error_max_turns branch). (3) No Non-Goals expanded into scope; no any/type erosion.

    Suggested fix (fold into PR): in the spec failure branch, mirror the main loop —

    // :598
    const extra = {
      error: specResult.capped
        ? "turn cap reached — partial output preserved (resume to continue)"
        : (specResult.error ?? "unknown"),
    };
    // :637 — add capped to the log options
    { error: specResult.error, capped: specResult.capped, errorContext: specErrorContext }

    plus a batch-executor test for a capped spec phase asserting the distinct signal + log marker.

    Status: Gaps Found


    Verdict: AC_MET_BUT_NOT_A_PLUS

    All 4 ACs are substantively met — the heart of the issue (preserve partial output + skip the un-fixable retries) lives in phase-agnostic phase-executor.ts and is correct, well-tested, and backward-compatible; CI is fully green. The one gap is a sibling-site consistency miss: the spec phase's separate failure handling doesn't surface the distinct capped signal or the capped log marker that the main loop now does, so a capped spec phase is observationally indistinguishable from a generic failure (partial work is still preserved and the run still halts — so it's an observability gap, not a correctness one). Recommend folding the ~4-line spec-block fix + one test into this PR before merge.

    Documentation

    Next Steps

    1. Apply the spec-phase fix above (batch-executor.ts:598 + :637) so AC-3's "surface the cap clearly" holds for every phase, including spec.
    2. Add a batch-executor test for a capped spec phase (distinct signal + capped log marker).
    3. Re-run /qa 739 (or /loop) — with the sibling site fixed this is a clean READY_FOR_MERGE.
  6. added a commit that references this issue on Jun 22, 2026
  7. admarble commented on Jun 22, 2026

    @admarble
    ContributorAuthor

    Quality Loop — Iteration 1/3

    Addressed the single AC_MET_BUT_NOT_A_PLUS finding from QA (sibling-site consistency gap).

    Fix applied

    • batch-executor.ts:598 — spec-phase failure signal now emits the distinct "turn cap reached — partial output preserved (resume to continue)" message when specResult.capped (was generic "unknown").
    • batch-executor.ts:637 — spec phase log now passes capped: specResult.capped (matching the main phase loop).
    • batch-executor.test.ts — added a capped-spec-phase test asserting the distinct signal, capped log marker, clean halt, and preserved partial output.

    A capped spec phase already preserved partial output and halted; this closes the observability gap so AC-3's "surface the cap clearly" now holds for every phase, including spec.

    Re-validation

    • npm run build ✅ · npm run lint ✅ (0 warnings)
    • npx vitest run src/lib/workflow/ → 944 passed, 2 skipped (+1 new test, no regressions)

    Status

    FIXED — all AC-3 sibling sites now consistent. Commit 7ff268f pushed to PR #741. Recommend re-running /qa 739 for a final READY_FOR_MERGE pass.

  8. admarble commented on Jun 22, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #739 (re-review @ 7ff268f)

    Incremental re-review after the /loop fix (7ff268f) that closed the sibling-site gap flagged in the prior QA (cb16422, AC_MET_BUT_NOT_A_PLUS).

    AC Coverage

    AC Description Status Notes
    AC-1 PhaseResult carries capped + partial output ✅ MET phase-executor.ts:764-766
    AC-2 Capped phase skips cold-start retry + MCP fallback (+ spec-extra retry) ✅ MET Early returns + !failureIsCapped guard; tests assert single invocation
    AC-3 Run loop surfaces cap clearly + preserves work (surface + halt) ✅ MET Now consistent across both failure-handling sites — main phase loop (:891/:952) and the spec-phase block (:605/:648). Distinct signal + capped log marker + clean halt + partial output preserved.
    AC-4 phase-executor.test.ts covers the capped path ✅ MET 3 unit cases + 3 batch-executor integration cases (incl. new capped-spec test)

    Coverage: 4/4 met. The prior sibling-site gap is resolved.

    CI Status

    Check State Impact
    build (22.x) ✅ pass (2m33s) MET
    typecheck ✅ pass MET
    validate-skills / validate-plugin / node-floor-guard ✅ pass MET

    CI Summary: 5 passed, 0 pending, 0 failed. mergeable: MERGEABLE.

    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 8 (1 module dir) OK
    Lines added / deleted +334 / -6 OK
    Build / Lint / Tests ✅ / ✅ / ✅ (275 affected pass) OK

    Test Coverage Analysis

    Changed file Tier Has Tests?
    phase-executor.ts Standard ✅ phase-executor.test.ts (3 capped cases)
    batch-executor.ts Standard ✅ batch-executor.test.ts (3 capped cases incl. spec sibling)
    run-log-schema.ts / log-writer.ts Optional (schema/type) ✅ suites green
    types.ts Optional (types only) —

    Code Review

    Strengths:

    • The /loop fix is a faithful mirror of the main-loop logic — same distinct message string, same capped log-marker plumbing — so the two failure-handling paths are now symmetric.
    • New capped-spec test routes through the real spec block (autoDetectPhases:true) and asserts the signal, log marker, halt, and preserved output — non-tautological.

    Issues: None blocking.

    Risk Assessment

    • Likely failure mode: None material. Across every primary phase, a turn-capped query now preserves partial output, halts cleanly, and surfaces a recognizable signal.
    • Not tested: A capped loop phase (the quality-loop recovery sub-phase) — see sibling-line audit.
    • Sibling sites considered: none cross-file — capped propagation is phase-agnostic in phase-executor.ts.
    • Sibling-line audit: Three "failed" emit sites in batch-executor.ts: spec block (:609) ✅ fixed, main phase loop (:912) ✅ fixed, and the loop phase (:1061) which still emits loopResult.error ?? "unknown" (not capped-aware). Assessed as out of scope / non-blocking: the loop phase is a conditional recovery sub-phase reached only in quality-loop mode after a non-capped primary failure; a capped loop result is still preserved (phaseResults.push) and still halts (break at :1058) — only the cosmetic distinct-signal string is absent. Outside AC-3's cited run-loop range (:867-887, :967-1041). Optional follow-up below.

    Adversarial Re-Read

    Findings: Traced the capped path through all three "failed" emit sites in batch-executor.ts plus the phase-agnostic propagation in phase-executor.ts. The spec sibling flagged last round is now closed and verified by reading both fix sites. Confirmed: (1) output on capped failures still misleads no consumer — buildLoopContext/parseRecommendedWorkflow are unreachable on the capped paths (loop skipped via !result.capped+haltedByCap; spec parse gated behind the :670 early return on failure); (2) capped ⟹ success:false invariant holds; (3) no any/type erosion, no deleted tests, no Non-Goals expanded. One residual sibling (loop-phase emit :1061) surfaced and assessed as a low-value optional follow-up, not an AC gap.

    Status: Clean (residual loop-phase observation is a recommendation, not a gap)

    Verdict: READY_FOR_MERGE

    All 4 ACs are met, the sibling-site consistency gap from the prior review is closed, CI is fully green, and local build/lint/tests pass (275 affected). The implementation is additive, backward-compatible, and well-tested. The lone residual observation (loop-phase emit not capped-aware) is a rarely-reached, out-of-AC-scope edge where partial work is still preserved and the run still halts — recommended as an optional follow-up, not a merge blocker.

    Documentation

    Next Steps

    1. Merge-ready — squash/merge PR feat(#739): preserve partial output for turn-capped phases in phase-executor #741.
    2. (Optional follow-up) Mirror the capped signal + log marker at the loop-phase emit site (batch-executor.ts:1061) for full cross-phase symmetry. Low priority — quality-loop-only, partial work already preserved.
  9. added
    ready-for-review
    on Jun 22, 2026
  10. admarble commented on Jun 22, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #739

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original PhaseResult carries capped + partial output from a capped driver result MET capped?: boolean added to PhaseResult (types.ts) and PhaseLogSchema (run-log-schema.ts); executePhase's failure return now propagates capped and output (previously dropped) — phase-executor.ts:766-767.
    AC-2 Original Capped phase does not trigger cold-start retry or MCP fallback MET Explicit early returns in both the skipColdStartRetry branch (:854) and the cold-start loop (:882), positioned before the MCP fallback (:934) and spec-extra retry (:991). Belt-and-suspenders !failureIsCapped guard added at the MCP gate.
    AC-3 Original Run loop surfaces the cap clearly + preserves partial work (continue-vs-halt decided) MET Decision = surface + halt (per issue's lean). Distinct signal turn cap reached — partial output preserved (resume to continue); partial output preserved in phaseResults; additive capped log marker (status stays "failure", no new enum); haltedByCap short-circuits the quality loop and outer retry. Spec-phase sibling site covered in commit 7ff268f.
    AC-4 Original phase-executor.test.ts covers the capped path end-to-end MET 3 unit tests (flag+output preserved, no cold-start/MCP fallback, no spec-extra retry) + 3 batch-executor integration tests (distinct signal, log marker+halt, quality-loop skip, spec sibling).

    Coverage: 4/4 AC items fully met


    CI Status

    Check State Impact
    build (22.x) pass ✅ MET
    node-floor-guard pass ✅ MET
    typecheck pass ✅ MET
    validate-plugin pass ✅ MET
    validate-skills pass ✅ MET

    CI Summary: 5 passed, 0 pending, 0 failed (PR #741)


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 (test-only as never/as PhaseResult casts) OK
    Deleted tests 0 OK
    Files changed 8 OK
    Lines added +334 -
    Lines deleted -6 -
    Local tests 166 passed (phase-executor + batch-executor) OK

    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    phase-executor.ts Standard ✅ Yes phase-executor.test.ts (3 new #739 tests)
    batch-executor.ts Standard ✅ Yes batch-executor.test.ts (3 new #739 tests)
    types.ts Optional N/A Additive interface field (no logic)
    run-log-schema.ts Optional N/A Additive zod field (no logic)
    log-writer.ts Optional N/A Adds capped to a Pick<> allow-list (no logic)

    Coverage: 2/2 logic files have corresponding tests.


    Code Review

    Strengths:

    • Faithfully mirrors the feat(driver): surface structured rate-limit/credits errors from SDK message stream (replaces #592 fallback noise) #732 structured-error retry-gating pattern; capped? is additive/optional, same shape as structuredError? — zero impact on existing consumers.
    • Both intra-file failure-return sites in executePhaseWithRetry are guarded (skip-cold-start branch + cold-start loop), with a defensive !failureIsCapped guard at the MCP gate documented as belt-and-suspenders.
    • The spec-phase sibling site (separate failure handling from the main loop) was explicitly addressed in a follow-up commit — exactly the §4-Q5/§5 sibling-site concern.
    • Excellent comment density explaining why an explicit early return is needed (vs. the billing case which still cold-start-retries in the <60s window).

    Issues: None blocking.

    Suggestions: None material.


    Risk Assessment

    • Likely failure mode: A non-capped failure now also carries output on the failure return (previously dropped). Traced both consumers: error-context builder (batch-executor.ts:126) — strictly beneficial; parseRecommendedWorkflow(specResult.output) (:695) — unreachable on failure because the spec failure path early-returns at :670. No behavior change for non-capped failures.
    • Not tested: No end-to-end test through the real ClaudeCodeDriver returning error_max_turns (driver→phase-executor wiring is unit-mocked) — acceptable; the driver slice was covered in Graceful error_max_turns handling for subagents #733/PR feat(#733): graceful error_max_turns handling for subagents #737.
    • Sibling sites considered: Cross-file — driver sets capped (claude-code.ts), /qa & /exec skills consume it (Graceful error_max_turns handling for subagents #733); this PR adds the orchestrator consumers (phase-executor + batch-executor). No other orchestrator-level site drops the flag.
    • Sibling-line audit: Both failure-return paths in executePhaseWithRetry audited and guarded; the mapAgentSuccessToPhaseResult returns (lines 401/415) are on the success===true path where capped is necessarily false, so correctly omitted; spec-phase failure block in batch-executor audited and handled.

    Adversarial Re-Read

    Findings: No gaps found because: (1) ran all 166 tests in both touched test files — green, and the new capped progress signal is observable in the emitted SEQUANT_PROGRESS lines; (2) traced the newly-unconditional output propagation to both consumers and confirmed the spec-recommendation parser is unreachable on a failed/capped spec (early return at :670); (3) inspected all four success:false return sites in phase-executor and confirmed the two non-propagating ones are on the success-mapping path; (4) verified continue-vs-halt is decided (surface+halt) and the outer quality-loop retry is also short-circuited via haltedByCap; (5) no Non-Goals from the issue body have crept into scope — change is confined to PhaseResult plumbing + retry-gating + run-loop signal.

    Status: Clean


    Verdict: READY_FOR_MERGE

    All 4 ACs met, CI green across all 5 checks, tests pass locally (166), CHANGELOG [Unreleased] entry present, and the implementation cleanly mirrors the established #732/#733 patterns with strong sibling-site coverage and adversarial re-read clean.

    Documentation

    Next Steps

    1. Merge PR feat(#739): preserve partial output for turn-capped phases in phase-executor #741.
  11. added 2 commits that reference this issue on Jun 22, 2026
  12. added 3 commits that reference this issue on Jul 24, 2026
  13. added a commit that references 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

    enhancementmulti-agentplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions