Skip to content

fix: transient upstream 5xx (gateway-relayed Bedrock 503) now fails over instead of blocking the customer - #83

Merged
Willi8910 merged 7 commits into
boonfrom
williamlie/eng-16815-preserve-http-status-for-failover
Jul 28, 2026
Merged

Willi8910 merged 7 commits into
boonfrom
williamlie/eng-16815-preserve-http-status-for-failover

Conversation

@Willi8910

@Willi8910 Willi8910 commented Jul 28, 2026 •

Copy link
Copy Markdown

Related: ENG-16815

What Problem This Solves

Fixes an issue where a Boon Agent user would get a hard LLM request failed error (with failoverReason: null) — instead of transparent failover to the next backend — when a transient upstream 5xx (e.g. a Bedrock 503 api_error, "Bedrock is unable to process your request.") was relayed through boon-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 bare Error(body) that discarded response.status, and AssistantMessage had no field to carry a status — so the classifier fell back to matching the free-text error body, which for Bedrock's phrasing yielded unclassified and 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:

  1. Add optional errorStatus?: number to AssistantMessage.
  2. Capture a numeric status off the thrown transport error in extractTransportErrorDetails.
  3. Preserve response.status on the error thrown by the Anthropic Messages client on a non-OK response.
  4. buildAssistantFailoverSignal prefers the real errorStatus over the text-derived status (the behavioral fix).
  5. Wire the real status into the observation/telemetry field (providerRuntimeFailureKind) that logged unclassified in 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's APIError.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 failed to the customer. The in-flight turn recovers transparently. Failover telemetry also reports the correct timeout kind rather than unclassified.

Evidence

Verified end-to-end (see docs/agent-guides root-cause write-up on ENG-16815):

  • New end-to-end test (anthropic-transport-stream.test.ts): a real 503 Response now yields errorStatus: 503 on the terminal assistant message.
  • Load-bearing regression guards (embedded-agent-helpers.isbillingerrormessage.test.ts): the exact Bedrock body with errorStatus: 503 classifies as timeout; the identical body without a status still returns null — proving the status (not the text) flips classification.
  • Full status chain confirmed by review: response.status → thrown error .status → extractTransportErrorDetails → AssistantMessage.errorStatus → buildAssistantFailoverSignal.status → existing 503 → timeout classifier path.
  • Local verification: 537 tests green across all touched suites; pnpm tsgo passes (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.

  • Bug Fixes
    • Added errorStatus?: number to AssistantMessage; capture numeric status from thrown transport errors and preserve response.status in the Anthropic client.
    • Failover now prefers errorStatus over message‑text parsing, activating the existing 503 → timeout rule and walking the fallback ladder.
    • Wired errorStatus into error observation so providerRuntimeFailureKind reports timeout; 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.

Review in cubic

Willi8910 and others added 6 commits July 28, 2026 11:06
…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]>
@boon-atlantis-production

Copy link
Copy Markdown
Error: This repo is not allowlisted for Atlantis.

@cubic-dev-ai cubic-dev-ai 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.

cubic analysis

No issues found across 11 files

Linked issue analysis

Linked issue: ENG-16815: OpenClaw fallback does not fire on gateway-relayed upstream 5xx (Bedrock 503 api_error) — customer blocked instead of failover

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.

Re-trigger cubic

@gandalfboon gandalfboon 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.

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]>
@Willi8910
Willi8910 merged commit 744718f into boon Jul 28, 2026
144 checks passed
@Willi8910
Willi8910 deleted the williamlie/eng-16815-preserve-http-status-for-failover branch July 28, 2026 10:24
Willi8910 added a commit that referenced this pull request Jul 28, 2026
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.
convyusboy added a commit that referenced this pull request Jul 30, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant