Skip to content

fix(agent): normalize provider failures#907

Open
sentry-junior[bot] wants to merge 10 commits into
mainfrom
fix/uniform-provider-errors
Open

fix(agent): normalize provider failures#907
sentry-junior[bot] wants to merge 10 commits into
mainfrom
fix/uniform-provider-errors

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

summary

  • add a structured ProviderError contract for provider/auth/capacity/rate-limit/network failures
  • preserve status, provider/model, retry/fallback eligibility, retry hints, bounded upstream diagnostics, and safe user copy
  • replace Error.name retry signaling with typed fields
  • carry normalized failures into turn diagnostics and Sentry attributes
  • show actionable terminal provider messages while retaining the event id

context

This is the first vertical slice from the provider-error investigation prompted by recurring xAI 503 capacity failures (JUNIOR-53). Gateway fallback configuration remains separate work.

tests

  • added focused coverage for xAI 503 normalization, retry hints, and safe user-facing capacity responses
  • git diff --check passes
  • local tests/typecheck are currently unverified: the checkout had no dependencies, and pnpm install --frozen-lockfile was cancelled by the runtime before completion

Requested by immutable dcramer via Junior.

--

View Junior Session in Sentry

Co-Authored-By: OpenAI GPT-5.4 <noreply@openai.com>
Co-Authored-By: immutable dcramer <david@sentry.io>
@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview Jul 15, 2026 6:38pm

Request Review

Co-Authored-By: OpenAI GPT-5.4 <noreply@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: immutable dcramer <david@sentry.io>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: immutable dcramer <david@sentry.io>
Co-Authored-By: Nick <nicholas.deschenes@sentry.io>
Co-Authored-By: OpenAI Codex <codex@openai.com>
@dcramer
dcramer marked this pull request as ready for review July 15, 2026 17:35
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Jul 15, 2026
Comment thread packages/junior/src/chat/services/provider-error.ts
Comment thread packages/junior/src/chat/services/provider-error.ts
Comment thread packages/junior/src/chat/services/provider-error.ts Outdated
Co-Authored-By: immutable dcramer <david@sentry.io>
Co-Authored-By: Nick <nicholas.deschenes@sentry.io>
Co-Authored-By: immutable dcramer <david@sentry.io>
Co-Authored-By: Nick <nicholas.deschenes@sentry.io>
Co-Authored-By: OpenAI GPT-5.4 <noreply@openai.com>
Co-Authored-By: immutable dcramer <david@sentry.io>
Co-Authored-By: Nick <nicholas.deschenes@sentry.io>
Comment thread packages/junior/src/chat/services/provider-error.ts
Co-Authored-By: OpenAI GPT-5.4 <noreply@openai.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 22698f0. Configure here.

message: string,
): ProviderErrorKind {
if (/content.?policy|safety|moderation/i.test(message))
return "content_policy";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overbroad safety error classification

Medium Severity

classifyProviderError treats any message containing bare safety as content_policy, which is non-retryable. Transient provider failures whose text happens to include that word are therefore dropped from retry/fallback even when status or other signals indicate a temporary outage.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 22698f0. Configure here.

messages: agent!.state.messages,
retryableFailure:
lastAssistant !== undefined &&
isRetryableAssistantError(lastAssistant),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thrown failures skip normalization

Medium Severity

The agent catch path stores the raw thrown value as providerError, while finalizeFailedTurnReply only emits actionable copy and provider attributes when that value is a ProviderError. buildTurnResult normalizes via createProviderError, so transport throws that never become assistant stopReason: "error" messages still get the generic terminal reply and empty provider telemetry.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 22698f0. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants