diff --git a/lib/providers/anthropic.mjs b/lib/providers/anthropic.mjs index 715e3a6..23feee6 100644 --- a/lib/providers/anthropic.mjs +++ b/lib/providers/anthropic.mjs @@ -1107,7 +1107,21 @@ async function* _spawnAndStream(irRequest, authContext, spawnImpl) { // Process close — safety net if no `result` event was emitted // (e.g. version drift where stream-json is not supported without -p). // Only throw on non-zero exit; zero exit with no result → emit synthetic stop. - if (exitCode !== 0 && !spawnTimedOut) { + // + // 2026-05-28 PR-B fold-in: when the spawn is sandbox-wrapped via /bin/sh -c + // ' ... claude ...', the wrapping shell can exit with code + // `null` (signal-cleanup) even though the model completed and emitted the + // `result` event. resultEventSeen=true is the authoritative signal that + // the model finished successfully; an abnormal exit *after* that is just + // sandbox bookkeeping noise, not a real failure. Without this guard, the + // HTTP layer would receive a thrown ProviderError despite chunks having + // been yielded, and the response would come back with content:null. + // + // Live PI231 evidence (2026-05-28 commit 2864275 deploy): + // stream NDJSON: delta(DIRECT_PROOF) → stop → close(null) + // without this guard: ProviderError 'claude exit null' → empty response + // with this guard: chunks propagate normally, content arrives + if (exitCode !== 0 && !spawnTimedOut && !resultEventSeen) { const errMsg = accumulatedStderr.slice(0, 300) || `claude exit ${exitCode}`; throw new ProviderError(errMsg, 'SPAWN_FAILED'); }