Skip to content

fix(agents): classify CDN/WAF edge blocks honestly, never as auth (ENG-16835) - #213

Merged
convyusboy merged 3 commits into
boonfrom
ridho/eng-16835-boon-agent-down
Sep 10, 2026
Merged

convyusboy merged 3 commits into
boonfrom
ridho/eng-16835-boon-agent-down

Conversation

@convyusboy

@convyusboy convyusboy commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

A Cloudflare WAF/edge block in front of boon-llm-gateway (e.g. a 403 with
<title>Blocked</title>) was misclassified as an auth failure. That
surfaced misleading "re-authenticate your credentials" copy to the customer
and, via model-fallback.ts's persistent-auth-issue gate, cooled down/disabled
an 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 the
error body to 400 chars before it reaches the classifier. A real Cloudflare
block page is several KB, so </html> never survives truncation — meaning
the already-shipped ENG-14852 fix (edge 429 → timeout, not rate_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-rohan root-caused an identical gandalf outage to exactly this
Cloudflare-403 signature: "classify a <title>Blocked</title>/cloudflare-403
as 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

  • A CDN/WAF edge block no longer tells the customer to re-authenticate, and no
    longer disables/cools down a healthy auth profile.
  • The failure is now honestly named (a gateway security filter blocked the
    request) instead of an opaque LLM request failed.
  • The fallback ladder aborts immediately on a detected edge block instead of
    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.
  • The truncated-body detection fix also revives the shipped ENG-14852 429 fix
    on real (truncated) Cloudflare pages, not just complete-document test
    fixtures.

Evidence

  • Arief's RCA (Slack #project-rohan, 2026-07-27): raw request/response pair
    showing Cloudflare returning 403 <title>Blocked</title> for
    POST /v1/messages, headers server: cloudflare, cf-ray, no
    x-render-routing — blocked at the edge before the gateway app ran.
  • src/agents/embedded-agent-helpers/errors.ts (pre-change): 401/403 branch
    in classifyFailoverClassificationFromHttpStatus never checked
    isEdgeBlockErrorBody before falling to "auth"; model-fallback.ts:1238
    isPersistentAuthIssue keys off exactly that reason.
  • src/agents/anthropic-transport-stream.ts (pre-change):
    ANTHROPIC_MESSAGES_ERROR_BODY_MAX_CHARS = 400 vs. HTML_CLOSE_RE = /<\/html>/i required by isHtmlErrorResponse/isCloudflareOrHtmlErrorPage
    — provably unreachable on a multi-KB real block page.
  • Test coverage added for both the truncated-403 (the production shape) and
    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.
  • Verification: 640 tests passing across every touched file; tsgo clean on
    tsconfig.core.json and tsconfig.extensions.json (caught and fixed 2 real
    compile errors from parallel closed unions —
    AuthProfileFailureReason, AgentRuntimeFailoverReason); oxfmt --check
    clean.
  • Known gap: a full check:changed/broad-lane Crabbox pass could not be run
    in the authoring environment (no Azure CLI configured for the local
    crabbox provider) — still owed before landing per this repo's
    $autoreview/pre-land policy.

Follow-ups filed as notes, not blocking this PR: confirm the
FleetEdgeHTMLBlockDetected Loki alert (gandalf-manager#478) still matches
now that the 401/403 kind is edge_blocked rather than auth_html; a WAF
block relayed as a bogus 200 + HTML is a separate, still-open gap (no
content-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_blocked instead of auth. 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

  • Detects truncated block pages using markers such as <title>Blocked</title>, cf-ray, and cdn-cgi/.
  • Raises Anthropic error-body classification from 400 to 2,000 characters, restoring edge 429 detection on real truncated responses.
  • Limits edge_blocked to recognized 401/403 pages so generic 5xx responses, challenge pages, and JSON auth errors keep their existing classifications.
  • Records failed-candidate telemetry before aborting, and only treats the reason as terminal when failoverFailure is set.
  • Excludes edge_blocked from 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.

Review in cubic

…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]>
@convyusboy
convyusboy requested a review from a team September 9, 2026 13:25
@claude

claude Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

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

All reported issues were addressed across 15 files

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread src/agents/model-fallback.ts Resolved
Comment thread src/agents/model-fallback.test.ts Resolved
- 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]>

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

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

Comment thread src/agents/model-fallback.ts Resolved
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]>

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

Reviewed the full diff against 845d7be. Approving.

Behavior is right and tightly scoped

  • edge_blocked is the correct new classification. CDN/WAF 401/403 block pages relayed by boon-llm-gateway were being misread as auth and cooling down otherwise-healthy profiles via model-fallback.ts's isPersistentAuthIssue. The 401/403 branch in classifyFailoverClassificationFromHttpStatus now checks isEdgeWafBlockPage before falling to auth, and resolveAuthProfileFailureReason returns null for edge_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 classifyFailoverClassificationFromHttpStatus and classifyProviderRuntimeFailureKind, so a generic upstream 5xx or 429 that happens to share a marker still lands in upstream_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. isTerminalNonRetryableFailure cleanly covers prompt-rotate, assistant-rotate, and retry-limit escalation. The outer model-fallback.ts ladder aborts immediately with observeFailedCandidate and nextCandidate: 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_CHARS 400 → 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_blocked and truncated 429 → timeout paths plus the four no-regression paths.

Minor observations (non-blocking)

  • Consumer copy (CONSUMER_ERROR_COPY.edge_blocked) and dev-facing copy (formatAssistantErrorText's edge_blocked branch) diverge slightly. Intentional and fine — one is short user-facing, the other is the operator hint — just flagging.
  • The FleetEdgeHTMLBlockDetected Loki alert match and the bogus 200 + HTML WAF-relay path called out in the PR body are the right follow-ups to file separately, not part of this PR.

Ship it.

@convyusboy
convyusboy merged commit b5c1285 into boon Sep 10, 2026
146 of 149 checks passed
@convyusboy
convyusboy deleted the ridho/eng-16835-boon-agent-down branch September 10, 2026 03:47
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.

2 participants