Skip to content

feat(#733): graceful error_max_turns handling for subagents - #737

Merged
admarble merged 3 commits into
mainfrom
feature/733-graceful-error-max-turns-handling-for-subagents
Jun 22, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/733-graceful-error-max-turns-handling-for-subagents

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

When a subagent hits its maxTurns cap, ClaudeCodeDriver previously treated error_max_turns as a hard failure (error: "Max turns reached"), discarding whatever partial work the agent had already produced. Turn caps are live on every agent (#484), so this is a real, reachable failure mode that wastes completed work. This change makes the cap a soft, recoverable outcome.

  • AC-1 — Driver: added additive capped?: boolean to AgentPhaseResult. On error_max_turns the driver now warns (via the onStderr channel) instead of erroring and returns the partial output flagged capped: true, with no hard error string. Branched out of the error-subtype switch so it never carries error.
  • AC-2 — /qa: a turn-capped spawned check is flagged ⚠️ Inconclusive in the QA summary and never fails the whole QA phase on the cap alone (partial findings are kept; an unverified AC becomes NEEDS_VERIFICATION, not AC_NOT_MET).
  • AC-3 — /exec: a turn-capped implementer is treated as incomplete, reporting which tasks finished vs. which were capped so the next iteration resumes them.

Out of scope (per spec): orchestrator-level partial preservation in phase-executor.ts (the failure path still discards on success: false) — confined to the driver + skills as scoped; settings/CLI cap overrides remain blocked on #632 / anthropics/claude-code#43869.

Pre-PR AC Verification

AC Source Description Status Evidence
AC-1 Original Driver warns + returns partial output + capped: true ✅ Implemented claude-code.ts:178-191, agent-driver.ts:70-77; test claude-code.test.ts:46-86
AC-2 Original /qa capped check → inconclusive, not phase failure ✅ Implemented qa/SKILL.md "Turn-Capped Checks → Inconclusive" (×3 mirrors)
AC-3 Original /exec capped implementer → incomplete, finished-vs-capped ✅ Implemented exec/SKILL.md §4b2 "Detecting Turn-Capped Implementers" (×3 mirrors)

Test plan

  • npm run build — passes (tsc clean)
  • npm run lint — passes (0 warnings)
  • npm test (drivers + phase-executor) — 179 passed, 2 skipped
  • check-skill-sync.ts — qa/exec SKILL.md mirrors in sync (pre-existing divergences elsewhere are unrelated)
  • lint:skill-calls — no violations
  • New unit test asserts error_max_turns → partial output + capped: true, no hard error, warns via onStderr

Closes #733

When a subagent hits its maxTurns cap, ClaudeCodeDriver previously
treated error_max_turns as a hard failure, discarding the partial work
already produced. Turn caps are live on every agent (#484), so this is a
real, reachable failure mode.

- AC-1: add additive `capped?: boolean` to AgentPhaseResult; on
  error_max_turns the driver warns (via onStderr) instead of erroring and
  returns the partial output flagged `capped: true`, with no hard error
  string. Branched out of the error-subtype switch. Unit test added.
- AC-2: /qa treats a turn-capped check as inconclusive (flagged in the
  summary, not a phase failure on the cap alone).
- AC-3: /exec treats a turn-capped implementer as incomplete (reports
  finished-vs-capped tasks for the next iteration to resume).

Orchestrator-level partial preservation in phase-executor is out of scope
(sub-agent caps only). Skill changes synced across all three mirrors.

Entire-Checkpoint: 12702c080a1d
admarble added 2 commits June 20, 2026 19:36
…anch

/testgen follow-up: AC-1's happy-path unit test already exists. Add the
inferred failure path the spec's verification implies — prove the new
error_max_turns branch is narrow: other error subtypes (error_during_
execution) still fail hard (success:false, real error string, no capped
flag), so soft-cap handling can't mask a genuine failure. Refactor the
mocked SDK result to be configurable via vi.hoisted; reset in beforeEach.

Entire-Checkpoint: 5a81b6733c70
…error-max-turns-handling-for-subagents

# Conflicts:
#	CHANGELOG.md
#	src/lib/workflow/drivers/agent-driver.ts
#	src/lib/workflow/drivers/claude-code.test.ts
@admarble
admarble merged commit 0a39ab7 into main Jun 22, 2026
8 checks passed
@admarble
admarble deleted the feature/733-graceful-error-max-turns-handling-for-subagents branch June 22, 2026 13:57
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.

Graceful error_max_turns handling for subagents

1 participant