Repository navigation
fix: transient upstream 5xx (gateway-relayed Bedrock 503) now fails over instead of blocking the customer - #83
Conversation
…onses (ENG-16815)
…ification (ENG-16815)
…tests (ENG-16815) Adds guard tests proving classifyProviderRuntimeFailureKind returns "timeout" for a Bedrock 503 when status is supplied, and "unclassified" without it. Threads AssistantMessage.errorStatus into buildApiErrorObservationFields (via embedded-agent-subscribe lifecycle handler) so the logged providerRuntimeFailureKind reflects the real HTTP status, not just text-parsed status. The failover DECISION (Task 4) already uses errorStatus; this completes the observation/telemetry path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…for type parity (ENG-16815) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
There was a problem hiding this comment.
cubic analysis
No issues found across 11 files
Linked issue analysis
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Add optional errorStatus?: number to AssistantMessage type so transports can carry numeric HTTP status. | The AssistantMessage type was extended with errorStatus?: number in packages/llm-core/src/types.ts. |
| ✅ | Capture a numeric status from thrown transport errors (extractTransportErrorDetails) and expose it as errorStatus. | A readNumericErrorStatus helper was added and extractTransportErrorDetails now returns errorStatus when found. |
| ✅ | Preserve response.status on the error thrown by the Anthropic Messages client for non-OK responses. | The Anthropic client now throws Object.assign(new Error(...), { status: response.status }), preserving the numeric status on the thrown error. |
| ✅ | Make buildAssistantFailoverSignal prefer AssistantMessage.errorStatus over text-derived leading status so the classifier uses the real status. | buildAssistantFailoverSignal now uses msg.errorStatus when present before falling back to extractLeadingHttpStatus. |
| ✅ | Wire the real status into telemetry/observation so providerRuntimeFailureKind classification uses the explicit status. | buildApiErrorObservationFields signature now accepts status and uses it for classification; lifecycle handler passes lastAssistant.errorStatus into the observation builder. |
| ✅ | Add tests that verify a gateway 503 yields errorStatus and that classification flips when status is present (regression guards + transport unit tests). | Multiple tests were added that assert errorStatus is captured (anthropic-transport-stream.test.ts, transport-stream-shared.test.ts) and that the classifier returns timeout when status is present but unclassified without it (embedded-agent-error-observation.test.ts, embedded-agent-helpers.isbillingerrormessage.test.ts). |
| ✅ | Propagate errorStatus through other transport output shapes (OpenAI) so status is available across transports. | MutableAssistantOutput in openai transport was extended to include errorStatus so that non-Anthropic transports can carry the numeric status similarly. |
There was a problem hiding this comment.
Approved (ENG-16815).
Traced the full chain — clean, minimal, correctly-scoped fix. Root cause is right: gateway-relayed Bedrock 503s arrive as a JSON body with no leading "NNN " status prefix, so extractLeadingHttpStatus can't recover the status and failover never fires — the customer gets blocked instead of failing over. The fix captures the numeric status at the transport (Object.assign(new Error, {status})), threads it via AssistantMessage.errorStatus, and buildAssistantFailoverSignal now prefers it over text-parsing.
No regression risk:
- errorStatus is optional; failover signal uses it only when finite, else falls back to the exact prior extractLeadingHttpStatus path.
- buildApiErrorObservationFields uses opts?.status ?? parsed?.httpCode — nullish coalescing preserves prior behavior when status is absent.
- The explicit regression-guard test proves a bare 503 body with no errorStatus still returns null/unclassified, identical to old behavior.
Tests: change-specific coverage at every layer (transport capture + omit-when-absent, anthropic 503 threading, classifier with/without status, observation telemetry). Type parity on both transports. No secrets in history, no migrations, no breaking contract. CI green (the one 'review' gate is the human-review requirement this approval satisfies).
… ladder (ENG-16815) Composes the real failover classifier with the real decision policy (no mocks) to prove the end-to-end handoff the unit tests leave open: an assistant error carrying errorStatus:503 -> classifyAssistantFailoverReason -> "timeout" -> resolveRunFailoverDecision -> fallback_model. Includes a pre-fix regression case (same bare Bedrock body without errorStatus) that reproduces the incident: unclassified -> continue_normal (no failover), which is what blocked the customer before the status was threaded through. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Version-bump release carrying #83 (ENG-16815): a transient upstream 5xx relayed through boon-llm-gateway (e.g. a Bedrock 503 api_error) now fails over to the next backend in the cross-backend ladder instead of hard-failing the customer's turn with 'LLM request failed'. The numeric HTTP status is now threaded from transport through to the failover classifier, so the existing 503->timeout status-driven failover path fires. Bumps the gateway + @openclaw/slack + @openclaw/msteams to 2026.6.11-boon.11 in lockstep (7 files: 3 package.json, 3 npm-shrinkwrap.json, CHANGELOG.md). Tagging v2026.6.11-boon.11 after merge triggers boon-release.yml to publish the 6 assets.
…y-origin 5xx (ENG-16922) (#89) * feat(sentry-monitor): classify gateway-relayed upstream 5xx vs gateway-origin 5xx (ENG-16922) The Rohan "Boon Agent 5xx error(s) detected" alert (openclaw-fleet Sentry project) pages with blanket "5xx = our infra. Investigate." copy — but the fleet runs single-hop, where boon-llm-gateway relays an upstream Bedrock 5xx verbatim and never self-captures. The page comes from this plugin's model_call_ended hook, which had no HTTP status to tell a relayed provider outage from a gateway-origin fault. Thread the numeric HTTP status (available on the thrown error post-#83) and a status-derived source class through the model_call_ended hook, and tag the Sentry capture with it so the alert can split/rate-gate the two: - classify5xxSource() in diagnostic-error-metadata.ts: status-driven (no message regex), 500/503/529 -> upstream_provider_5xx, 502/other-5xx -> gateway_origin_5xx, with a recognized api_error/overloaded provider error.type as an ambiguous-status tie-break. - Add httpStatus + errorClass to PluginHookModelCallEndedEvent and the model.call.error diagnostic event; populate both in modelCallErrorFields. - Tag error_class + extra.http_status in buildModelCallEndedCapture; lead the Sentry title with them so the two classes fingerprint into separate issues. - Tests for classify5xxSource + the capture; docs/gateway/sentry-monitor.md tag table + note. The alert threshold/rate-gate/copy are Sentry-UI-configured and land after this ships fleet-wide (see gandalf-manager spec docs/specs/2026-07-29-eng16922-5xx-source-classification.md). tsgo:prod clean; oxlint clean; 57 targeted tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(sentry-monitor): list overloaded_error in the error_class tie-break types (ENG-16922) Address cubic review P3: the classify5xxSource tie-break matches api_error/overloaded/overloaded_error (UPSTREAM_PROVIDER_ERROR_TYPES), but the doc listed only api_error/overloaded. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Related: ENG-16815
What Problem This Solves
Fixes an issue where a Boon Agent user would get a hard
LLM request failederror (withfailoverReason: null) — instead of transparent failover to the next backend — when a transient upstream 5xx (e.g. a Bedrock503 api_error, "Bedrock is unable to process your request.") was relayed throughboon-llm-gateway, even though a full cross-backend fallback ladder was configured.This is fleet-wide: every paid boon-agent runs the single-hop cross-backend chain, so any transient Bedrock 5xx blocked the in-flight customer turn instead of failing over.
Why This Change Was Made
The failover classifier already maps HTTP
503 → timeout(failover-eligible). The real defect was that the HTTP status was dropped before it ever reached the classifier: the custom Anthropic Messages fetch client threw a bareError(body)that discardedresponse.status, andAssistantMessagehad no field to carry a status — so the classifier fell back to matching the free-text error body, which for Bedrock's phrasing yieldedunclassifiedand no failover.The fix threads the numeric HTTP status from transport through to the classifier, so the existing status-driven path fires and the message text is no longer load-bearing:
errorStatus?: numbertoAssistantMessage.extractTransportErrorDetails.response.statuson the error thrown by the Anthropic Messages client on a non-OK response.buildAssistantFailoverSignalprefers the realerrorStatusover the text-derived status (the behavioral fix).providerRuntimeFailureKind) that loggedunclassifiedin the incident.Deliberately not done: broadening the message-text regex (
API_ERROR_TRANSIENT_SIGNALS_RE). That would reintroduce the fragile string-matching this change removes and would defeat the regression guards that prove the HTTP status — not the wording — is what drives classification. OpenAI-shaped transports already carry status via the SDK'sAPIError.status, so they route through the same extractor for free.User Impact
A transient upstream 5xx (Bedrock 503 and other gateway-relayed 5xx) now walks the configured model-fallback ladder to the next backend instead of surfacing
LLM request failedto the customer. The in-flight turn recovers transparently. Failover telemetry also reports the correcttimeoutkind rather thanunclassified.Evidence
Verified end-to-end (see
docs/agent-guidesroot-cause write-up on ENG-16815):anthropic-transport-stream.test.ts): a real 503Responsenow yieldserrorStatus: 503on the terminal assistant message.embedded-agent-helpers.isbillingerrormessage.test.ts): the exact Bedrock body witherrorStatus: 503classifies astimeout; the identical body without a status still returnsnull— proving the status (not the text) flips classification.response.status→ thrown error.status→extractTransportErrorDetails→AssistantMessage.errorStatus→buildAssistantFailoverSignal.status→ existing503 → timeoutclassifier path.pnpm tsgopasses (EXIT 0); oxlint clean (0/0) on touched files.🤖 Generated with Claude Code
Summary by cubic
Fixes failover for gateway‑relayed upstream 5xx (e.g., Bedrock 503) by threading the HTTP status to the classifier so requests move to the next backend instead of failing with “LLM request failed.” Addresses Linear ENG-16815 and corrects telemetry to report the right failure kind.
errorStatus?: numbertoAssistantMessage; capture numeric status from thrown transport errors and preserveresponse.statusin the Anthropic client.errorStatusover message‑text parsing, activating the existing503 → timeoutrule and walking the fallback ladder.errorStatusinto error observation soproviderRuntimeFailureKindreportstimeout; added tests, including an integration test that composes the real classifier and decision policy to prove a Bedrock 503 walks the fallback ladder, plus regression guards.Written for commit aefcb5b. Summary will update on new commits.