Skip to content

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

Merged
admarble merged 3 commits into
mainfrom
feature/739-feat-orchestrator-preserve-partial-output-for-turn
Jun 23, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/739-feat-orchestrator-preserve-partial-output-for-turn

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Completes the follow-up carved out of #733. At the orchestrator level the driver's capped flag was dead data: phase-executor's failure return dropped both the flag and the partial output, so a top-level phase query (not a spawned sub-agent) that hit its maxTurns ceiling discarded its work exactly as before #733.

Pre-PR AC Verification

AC Description Status Evidence
AC-1 PhaseResult carries capped + partial output from a capped driver result ✅ Implemented types.ts:223 (capped?); phase-executor.ts:765-767 (propagate capped + output)
AC-2 Capped phase skips cold-start retry AND MCP fallback (and spec-extra retry) ✅ Implemented phase-executor.ts:854,882 (early returns); :947 (!failureIsCapped MCP guard)
AC-3 Run loop surfaces the cap clearly, preserves partial work, halts cleanly ✅ Implemented batch-executor.ts:886-893 (distinct signal), :948 (log marker), :987 + :1068 (skip inner /loop + outer quality-loop)
AC-4 phase-executor.test.ts covers the capped path end-to-end ✅ Implemented phase-executor.test.ts (3 capped cases) + batch-executor.test.ts (2 AC-3 integration cases)

Design decision (AC-3, open question in spec): chose surface + halt per the spec recommendation — auto-continuing on partial work is risky. Reversible later via the now-first-class capped flag.

Log-schema decision: added an additive optional capped boolean to PhaseLogSchema and reused the "failure" status rather than introducing a new PhaseStatus enum value — keeps the persisted-log schema stable (spec Open Question #2 recommendation).

Test plan

  • npm run build — passes (tsc clean)
  • npm run lint — passes (0 warnings)
  • npx vitest run src/lib/workflow/ — 943 passed, 2 skipped
  • Orchestrator integration tests (__tests__/run-orchestrator*.test.ts) — 48 passed

Closes #739

🤖 Generated with Claude Code

…xecutor

#733 made the driver return a soft `capped` result for `error_max_turns`,
but at the orchestrator level the flag was dead data: phase-executor's
failure return dropped both `capped` and the partial `output`, so a
top-level phase query that hit its turn cap discarded its work.

- AC-1: add additive `capped?` to `PhaseResult` and propagate it plus the
  partial `output` on the failure return (output was previously dropped).
- AC-2: short-circuit `executePhaseWithRetry` on a capped result before the
  cold-start retry, MCP fallback, and spec-extra retry — a retry cannot
  un-cap a turn limit (mirrors the #732 billing skip, but via explicit early
  return since capped must skip cold-start retries too). Belt-and-suspenders
  `!failureIsCapped` guard at the MCP gate.
- AC-3: run loop surfaces a distinct "turn cap reached — partial output
  preserved" signal (not a generic failure), persists the partial output and
  an additive `capped` marker on the phase log (status stays "failure"), and
  halts cleanly — skipping both the inner /loop spawn and the outer
  quality-loop retry so it never acts on incomplete work.
- AC-4: capped-path tests in phase-executor.test.ts (flag + output preserved,
  single invocation / no MCP fallback, no spec-extra retry) and
  batch-executor.test.ts (distinct signal, capped log marker, clean halt,
  quality-loop skip).

Entire-Checkpoint: c5a9668ff2b8
admarble added 2 commits June 22, 2026 09:20
…ng site

QA (#741) found the AC-3 run-loop signalling was applied only to the main
phase loop. The spec phase has its own failure-handling block, so a capped
spec phase preserved partial output and halted cleanly but emitted a generic
"unknown" signal and omitted the `capped` log marker — making it
indistinguishable from a real failure.

Mirror the main loop in the spec block:
- distinct "turn cap reached — partial output preserved" progress signal
- pass `capped: specResult.capped` to the spec phase log

Adds a batch-executor test for a capped spec phase (distinct signal, capped
log marker, clean halt, partial output preserved).

Entire-Checkpoint: 469a5a4b8160
Address two gaps found in review of PR #741:

1. Output scope creep: phase-executor's failure return propagated the
   partial output unconditionally, silently injecting a 2000-char output
   tail into the /loop fix-context (formatFailureContext) for every
   genuine (non-capped) failure — behaviour that never existed pre-#739
   and was outside the issue's scope. Gate output on capped, extracted
   into a unit-tested mapAgentFailureToPhaseResult helper symmetric to
   mapAgentSuccessToPhaseResult.

2. Capped marker not persisted to state: a turn-capped halt was recorded
   in .sequant/state.json as a plain "failed" phase, indistinguishable
   from a genuine failure on resume (only the run-log carried capped).
   Add an additive capped field to PhaseStateSchema and thread it through
   updatePhaseStatus and the two batch-executor call sites, making the
   PR's 'reversible later' resume path first-class.

Tests: non-capped failure drops output (phase-executor.test.ts), capped
marker persisted/unset (state-manager.test.ts). Full workflow suite green
(948 passed), lint clean.
@admarble
admarble merged commit 19429d6 into main Jun 23, 2026
5 checks passed
@admarble
admarble deleted the feature/739-feat-orchestrator-preserve-partial-output-for-turn branch June 23, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant