Repository navigation
fix(agents): classify CDN/WAF edge blocks honestly, never as auth (ENG-16835) - #213
Merged
Merged
Conversation
…G-16835) A Cloudflare WAF block on boon-llm-gateway (403, <title>Blocked</title>) was classified as an "auth" failure: it surfaced misleading "re-authenticate your credentials" copy and cooled down/disabled an otherwise-healthy auth profile via model-fallback's persistent-auth-issue gate. The block is content-based and deterministic, not a credentials problem. Also found and fixed: the existing edge-block detector required a complete `</html>` closing tag, but the Anthropic Messages transport truncated error bodies to 400 chars, so the shipped ENG-14852 429 fix was silently inert on the real gateway path. - New isEdgeWafBlockPage detector matches truncation-tolerant block-page markers (title=Blocked, cf-ray, cdn-cgi/) without requiring a complete document. - New edge_blocked FailoverReason/ProviderRuntimeFailureKind, scoped narrowly (marker-based, 401/403-gated for the kind) so it doesn't reclassify legitimate generic Cloudflare 5xx relays or bare CF challenge pages. - edge_blocked is terminal within one attempt (failover-policy.ts) and a hard-abort in model-fallback's outer ladder: the WAF blocks the gateway edge, not any specific model, so walking remaining candidates only adds latency for a guaranteed repeat. - Excluded edge_blocked from both of the codebase's independent auth-profile-health gates, the cron run-log persistence allowlist, and mirrored it into the plugin-facing AgentRuntimeFailoverReason type. - Raised ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS 400 -> 2000 so a real block page's markers reliably survive truncation. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
All reported issues were addressed across 15 files
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
- Gate the edge_blocked terminal check on failoverFailure, matching
the format check, so a stale carried-over reason doesn't wrongly
surface an error instead of continuing normally.
- Record telemetry (observeFailedCandidate, nextCandidate: undefined)
before aborting the ladder on an edge block, so fleet metrics, the
Loki exhaustion alert, and fallback-step consumers still observe it.
- Add the missing shouldSuppressRawErrorConsoleSuffix("edge_blocked")
assertion.
- Drop Linear ticket references from comments/test titles added by
this PR (root AGENTS.md: no ENG-... refs in code/comments/commits).
Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Per repo comment-shape convention (1-3 short lines), drop the fleet/Loki/fallback-consumer narrative and keep only the deterministic edge-block invariant and why nextCandidate is left undefined. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
Reviewed the full diff against 845d7be. Approving.
Behavior is right and tightly scoped
edge_blockedis the correct new classification. CDN/WAF 401/403 block pages relayed byboon-llm-gatewaywere being misread asauthand cooling down otherwise-healthy profiles viamodel-fallback.ts'sisPersistentAuthIssue. The 401/403 branch inclassifyFailoverClassificationFromHttpStatusnow checksisEdgeWafBlockPagebefore falling toauth, andresolveAuthProfileFailureReasonreturns null foredge_blocked— so a WAF hiccup can never disable a real profile.- The scoping is careful. The new kind is gated to 401/403 in both
classifyFailoverClassificationFromHttpStatusandclassifyProviderRuntimeFailureKind, so a generic upstream 5xx or 429 that happens to share a marker still lands inupstream_html/ the existing timeout branch. The explicit no-regression tests for the 429 upstream_html case, bare Cloudflare challenge, complete-HTML auth 403, and JSON 401/403 all cover the failure modes I'd have worried about. - Terminal handling is thorough.
isTerminalNonRetryableFailurecleanly covers prompt-rotate, assistant-rotate, and retry-limit escalation. The outermodel-fallback.tsladder aborts immediately withobserveFailedCandidateandnextCandidate: undefined, so telemetry / fleet metrics / fallback-step consumers still see the failure — no silent skip.
Second fix (transport truncation)
- The
ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS400 → 2000 raise is the real reason the previously-shipped ENG-14852 429 fix was silently inert on live Cloudflare bodies.maxBytes(8 KB) still bounds what's read off the wire, so no new backpressure/latency risk — this just raises how much of the already-read body reaches the classifier. Good.
Quality bar
- All three commits verified/signed. CI fully green (
check-lint,check-prod-types, all boundary checks, CodeQL, cubic critical-quality and dispatch). - Cubic re-reviewed after the fixup commits and confirmed all reported issues addressed. Comments trimmed to the invariant per repo convention on the third commit. No
ENG-refs in added code/comments. - 640 tests green across every touched file, and the added coverage exercises both the truncated 403 →
edge_blockedand truncated 429 →timeoutpaths plus the four no-regression paths.
Minor observations (non-blocking)
- Consumer copy (
CONSUMER_ERROR_COPY.edge_blocked) and dev-facing copy (formatAssistantErrorText'sedge_blockedbranch) diverge slightly. Intentional and fine — one is short user-facing, the other is the operator hint — just flagging. - The
FleetEdgeHTMLBlockDetectedLoki alert match and the bogus200 + HTMLWAF-relay path called out in the PR body are the right follow-ups to file separately, not part of this PR.
Ship it.
holywend
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
A Cloudflare WAF/edge block in front of
boon-llm-gateway(e.g. a403with<title>Blocked</title>) was misclassified as an auth failure. Thatsurfaced misleading "re-authenticate your credentials" copy to the customer
and, via
model-fallback.ts's persistent-auth-issue gate, cooled down/disabledan otherwise-healthy auth profile — turning one blocked request into a
sustained "Boon Agent down" incident (ENG-16835).
Digging into the classifier also surfaced a second, more severe defect: the
existing edge-block detector (
isEdgeBlockErrorBody) required a complete</html>closing tag, but the Anthropic Messages transport truncates theerror body to 400 chars before it reaches the classifier. A real Cloudflare
block page is several KB, so
</html>never survives truncation — meaningthe already-shipped ENG-14852 fix (edge 429 →
timeout, notrate_limit)was silently inert on the real gateway path. Its own acceptance notes concede
the reclassification was never exercised live; this is why.
Why This Change Was Made
ENG-16835 itself has no logs/repro (blank ticket), but Arief's same-day RCA in
#project-rohanroot-caused an identical gandalf outage to exactly thisCloudflare-403 signature: "classify a
<title>Blocked</title>/cloudflare-403as a named non-retryable failure w/ honest copy, not opaque 'LLM request
failed'" — that ask was never implemented. The rest of that incident cluster
is already closed (ENG-16834 done, ENG-16815 merged as PR #83, ENG-14852 done),
leaving this as the one unfixed path.
User Impact
longer disables/cools down a healthy auth profile.
request) instead of an opaque
LLM request failed.walking every remaining model candidate behind the same blocked gateway —
the block is content-based and deterministic, so trying the next model was
pure wasted latency, never a real recovery path.
on real (truncated) Cloudflare pages, not just complete-document test
fixtures.
Evidence
#project-rohan, 2026-07-27): raw request/response pairshowing Cloudflare returning
403 <title>Blocked</title>forPOST /v1/messages, headersserver: cloudflare,cf-ray, nox-render-routing— blocked at the edge before the gateway app ran.src/agents/embedded-agent-helpers/errors.ts(pre-change): 401/403 branchin
classifyFailoverClassificationFromHttpStatusnever checkedisEdgeBlockErrorBodybefore falling to"auth";model-fallback.ts:1238isPersistentAuthIssuekeys off exactly that reason.src/agents/anthropic-transport-stream.ts(pre-change):ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS = 400vs.HTML_CLOSE_RE = /<\/html>/irequired byisHtmlErrorResponse/isCloudflareOrHtmlErrorPage— provably unreachable on a multi-KB real block page.
truncated-429 (revived ENG-14852) cases, plus explicit no-regression
assertions for generic Cloudflare 5xx relays, bare CF challenge pages, plain
JSON 401/403, and the two independent auth-profile-health gates.
tsgoclean ontsconfig.core.jsonandtsconfig.extensions.json(caught and fixed 2 realcompile errors from parallel closed unions —
AuthProfileFailureReason,AgentRuntimeFailoverReason);oxfmt --checkclean.
check:changed/broad-lane Crabbox pass could not be runin the authoring environment (no Azure CLI configured for the local
crabboxprovider) — still owed before landing per this repo's$autoreview/pre-land policy.Follow-ups filed as notes, not blocking this PR: confirm the
FleetEdgeHTMLBlockDetectedLoki alert (gandalf-manager#478) still matchesnow that the 401/403 kind is
edge_blockedrather thanauth_html; a WAFblock relayed as a bogus
200 + HTMLis a separate, still-open gap (nocontent-type check on the Anthropic transport); ENG-16815 is merged (PR #83)
but still shows "In Progress" in Linear.
🤖 Generated with Claude Code
Summary by cubic
Fixes ENG-16835 by classifying CDN/WAF 401/403 block pages as
edge_blockedinstead ofauth. This prevents misleading re-authentication errors and keeps healthy auth profiles from being cooled down or disabled, while stopping the fallback ladder from retrying a deterministic edge block.Behavior changes
<title>Blocked</title>,cf-ray, andcdn-cgi/.edge_blockedto recognized 401/403 pages so generic 5xx responses, challenge pages, and JSON auth errors keep their existing classifications.failoverFailureis set.edge_blockedfrom auth-profile health checks, preserves it in cron run logs, and suppresses its raw error suffix.Written for commit 845d7be. Summary will update on new commits.