Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion dist/action/211.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions dist/action/663.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions packages/warden/src/sdk/analyze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
11 changes: 9 additions & 2 deletions packages/warden/src/sdk/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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';

Check warning on line 7 in packages/warden/src/sdk/analyze.ts

View check run for this annotation

@sentry/warden / warden: code-review

ProviderResultError with IPC substrings skips retry and becomes auth failure

Retryable `provider_error` results are thrown as `ProviderResultError`, but the catch path runs `isSubprocessError` before `isRetryableError`, so messages containing ECONNRESET/EPIPE/etc. abort as auth instead of retrying. Handle `ProviderResultError` before the subprocess/auth converters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProviderResultError with IPC substrings skips retry and becomes auth failure

Retryable provider_error results are thrown as ProviderResultError, but the catch path runs isSubprocessError before isRetryableError, so messages containing ECONNRESET/EPIPE/etc. abort as auth instead of retrying. Handle ProviderResultError before the subprocess/auth converters.

Evidence
  • On non-final attempts, provider_error becomes throw new ProviderResultError(failureMessage) where failureMessage embeds resultMessage.errors (analyze.ts ~504).
  • The hunk catch path checks isSubprocessError(error) before isRetryableError(error) (analyze.ts ~662–680).
  • isSubprocessError is true for any Error whose message includes ECONNRESET/EPIPE/ECONNREFUSED/ENOTCONN (errors.ts, covered by errors.test.ts).
  • That branch records auth_failed, opens the circuit, and throws WardenAuthenticationError, so the intended ProviderResultError retry never runs.
  • Before this change, the same provider_error result returned failureCode: 'provider_unavailable' without entering that catch path.

Identified by Warden · code-review · 4FJ-4QF

import { genAiProviderName } from './otel.js';
import type { CircuitBreakerReason } from './circuit-breaker.js';
import { DEFAULT_RETRY_CONFIG, calculateRetryDelay, sleep } from './retry.js';
Expand Down Expand Up @@ -498,6 +498,11 @@
? '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,
Expand Down Expand Up @@ -1278,8 +1283,10 @@
{ 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' },
);
Expand Down
12 changes: 11 additions & 1 deletion packages/warden/src/sdk/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading