diff --git a/dist/action/211.index.js b/dist/action/211.index.js index e4103d984..e67af568b 100644 --- a/dist/action/211.index.js +++ b/dist/action/211.index.js @@ -13843,6 +13843,11 @@ async function analyzeHunk(skill, hunkCtx, repoPath, options, callbacks, prConte ? 'provider_unavailable' : 'sdk_error'; const failureMessage = `Runtime execution failed: ${errorSummary}`; + // Provider errors are often transient. Retry them like thrown API errors; + // the last attempt falls through and reports the failure. + if (failureCode === 'provider_unavailable' && attempt < retryConfig.maxRetries) { + throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__/* .ProviderResultError */ .z3(failureMessage); + } const openReason = recordCircuitFailure(options, failureCode, failureMessage, failureCode === 'provider_unavailable' ? providerErrorContext(options, resultMessage, errorSummary) : undefined); @@ -14466,7 +14471,9 @@ async function runSkillAnalysis(skill, context, options = {}) { && analysisFailures.every((failure) => failure.code === 'provider_unavailable')) { throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__/* .SkillRunnerError */ .cy(`Provider unavailable: all ${totalHunks} chunk${totalHunks === 1 ? '' : 's'} failed to analyze. Warden stopped early.`, { code: 'provider_unavailable' }); } - throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__/* .SkillRunnerError */ .cy(`All ${totalHunks} chunk${totalHunks === 1 ? '' : 's'} failed to analyze. ` + + const reasons = [...new Set(analysisFailures.map((failure) => `${failure.code}: ${failure.message}`))]; + throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__/* .SkillRunnerError */ .cy(`All ${totalHunks} chunk${totalHunks === 1 ? '' : 's'} failed to analyze` + + `${reasons.length > 0 ? ` (${reasons.join('; ')})` : ''}. ` + `This usually indicates an authentication problem. ${allHunksFailedGuidance(options.runtime)}`, { code: 'all_hunks_failed' }); } let finalFindings = allFindings; diff --git a/dist/action/663.index.js b/dist/action/663.index.js index 95361b1f0..e79cc6f4a 100644 --- a/dist/action/663.index.js +++ b/dist/action/663.index.js @@ -91,7 +91,8 @@ module.exports = webpackEmptyAsyncContext; /* harmony export */ bk: () => (/* binding */ mapExtractionErrorCode), /* harmony export */ cy: () => (/* binding */ SkillRunnerError), /* harmony export */ fe: () => (/* binding */ classifyError), -/* harmony export */ mu: () => (/* binding */ isSubprocessError) +/* harmony export */ mu: () => (/* binding */ isSubprocessError), +/* harmony export */ z3: () => (/* binding */ ProviderResultError) /* harmony export */ }); /* harmony import */ var _anthropic_ai_sdk__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(35035); /* harmony import */ var _runtimes_model_selectors_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(85286); @@ -187,11 +188,21 @@ class WardenAuthenticationError extends Error { this.name = 'WardenAuthenticationError'; } } +/** A runtime run that ended with `provider_error` instead of throwing. Thrown so the hunk retries. */ +class ProviderResultError extends Error { + constructor(message) { + super(message); + this.name = 'ProviderResultError'; + } +} /** * Check if an error is retryable. - * Retries on: rate limits (429), server errors (5xx), connection errors, timeouts. + * Retries on: rate limits (429), server errors (5xx), connection errors, timeouts, + * and runtime results that reported a provider error. */ function isRetryableError(error) { + if (error instanceof ProviderResultError) + return true; if (error instanceof _anthropic_ai_sdk__WEBPACK_IMPORTED_MODULE_0__/* .RateLimitError */ .OE) return true; if (error instanceof _anthropic_ai_sdk__WEBPACK_IMPORTED_MODULE_0__/* .InternalServerError */ .PO) diff --git a/packages/warden/src/sdk/analyze.test.ts b/packages/warden/src/sdk/analyze.test.ts index bc57dbee0..8cee4b300 100644 --- a/packages/warden/src/sdk/analyze.test.ts +++ b/packages/warden/src/sdk/analyze.test.ts @@ -494,6 +494,48 @@ describe('analyzeFile', () => { consoleSpy.mockRestore(); }); + it('retries a hunk when the runtime reports a provider error', async () => { + const runSkill = vi.fn() + .mockResolvedValueOnce({ + result: { + status: 'provider_error', + text: '', + errors: ['Internal error during token generation'], + usage: makeUsage(), + }, + }) + .mockResolvedValueOnce({ + result: { status: 'success', text: '{"findings":[]}', errors: [], usage: makeUsage() }, + }); + vi.mocked(getRuntime).mockReturnValue({ + name: 'pi', + runSkill, + runAuxiliary: vi.fn(), + runSynthesis: vi.fn(), + } as unknown as Runtime); + const onRetry = vi.fn(); + + const result = await analyzeFile( + { + name: 'security-review', + description: 'Security review.', + prompt: 'Return findings as JSON.', + }, + makePreparedFile(1), + '/tmp/repo', + { + concurrency: 1, + retry: { maxRetries: 2, initialDelayMs: 1, backoffMultiplier: 1, maxDelayMs: 1 }, + }, + { onRetry }, + ); + + expect(runSkill).toHaveBeenCalledTimes(2); + expect(onRetry).toHaveBeenCalledTimes(1); + expect(result.failedHunks).toBe(0); + expect(result.hunkFailures).toEqual([]); + }); + it('preserves the response model when the circuit opens on an SDK-reported provider error', async () => { const controller = new AbortController(); const circuitBreaker = new ProviderFailureCircuitBreaker({ diff --git a/packages/warden/src/sdk/analyze.ts b/packages/warden/src/sdk/analyze.ts index 034853b33..1ec4553a9 100644 --- a/packages/warden/src/sdk/analyze.ts +++ b/packages/warden/src/sdk/analyze.ts @@ -4,7 +4,7 @@ import { isExtractionErrorCode } from '../types/index.js'; import type { ErrorCode, Finding, RetryConfig } from '../types/index.js'; import { getHunkLineRange, type HunkWithContext } from '../diff/index.js'; import { Sentry, emitExtractionMetrics, emitRetryMetric, emitSkillMetrics, ensureLocalTracing } from '../sentry.js'; -import { SkillRunnerError, WardenAuthenticationError, isRetryableError, isAuthenticationError, isAuthenticationErrorMessage, isSubprocessError, classifyError, mapExtractionErrorCode, sanitizeErrorMessage, type ProviderErrorContext } from './errors.js'; +import { ProviderResultError, SkillRunnerError, WardenAuthenticationError, isRetryableError, isAuthenticationError, isAuthenticationErrorMessage, isSubprocessError, classifyError, mapExtractionErrorCode, sanitizeErrorMessage, type ProviderErrorContext } from './errors.js'; import { genAiProviderName } from './otel.js'; import type { CircuitBreakerReason } from './circuit-breaker.js'; import { DEFAULT_RETRY_CONFIG, calculateRetryDelay, sleep } from './retry.js'; @@ -498,6 +498,11 @@ async function analyzeHunk( ? 'provider_unavailable' : 'sdk_error'; const failureMessage = `Runtime execution failed: ${errorSummary}`; + // Provider errors are often transient. Retry them like thrown API errors; + // the last attempt falls through and reports the failure. + if (failureCode === 'provider_unavailable' && attempt < retryConfig.maxRetries) { + throw new ProviderResultError(failureMessage); + } const openReason = recordCircuitFailure( options, failureCode, @@ -1278,8 +1283,10 @@ async function runSkillAnalysis( { code: 'provider_unavailable' }, ); } + const reasons = [...new Set(analysisFailures.map((failure) => `${failure.code}: ${failure.message}`))]; throw new SkillRunnerError( - `All ${totalHunks} chunk${totalHunks === 1 ? '' : 's'} failed to analyze. ` + + `All ${totalHunks} chunk${totalHunks === 1 ? '' : 's'} failed to analyze` + + `${reasons.length > 0 ? ` (${reasons.join('; ')})` : ''}. ` + `This usually indicates an authentication problem. ${allHunksFailedGuidance(options.runtime)}`, { code: 'all_hunks_failed' }, ); diff --git a/packages/warden/src/sdk/errors.ts b/packages/warden/src/sdk/errors.ts index 6d4d19dfe..578f7212c 100644 --- a/packages/warden/src/sdk/errors.ts +++ b/packages/warden/src/sdk/errors.ts @@ -121,11 +121,21 @@ export class WardenAuthenticationError extends Error { } } +/** A runtime run that ended with `provider_error` instead of throwing. Thrown so the hunk retries. */ +export class ProviderResultError extends Error { + constructor(message: string) { + super(message); + this.name = 'ProviderResultError'; + } +} + /** * Check if an error is retryable. - * Retries on: rate limits (429), server errors (5xx), connection errors, timeouts. + * Retries on: rate limits (429), server errors (5xx), connection errors, timeouts, + * and runtime results that reported a provider error. */ export function isRetryableError(error: unknown): boolean { + if (error instanceof ProviderResultError) return true; if (error instanceof RateLimitError) return true; if (error instanceof InternalServerError) return true; if (error instanceof APIConnectionError) return true;