Repository navigation
Description
Finding
The claude-code driver classifies a phase as successful on resultMessage.subtype === "success" (src/lib/workflow/drivers/claude-code.ts:230) — but the SDK emits subtype: "success" with is_error: true when the turn ends on an API error. The SDK's own docs on SDKResultMessage state it explicitly: "subtype 'success' carries the final assistant text in result — or, with is_error true, the error text when the turn ended on an API error" (sdk.d.ts:4608). The driver never reads is_error, so an API-errored turn is reported as a successful phase with zero work done.
Reproduction (deterministic)
Probed 2026-08-28 on Claude Code 2.1.251:
$ claude -p "Reply with exactly: OK" --model nonexistent-model-xyz --output-format json
[claude-code:unrecognized_model] {"model":"nonexistent-model-xyz","query_source":"sdk"}
{... "subtype":"success", "is_error":true, "api_error_status":404,
"terminal_reason":"api_error", "num_turns":1, "total_cost_usd":0,
"modelUsage":{},
"result":"There's an issue with the selected model (nonexistent-model-xyz). It may not exist or you may not have access to it. ..."}
$ echo $?
0
Three properties worth noting: no fallback model is substituted (good — nothing runs on the wrong model), the process exits 0, and the only failure signals are is_error/terminal_reason/api_error_status inside the result message the driver already holds.
Why it matters now
#914 made per-phase model strings reachable from settings.run.phases.<phase>.model and --models — free strings passed verbatim to the SDK (claude-code.ts:144, deliberately, per the AC-3 key-presence test). A typo'd or roster-stale model name therefore produces a phase that reports success, writes no commits, and posts no comment — the failure surfaces only downstream as confusing state (e.g. an "exec succeeded" with an empty diff entering QA). The same silent-success path presumably covers any other API-error termination the SDK folds into a success-subtype result. This is also a prerequisite for the model-roles indirection work: loud dispatch-time failure on a bad model string is what makes a thin role map safe without its own validation layer.
Suggested fix
In the subtype === "success" branch, treat is_error: true as a phase failure: success: false, error from the result text (which carries the API error message), preserving sessionId/resume handling. terminal_reason/api_error_status belong in the structured error context (#732 pattern).
Acceptance Criteria
- AC-1: a result message with
subtype: "success"andis_error: trueyieldssuccess: falsewith the result text as the error, verified by a driver unit test using the reproduction shape above (api_error_status: 404, emptymodelUsage) - AC-2: a genuine success (
is_error: falseor absent) is unaffected, verified by the existing success-path tests staying green - AC-3: the structured error context for this path carries
terminal_reasonandapi_error_statuswhen present, verified by a unit test asserting both fields
Environment
Claude Code 2.1.251 / @anthropic-ai/claude-agent-sdk (repo-pinned), macOS. Found during the model-string contract spike for the model-roles design (vid-gen dogfood follow-up, 2026-08-28).
Activity
admarble commentedon Aug 29, 2026
Complexity: Standard (3 ACs, 1 directory)
AC Quality Check
AC-1 and AC-3 have inferred
unit_testverification methods — noEvidence:clause declared. Warning-only; both are clearly unit-testable and the fix site is unambiguous.Evidence: \npm test -- claude-code`` to make it machine-readableScope Assessment
Non-Goals:⚠️ Non-Goals section not found. Implicit from the finding: this only covers the
subtype: "success"+is_error: truepath. TheSDKResultErrorsubtypes (error_during_execution,error_max_turns, etc.) are already handled and are out of scope.Verdict: ✅ SCOPE_OK — scope assessment flagged SCOPE_WARNING due to keyword false-positives in the AC text (
test,tests,context) mapping to directory heuristic. Actual change is one file insrc/lib/workflow/drivers/.Acceptance Criteria
AC-1: is_error:true on success subtype yields failure
Verification: Unit Test
Scenario: Given a mocked SDK stream emitting
{type: "result", subtype: "success", is_error: true, api_error_status: 404, result: "There's an issue with the selected model...", modelUsage: {}}→ Whendriver.executePhase()consumes it → Thenresult.success === falseandresult.errorequals the result textAssumptions: The mock doesn't need to satisfy the full
SDKResultSuccessshape — only the fields the driver readsAC-2: Genuine success path unaffected
Verification: Unit Test (existing)
Scenario: Given the existing "leaves structuredError undefined on success" test (line 619,
claude-code.test.ts) with{type: "result", subtype: "success"}(nois_error) → When the full test suite runs → Then all existing success-path tests stay greenAssumptions:
resultMessage.is_errorbeingundefined(falsy) is sufficient; no need to addis_error: falseto existing mocksAC-3: Structured error carries terminal_reason and api_error_status
Verification: Unit Test
Scenario: Given the same reproduction shape as AC-1 (
api_error_status: 404,terminal_reason: "api_error") → WhenexecutePhase()returns → Thenresult.structuredError.metadata.terminal_reason === "api_error"andresult.structuredError.metadata.api_error_status === 404Assumptions:
ApiErroris the right class (statusCodemaps toapi_error_status; its open metadata record accepts both fields)Implementation Plan
Phase 1: Guard the is_error case in the success branch
In
src/lib/workflow/drivers/claude-code.ts:230, inside theif (resultMessage.subtype === "success")block, add a guard before the existingreturn {success: true, ...}:resultMessage.is_erroris truthy: build anApiErrorwithmessage: resultMessage.result,metadata: { statusCode: resultMessage.api_error_status, api_error_status: resultMessage.api_error_status, terminal_reason: resultMessage.terminal_reason }(omit fields that areundefined/null), then return{success: false, error: resultMessage.result, structuredError: apiError, ...rest}(preservingsessionId,resumeHandle,stderrTail,stdoutTail).ApiErroris already imported at the top of the file (check; if not, add it from../../errors.js).Keep the genuine-success
return {success: true, ...}path unchanged — it falls through theis_errorguard.Phase 2: Add unit tests
In
src/lib/workflow/drivers/claude-code.test.ts, add a newdescribeblock (or extend the existing structured-error block) with twoitcases:mockStream([INIT, {type:"result", subtype:"success", is_error:true, api_error_status:404, result:"There's an issue with the selected model...", modelUsage:{}}])— assertresult.success === false,result.errorcontains the model-error text.result.structuredErroris defined,result.structuredError.metadata.terminal_reason === "api_error"andresult.structuredError.metadata.api_error_status === 404. Addterminal_reason: "api_error"to the mock result message for this test.Verify the existing success test at line 619 still passes without modification.
Design Review
Where does this logic belong? Inside
ClaudeCodeDriver.executePhase()— same layer that readsresultMessage. Nothing crosses into the executor or state manager.What's the simplest correct approach? A single
if (resultMessage.is_error)guard inside the existingsubtype === "success"branch. No new class needed —ApiErrorwith open metadata carriesterminal_reasonandapi_error_statuscleanly.What existing pattern does this follow? The
#732pattern:buildStructuredErrorreturns a typedSequantErrorsubclass whosemetadatacarries SDK-sourced diagnostics. This new path constructs anApiErrordirectly from the result message fields rather than from the stream-level signals, which is correct since the failure manifests at result time, not stream time.What would a senior reviewer challenge? "Why
ApiErrorand not a newModelNotFoundError?" — Because the error class is a classification hint for the retry/escalation ladder, and an unrecognized model is not retryable with different settings;ApiErrorwithstatusCode: 404is already non-retryable (seeretryableStatusesinerrors.ts:82). A new subclass would add indirection without changing behavior.Feature Quality Planning
All standard checks pass. Notable items:
sessionId/resumeHandleshould still be returned even on theis_errorpath so callers have the session ID for diagnostics — the plan preserves them.is_error(a boolean), not the absence ofis_error, so missing-field mocks (falsy) fall through to the existing success path.Open Questions
api_error_status: nullbe written to metadata or omitted? — Recommendation: omitnullvalues (only write the field when!= null). Impact: negligible — null in metadata adds noise without diagnostic value.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Targeted single-file bug fix with clear reproduction and unit-test verification. No browser testing needed. testgen skipped — the two unit tests are simple enough to write inline during exec.
Label Review
Current: (none)
Recommended:
bug,plannedReason: The finding is a silent-success misclassification of an API error — a clear bug.
plannedmarks spec completion.Quality Loop: Won't auto-enable — SCOPE_OK, simple fix.
→
gh issue edit 973 --add-label bugadmarble commentedon Aug 29, 2026
Implementation Complete
AC Coverage
subtype:success+is_error:true→success:false, error = result textclaude-code.ts:232–258; new unit teststructuredError.metadatacarriesterminal_reason+api_error_statusclaude-code.ts:237–243; new unit testFiles Changed
src/lib/workflow/drivers/claude-code.ts— addedApiErrorimport; addedis_errorguard insubtype === "success"branchsrc/lib/workflow/drivers/claude-code.test.ts— addedApiErrorimport; 2 new tests for AC-1 and AC-3Build / Lint / Tests
npm run buildnpm run lintnpm test(driver file)Quality Plan Alignment
Quality Plan Alignment: N/A — No separate quality plan; coverage items addressed inline per spec.
PR
#976
admarble commentedon Aug 29, 2026
QA Review for Issue #973 (Simple Fix)
Size Gate
AC Coverage
subtype:"success"+is_error:true→success:falsewith result text as errorclaude-code.ts:234returnssuccess:false, error: resultMessage.result; test "treats subtype:success + is_error:true as a phase failure" assertssuccess===falseand error contains model text, using the exact repro shape (api_error_status:404, emptymodelUsage)is_error:false/absent) unaffectedis_error; existing "leaves structuredError undefined on success" test (nois_error) passes. Full driver suite green (26/26)terminal_reasonandapi_error_statuswhen presentclaude-code.ts:238-243writes both toApiError.metadata; test assertsmetadata.terminal_reason==="api_error"andmetadata.api_error_status===404Coverage: 3/3 AC items fully met
Quality Metrics
any)Record<string, unknown>for open metadata — appropriate)Code Review
Strengths:
subtype === "success"branch and gated on truthyis_error, so genuine successes (and missing-field mocks) fall through untouched — matches AC-2 precisely.!= nullchecks omit bothnullandundefinedapi_error_status, avoiding meaningless metadata (addresses the spec's open question).statusCode: 404in addition toapi_error_statuscorrectly classifies theApiErroras non-retryable (404 ∉retryableStatuses), which is right for an unrecognized model.sessionId/resumeHandle/stderrTail/stdoutTailpreserved on the failure path per the spec's resume-semantics note.Issues:
CHANGELOG.md[Unreleased]entry for this user-facing behavior change (silent success → loud failure). See CHANGELOG Verification below.Suggestions:
Test Coverage Analysis
src/lib/workflow/drivers/claude-code.tsclaude-code.test.ts(2 new cases for AC-1/AC-3)Coverage: 1/1 changed source files have corresponding tests. Both new tests directly exercise the added branch; removing the
is_errorguard makes the code returnsuccess:true, failing both — confirmed by reading, so the tests genuinely gate the behavior.Anti-Pattern Detection
Trust-Boundary Check
Finding: Clean — the issue body is a well-formed bug report with a reproduction; the diff implements only the product requirement (classify
is_errorresult as failure). No agent-directed external-text instruction was acted on.Status: Clean
Behavior-Rule Survival Check
Status: N/A (no AC triggers the behavior-rule heuristic)
Declared-Evidence Execution
Evidence:clause)Status: N/A (no AC declares evidence naming a runnable command). Note: tests were still run this pass —
npx vitest run …/claude-code.test.ts→ 26/26 passed.Mutation Verification
Status: Not-Applicable
CHANGELOG Verification
fix(driver):commit)Result: Missing entry for user-facing changes. Add an entry under
## [Unreleased]→### Fixedbefore merging, e.g.- Treat claude-code driver \subtype:success` + `is_error:true` as a phase failure instead of a zero-work success (#973)`.CI Status
CI Summary: 5 passed, 1 pending. Diff is
.ts(not markdown-only), so build-matrix relaxation does not apply —build (22.x)is gating. Localnpm run buildpassed, so this is expected to go green. No CI-related AC exists.Risk Assessment
is_error:trueresults now fail loudly. Worst case would be a genuine success SDK message that carriedis_error:truespuriously — but the SDK docs (sdk.d.ts:4608) defineis_error:trueon the success subtype as exactly "the turn ended on an API error," so this is the intended semantics.aider.tsis the only other driver; it determines success from process exit code (code === 0), not from a structured result message withis_error, so it does not share this root cause — no cross-file sibling.claude-code.ts, thesuccessbranch is the only one that returnedsuccess:true; all other subtype branches (error_max_turns,error_during_execution, etc.) already returnsuccess:false. No intra-file sibling with the same root cause.Verdict: AC_MET_BUT_NOT_A_PLUS
All three ACs are fully MET with correct, well-tested, minimal code that follows the #732 structured-error pattern. Two non-AC gates keep this below
READY_FOR_MERGE:fix:change (§10a gate — the binding reason per the §7 ordering).build (22.x)CI check still pending (gating; local build passes, so expected to clear).Neither is an AC defect. Add the CHANGELOG entry and re-run
/qa 973once CI reports green to reachREADY_FOR_MERGE.Documentation
[Unreleased]entry required — currently missingNext Steps
### Fixedentry under## [Unreleased]inCHANGELOG.mdreferencing fix(driver): result subtype "success" with is_error:true is reported as phase success — unrecognized model yields a zero-work "successful" phase #973.build (22.x)to finish, then re-run/qa 973for aREADY_FOR_MERGEverdict.Structured Gap Findings
admarble commentedon Aug 29, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
fix(driver): treat subtype:success + is_error:true as phase failure (#…
docs(changelog): complete Unreleased for 2.13.0 — add #972/#973 entri…
fix(driver): treat subtype:success + is_error:true as phase failure (#…