From 3643e1ce5e09e7bc7b7c8180caea8fdfb67ee03b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:33:43 +0000 Subject: [PATCH 1/6] fix(combos): make moderation-refusal prose matching linear (CodeQL js/redos) MODERATION_REFUSAL_PROSE wrapped a verdict alternation and a tail alternation in one ^(?:v)(?:t)*$ regex. Its category list consumed separator words ("and retry") that a sibling tail option also accepts, and its ",? and |, " separators overlapped, so a crafted upstream error body (e.g. "refused category: a" + ", and retry category: a" repeated) forced exponential backtracking before rejection (CodeQL alerts #4342, #4343). Split it into two anchored regexes consumed by an explicit scan: one verdict, then tail phrases eaten greedily in order. The Azure wording leads the verdict alternation because "the response was filtered" is a strict prefix of it, and category separators are disjoint by first byte, so every position has exactly one parse. Behavior verified identical on a 29-case corpus; the attack string runs in ~0ms instead of exploding exponentially. Verified: bun test tests/routing/router-combo-failover-classification.test.ts tests/routing/combo-failure-transport-parity.test.ts (228 pass), bun run typecheck. Co-Authored-By: Epinephrine --- src/combos/failover.ts | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/combos/failover.ts b/src/combos/failover.ts index 12e06ef9abd..fb1e1edbd8a 100644 --- a/src/combos/failover.ts +++ b/src/combos/failover.ts @@ -1061,23 +1061,38 @@ const RESPONSE_REQUEST_ECHO_KEYS = new Set([ * Any other wording (an account, model, parameter or billing problem, in any phrasing) does not * match, so the body keeps dev's decision; only known shapes are admitted. */ -const MODERATION_REFUSAL_PROSE = new RegExp("^(?:" - + "(?:content )?(?:refused|flagged|blocked|rejected|filtered)(?: by (?:the )?(?:moderation|content filter))?\\.?" +// Verdict and tail stay apart: a single `^(?:verdict)(?:tail)*$` backtracks exponentially +// because a category list swallows words ("and retry") that a later tail phrase also accepts. +// The Azure wording leads because "the response was filtered" is a strict prefix of it; the +// anchored scan commits to the first verdict alternative that matches, so the longest must run first. +const MODERATION_REFUSAL_VERDICT = new RegExp("^(?:" + + "the response was filtered due to the prompt triggering azure openai'?s content management policy\\.?" + + "|(?:content )?(?:refused|flagged|blocked|rejected|filtered)(?: by (?:the )?(?:moderation|content filter))?\\.?" + "|(?:(?:the|your) )?(?:input|request|prompt|content|message|response|output)(?: (?:was|has been|is))?" + " (?:refused|flagged|blocked|rejected|filtered)(?: by (?:the )?(?:moderation|content filter)(?: system)?)?\\.?" - + "|the response was filtered due to the prompt triggering azure openai'?s content management policy\\.?" + "|(?:your )?(?:input|request|prompt|content) violated (?:the )?content (?:safety|management|filtering) polic(?:y|ies)\\.?" - + ")(?:" - + " categor(?:y|ies): [a-z][a-z/_-]*(?:(?:,? and |, )[a-z][a-z/_-]*)*\\.?" + + ")", "i"); +// Category separators are disjoint by first byte so each anchored match has exactly one parse. +const MODERATION_REFUSAL_TAIL = new RegExp("^(?:" + + " categor(?:y|ies): [a-z][a-z/_-]*(?:(?:, and | and |, )[a-z][a-z/_-]*)*\\.?" + "| please (?:modify|revise|rephrase|change|adjust|edit) (?:your|the) (?:prompt|input|request|message)(?: and (?:retry|try again))?\\.?" + "| (?:please )?(?:retry|try again)(?: later)?\\.?" + "| to learn more about our content filtering policies please read our documentation: https://[^ ]+" - + ")*$", "i"); + + ")", "i"); /** Whether a prose string is a known moderation refusal copy and nothing else (bounded, linear). */ function isModerationRefusalProse(text: string): boolean { if (text.length > 2_000) return false; - return MODERATION_REFUSAL_PROSE.test(text.replace(/\s+/g, " ").trim()); + let rest = text.replace(/\s+/g, " ").trim(); + const verdict = MODERATION_REFUSAL_VERDICT.exec(rest); + if (!verdict) return false; + rest = rest.slice(verdict[0].length); + while (rest.length > 0) { + const piece = MODERATION_REFUSAL_TAIL.exec(rest); + if (!piece) return false; + rest = rest.slice(piece[0].length); + } + return true; } /** From 743d8a01eb94031f6af91fa5ae069cb99be4fc28 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:34:48 +0000 Subject: [PATCH 2/6] test(combos): pin moderation-refusal matcher language and linear bound Direct coverage of isModerationRefusalProse (exported for tests): every accepted verdict and tail spelling, non-refusal bodies that must keep dev's decision, and both rejecting and accepting 80x-repeat category lists completing under a 1s bound (the previous nested-regex shape grew exponentially on the rejecting one). Registers the file in scripts/test-layout/layout.json and tests/fixtures/test-layout-expected.json under routing. Verified: bun test tests/routing/combo-failover-moderation-prose.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts (55 pass), bun run typecheck, bun run privacy:scan. Co-Authored-By: Epinephrine --- scripts/test-layout/layout.json | 2 +- src/combos/failover.ts | 2 +- tests/fixtures/test-layout-expected.json | 2 +- .../combo-failover-moderation-prose.test.ts | 61 +++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 tests/routing/combo-failover-moderation-prose.test.ts diff --git a/scripts/test-layout/layout.json b/scripts/test-layout/layout.json index 9b34ef31b59..13f92b1b7b6 100644 --- a/scripts/test-layout/layout.json +++ b/scripts/test-layout/layout.json @@ -1622,7 +1622,7 @@ "route-explainability.test.ts": "cli", "routed-agent-messages.test.ts": "adapters", "router-blocked-cross-provider.test.ts": "routing", - "router-combo-failover-classification.test.ts": "routing", "combo-failure-transport-parity.test.ts": "routing", + "router-combo-failover-classification.test.ts": "routing", "combo-failover-moderation-prose.test.ts": "routing", "combo-failure-transport-parity.test.ts": "routing", "router-discarded-baseurl-warning.test.ts": "routing", "router-template-baseurl.test.ts": "routing", "router.test.ts": "routing", diff --git a/src/combos/failover.ts b/src/combos/failover.ts index fb1e1edbd8a..55c971a0e9a 100644 --- a/src/combos/failover.ts +++ b/src/combos/failover.ts @@ -1081,7 +1081,7 @@ const MODERATION_REFUSAL_TAIL = new RegExp("^(?:" + ")", "i"); /** Whether a prose string is a known moderation refusal copy and nothing else (bounded, linear). */ -function isModerationRefusalProse(text: string): boolean { +export function isModerationRefusalProse(text: string): boolean { if (text.length > 2_000) return false; let rest = text.replace(/\s+/g, " ").trim(); const verdict = MODERATION_REFUSAL_VERDICT.exec(rest); diff --git a/tests/fixtures/test-layout-expected.json b/tests/fixtures/test-layout-expected.json index 289167d3f2b..f2cf40cf0ab 100644 --- a/tests/fixtures/test-layout-expected.json +++ b/tests/fixtures/test-layout-expected.json @@ -1368,7 +1368,7 @@ "restore-completes-shared-teardown.test.ts": "cli", "retry-after-429.test.ts": "server", "route-decision-trace.test.ts": "server", "route-explainability.test.ts": "cli", "routed-agent-messages.test.ts": "adapters", "router-blocked-cross-provider.test.ts": "routing", - "router-combo-failover-classification.test.ts": "routing", "combo-failure-transport-parity.test.ts": "routing", "router-discarded-baseurl-warning.test.ts": "routing", + "router-combo-failover-classification.test.ts": "routing", "combo-failover-moderation-prose.test.ts": "routing", "combo-failure-transport-parity.test.ts": "routing", "router-discarded-baseurl-warning.test.ts": "routing", "router-template-baseurl.test.ts": "routing", "router.test.ts": "routing", "routing-analytics.test.ts": "routing", "routing-capability-catalog.test.ts": "routing", "routing-capability-model-matching.test.ts": "routing", "routing-compatibility-auth-identity.test.ts": "routing", diff --git a/tests/routing/combo-failover-moderation-prose.test.ts b/tests/routing/combo-failover-moderation-prose.test.ts new file mode 100644 index 00000000000..c90f599e000 --- /dev/null +++ b/tests/routing/combo-failover-moderation-prose.test.ts @@ -0,0 +1,61 @@ +import { describe, expect, test } from "bun:test"; +import { isModerationRefusalProse } from "../../src/combos/failover"; + +/** + * Direct coverage of the moderation-refusal prose matcher. The pipeline-level + * classification lives in router-combo-failover-classification.test.ts; this + * file pins the matcher's accepted language and its linear bound. + */ +describe("moderation refusal prose matcher", () => { + const accepted = [ + "refused", + "Content refused.", + "The input was refused by moderation.", + "Prompt was blocked by moderation.", + "Input was flagged by moderation.", + "Your request was rejected by the content filter system.", + "the response was filtered due to the prompt triggering azure openai's content management policy.", + "the response was filtered due to the prompt triggering azure openais content management policy.", + "Your input violated the content safety policies.", + "input violated content filtering policy", + "refused category: a, b and c. please change your prompt and retry.", + "refused categories: a, and b, c. retry later.", + "refused please modify the prompt", + "refused try again", + "refused. to learn more about our content filtering policies please read our documentation: https://example.com/x", + "flagged by content filter. category: harassment, hate. please revise your input.", + ]; + test.each(accepted)("admits %s", prose => { + expect(isModerationRefusalProse(prose)).toBe(true); + }); + + const rejected = [ + "your account is suspended", + "quota exceeded: billing required", + "model not found", + "refused category: a!", + "refused and retried", + "please retry", + "category: harassment", + "", + ]; + test.each(rejected)("keeps dev's decision on %s", prose => { + expect(isModerationRefusalProse(prose)).toBe(false); + }); + + test("rejects a crafted category list in bounded time", () => { + // CodeQL js/redos: the old single-regex shape backtracked exponentially on + // "refused category: a" + ", and retry category: a" repeated before failing. + const attack = "refused category: a" + ", and retry category: a".repeat(80) + "!"; + const started = performance.now(); + expect(isModerationRefusalProse(attack)).toBe(false); + expect(performance.now() - started).toBeLessThan(1_000); + }); + + test("matches a crafted category list that happens to be accepted in bounded time", () => { + const attack = "refused category: a" + ", and retry category: a".repeat(80); + const started = performance.now(); + expect(isModerationRefusalProse(attack)).toBe(true); + expect(performance.now() - started).toBeLessThan(1_000); + }); +}); From cedbd9080b987d9e60b57200aa780e685a71c9ce Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:37:45 +0000 Subject: [PATCH 3/6] fix(combos): rank verdict alternatives longest-first in refusal prose scan Devin Review flagged two accepted-wording regressions on the rewritten matcher: the bare-verb verdict alternative won before the noun-phrased one that reaches `by ... system` (HTTP 400/422 + moderation code strings like "content refused by moderation system." were rejected), and the greedy category-list separator `, and ` swallowed retry-advice openings so "refused category: harassment, and retry later." failed to parse. Order the verdict scan Azure-first, then noun-phrased, then bare verb, then policy wording, and put a negative lookahead on the `, and ` separator for retry/try/please/to openings. The committed-test corpus now covers both regression shapes; equivalence vs the pre-fix regex holds at 0/42 divergences and the attack strings stay ~0.1ms vs >3.4s before. Co-Authored-By: Epinephrine --- src/combos/failover.ts | 11 +++++++---- tests/routing/combo-failover-moderation-prose.test.ts | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/combos/failover.ts b/src/combos/failover.ts index 55c971a0e9a..f64603fcc74 100644 --- a/src/combos/failover.ts +++ b/src/combos/failover.ts @@ -1063,18 +1063,21 @@ const RESPONSE_REQUEST_ECHO_KEYS = new Set([ */ // Verdict and tail stay apart: a single `^(?:verdict)(?:tail)*$` backtracks exponentially // because a category list swallows words ("and retry") that a later tail phrase also accepts. -// The Azure wording leads because "the response was filtered" is a strict prefix of it; the -// anchored scan commits to the first verdict alternative that matches, so the longest must run first. +// The anchored scan commits to the first verdict alternative that matches, so alternatives run +// longest-first: Azure's fixed wording leads ("the response was filtered" is a strict prefix of it) +// and the noun-phrased verdict precedes the bare one (its `by ... system` clause reaches further). const MODERATION_REFUSAL_VERDICT = new RegExp("^(?:" + "the response was filtered due to the prompt triggering azure openai'?s content management policy\\.?" - + "|(?:content )?(?:refused|flagged|blocked|rejected|filtered)(?: by (?:the )?(?:moderation|content filter))?\\.?" + "|(?:(?:the|your) )?(?:input|request|prompt|content|message|response|output)(?: (?:was|has been|is))?" + " (?:refused|flagged|blocked|rejected|filtered)(?: by (?:the )?(?:moderation|content filter)(?: system)?)?\\.?" + + "|(?:content )?(?:refused|flagged|blocked|rejected|filtered)(?: by (?:the )?(?:moderation|content filter))?\\.?" + "|(?:your )?(?:input|request|prompt|content) violated (?:the )?content (?:safety|management|filtering) polic(?:y|ies)\\.?" + ")", "i"); // Category separators are disjoint by first byte so each anchored match has exactly one parse. +// `, and ` skips retry/please/to word openings so `retry later` still parses as the retry advice +// rather than a trailing category (the historical ambiguity made both readings reach `$`). const MODERATION_REFUSAL_TAIL = new RegExp("^(?:" - + " categor(?:y|ies): [a-z][a-z/_-]*(?:(?:, and | and |, )[a-z][a-z/_-]*)*\\.?" + + " categor(?:y|ies): [a-z][a-z/_-]*(?:(?:, and (?!retry\\b|try\\b|please\\b|to\\b)| and |, )[a-z][a-z/_-]*)*\\.?" + "| please (?:modify|revise|rephrase|change|adjust|edit) (?:your|the) (?:prompt|input|request|message)(?: and (?:retry|try again))?\\.?" + "| (?:please )?(?:retry|try again)(?: later)?\\.?" + "| to learn more about our content filtering policies please read our documentation: https://[^ ]+" diff --git a/tests/routing/combo-failover-moderation-prose.test.ts b/tests/routing/combo-failover-moderation-prose.test.ts index c90f599e000..9463bd89c24 100644 --- a/tests/routing/combo-failover-moderation-prose.test.ts +++ b/tests/routing/combo-failover-moderation-prose.test.ts @@ -16,6 +16,13 @@ describe("moderation refusal prose matcher", () => { "Your request was rejected by the content filter system.", "the response was filtered due to the prompt triggering azure openai's content management policy.", "the response was filtered due to the prompt triggering azure openais content management policy.", + // A shorter verdict alternative must not win over the noun-phrased one that + // reaches `by ... system` — the scan commits to the first verdict match. + "content refused by moderation system.", + "The request was blocked by the content filter system.", + // `, and ` must not swallow retry-advice openings as category names. + "refused category: harassment, and retry later.", + "refused category: harassment, and please change your prompt.", "Your input violated the content safety policies.", "input violated content filtering policy", "refused category: a, b and c. please change your prompt and retry.", From e8dc03a6371da59771e61b0af3b30f442cc81217 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:54:13 +0000 Subject: [PATCH 4/6] ci: retrigger ocx-ci-v1 (shard 4/5 cancelled after all tests passed) Co-Authored-By: Epinephrine From 98e6ced02daada87fdbb0a5fabeb8b7605ec6813 Mon Sep 17 00:00:00 2001 From: luvs01 <27862058+luvs01@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:35:25 +0900 Subject: [PATCH 5/6] fix(combos): retain category-list alternatives through the full message --- src/combos/failover.ts | 49 ++++++++++++------- structure/providers-and-adapters.md | 2 + .../combo-failover-moderation-prose.test.ts | 2 + 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/combos/failover.ts b/src/combos/failover.ts index 194410e06d9..d72baa837ad 100644 --- a/src/combos/failover.ts +++ b/src/combos/failover.ts @@ -1226,8 +1226,6 @@ const RESPONSE_REQUEST_ECHO_KEYS = new Set([ * Any other wording (an account, model, parameter or billing problem, in any phrasing) does not * match, so the body keeps dev's decision; only known shapes are admitted. */ -// Verdict and tail stay apart: a single `^(?:verdict)(?:tail)*$` backtracks exponentially -// because a category list swallows words ("and retry") that a later tail phrase also accepts. // The anchored scan commits to the first verdict alternative that matches, so alternatives run // longest-first: Azure's fixed wording leads ("the response was filtered" is a strict prefix of it) // and the noun-phrased verdict precedes the bare one (its `by ... system` clause reaches further). @@ -1238,29 +1236,46 @@ const MODERATION_REFUSAL_VERDICT = new RegExp("^(?:" + "|(?:content )?(?:refused|flagged|blocked|rejected|filtered)(?: by (?:the )?(?:moderation|content filter))?\\.?" + "|(?:your )?(?:input|request|prompt|content) violated (?:the )?content (?:safety|management|filtering) polic(?:y|ies)\\.?" + ")", "i"); -// Category separators are disjoint by first byte so each anchored match has exactly one parse. -// `, and ` skips retry/please/to word openings so `retry later` still parses as the retry advice -// rather than a trailing category (the historical ambiguity made both readings reach `$`). -const MODERATION_REFUSAL_TAIL = new RegExp("^(?:" - + " categor(?:y|ies): [a-z][a-z/_-]*(?:(?:, and (?!retry\\b|try\\b|please\\b|to\\b)| and |, )[a-z][a-z/_-]*)*\\.?" +const MODERATION_REFUSAL_TAIL = new RegExp("(?:" + + "( categor(?:y|ies): )" + "| please (?:modify|revise|rephrase|change|adjust|edit) (?:your|the) (?:prompt|input|request|message)(?: and (?:retry|try again))?\\.?" + "| (?:please )?(?:retry|try again)(?: later)?\\.?" + "| to learn more about our content filtering policies please read our documentation: https://[^ ]+" - + ")", "i"); + + ")", "iy"); +const MODERATION_CATEGORY_WORD = /[a-z][a-z/_-]*/iy; +const MODERATION_CATEGORY_AND = / and /iy; -/** Whether a prose string is a known moderation refusal copy and nothing else (bounded, linear). */ +/** Whether the whole string is known moderation refusal copy. */ export function isModerationRefusalProse(text: string): boolean { if (text.length > 2_000) return false; - let rest = text.replace(/\s+/g, " ").trim(); - const verdict = MODERATION_REFUSAL_VERDICT.exec(rest); + const prose = text.replace(/\s+/g, " ").trim(); + const verdict = MODERATION_REFUSAL_VERDICT.exec(prose); if (!verdict) return false; - rest = rest.slice(verdict[0].length); - while (rest.length > 0) { - const piece = MODERATION_REFUSAL_TAIL.exec(rest); - if (!piece) return false; - rest = rest.slice(piece[0].length); + + // A comma can introduce the category "and" or the separator ", and ". Keep both + // interpretations until the rest of the sentence distinguishes them. Each token + // boundary is visited once, even when several interpretations reach it. + const tailStarts = new Set([verdict[0].length]); + const categoryStarts = new Set(); + for (let index = verdict[0].length; index < prose.length; index++) { + if (tailStarts.has(index)) { + MODERATION_REFUSAL_TAIL.lastIndex = index; + const tail = MODERATION_REFUSAL_TAIL.exec(prose); + if (tail) { + const next = tail[1] ? categoryStarts : tailStarts; + next.add(MODERATION_REFUSAL_TAIL.lastIndex); + } + } + if (!categoryStarts.has(index)) continue; + MODERATION_CATEGORY_WORD.lastIndex = index; + if (!MODERATION_CATEGORY_WORD.test(prose)) continue; + const end = MODERATION_CATEGORY_WORD.lastIndex; + tailStarts.add(prose[end] === "." ? end + 1 : end); + if (prose.startsWith(", ", end)) categoryStarts.add(end + 2); + MODERATION_CATEGORY_AND.lastIndex = prose[end] === "," ? end + 1 : end; + if (MODERATION_CATEGORY_AND.test(prose)) categoryStarts.add(MODERATION_CATEGORY_AND.lastIndex); } - return true; + return tailStarts.has(prose.length); } /** diff --git a/structure/providers-and-adapters.md b/structure/providers-and-adapters.md index 1c312121cdc..d005c2642a9 100644 --- a/structure/providers-and-adapters.md +++ b/structure/providers-and-adapters.md @@ -589,6 +589,8 @@ Account-row projection is loaded with `import()` after each account probe in `sr ## Combo model refusal evidence `src/combos/failover.ts` recognizes a bounded, exact HTTP 400 plan/model refusal, not credential or entitlement evidence. It also permits OpenRouter's exact opaque numeric-400 wrapper (`Provider returned error` with `metadata.raw: "ERROR"`, without `type`) to try another combo target. Typed uncoded 400s, malformed `response_format` schema errors and other terminal `invalid_request_error` cases stop and cool the target. An envelope root that states a terminal code of its own stops too (`origin_rejected`, `content_policy_violation`, `context_length_exceeded`, `invalid_request_error`, the shared terminal-refusal set and the non-replayable post-send codes, not a blanket inequality); a root that states only an ordinary hop signal adds no verdict, and an empty code counts as absent. The root code and the record it wraps are both consulted, so a hop needs each to authorize one and a root hard stop is never hidden behind a retryable nested record. Request-local target incompatibilities recognized by `isRequestLocalTargetIncompatibility` and `isResponseFormatCapabilityRefusal` may advance without cooling. So may a provider or gateway moderation verdict on HTTP 400/422 (`isProviderModerationRefusal`), granted on structured evidence only and only for the known shape of a refusal: a `moderation_refusal` or `content_filter` code (the caller's, or a `code`/`error_code` in the body; a `type` or an incomplete `reason` of `content_filter` alone is a model's own output filter and stays terminal) and nothing else. The walk (`moderationVerdictFields`) admits a closed set of fields: verdict codes and types on a short compatible list, a stated status of 400/422 (or a Responses `failed`/`incomplete` state), a `param` naming the prompt or input (or an AI SDK error object read as a record), bare identifiers (`id`, `request_id`, `model`, `name`...), `innererror`, Azure's per-category filter results in their own shape only (category objects of flags and numbers, a `severity` of safe/low/medium/high, bare `id`/`url`/`license` tokens and compatible codes; any other text, or a key naming a state, status, error or message, stops), and a gateway's `providerMetadata` holding plain routing tokens under keys that name no state. Any other field stops. Prose (`message`, a string `error`, plain text with a caller's code) must be known refusal copy as a whole, after whitespace is collapsed: one verdict sentence (OpenAI's "The input was refused by moderation", Azure's content-management sentence, a bare "filtered"...) optionally followed by the category list, the advice to change the prompt and retry, and Azure's documentation pointer; anything else, an account, model, parameter or billing problem in any phrasing, keeps dev's decision. A Responses event's own `response.*` type is read as the carrier, whose response object is read without the fields that echo the caller's request (`instructions`, `tools`, `text`, `reasoning`, `input`, `output`, `usage`...); its `metadata` must be empty. Prose alone never hops (owner decision on #8428). It never outranks a stop: an envelope root verdict code, a hard-refusal token in any spelling (JSON-escaped, camelCase, or with hyphens, dots, slashes or spaces for underscores), safety or terminal-refusal copy, a malformed `response_format` diagnostic, subscription-gate wording, or any text the shared `classifyError` files more specifically than a generic invalid request keeps the terminal decision and its cooldown, and quota, billing or account-state evidence (including such wording beside a moderation code) still cools the provider. The verdict needs the whole body: `consumeComboFailure`, the responses stream preflight, the Messages native preflight and `policy-fallback.ts` judge the complete bounded body or event and pass `providerModerationRefusal`; a preflight that rebuilds a slim envelope attaches the whole event as combo failure evidence whenever either reads as a moderation verdict, and an event that states a non-400/422 status of its own is never a moderation refusal; and without it a classification text of 500 characters or more (possibly cut) never hops. +Within a category list, `and` can name a category or separate two names. The parser accepts a reading only if the rest of the message matches the expected grammar. + `src/server/responses/core-combo-failure.ts` captures its finite classification before display truncation; `src/server/responses/combo-stream-preflight.ts` preserves it before rebuilding terminal SSE errors. `src/server/responses/core-options.ts` carries the value to the combo decision. An inspected non-match diff --git a/tests/routing/combo-failover-moderation-prose.test.ts b/tests/routing/combo-failover-moderation-prose.test.ts index 9463bd89c24..8b4e0c263c5 100644 --- a/tests/routing/combo-failover-moderation-prose.test.ts +++ b/tests/routing/combo-failover-moderation-prose.test.ts @@ -23,6 +23,8 @@ describe("moderation refusal prose matcher", () => { // `, and ` must not swallow retry-advice openings as category names. "refused category: harassment, and retry later.", "refused category: harassment, and please change your prompt.", + "content refused. category: spam, and please", + "refused category: a, and and b", "Your input violated the content safety policies.", "input violated content filtering policy", "refused category: a, b and c. please change your prompt and retry.", From 21a4b6db51e783f54e8e896d4d4cfdc0ee97d2e7 Mon Sep 17 00:00:00 2001 From: luvs01 <27862058+luvs01@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:39:42 +0900 Subject: [PATCH 6/6] docs: keep category-list guidance within the structure budget --- structure/providers-and-adapters.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/structure/providers-and-adapters.md b/structure/providers-and-adapters.md index d005c2642a9..a41948c29a2 100644 --- a/structure/providers-and-adapters.md +++ b/structure/providers-and-adapters.md @@ -588,9 +588,7 @@ Account-row projection is loaded with `import()` after each account probe in `sr ## Combo model refusal evidence -`src/combos/failover.ts` recognizes a bounded, exact HTTP 400 plan/model refusal, not credential or entitlement evidence. It also permits OpenRouter's exact opaque numeric-400 wrapper (`Provider returned error` with `metadata.raw: "ERROR"`, without `type`) to try another combo target. Typed uncoded 400s, malformed `response_format` schema errors and other terminal `invalid_request_error` cases stop and cool the target. An envelope root that states a terminal code of its own stops too (`origin_rejected`, `content_policy_violation`, `context_length_exceeded`, `invalid_request_error`, the shared terminal-refusal set and the non-replayable post-send codes, not a blanket inequality); a root that states only an ordinary hop signal adds no verdict, and an empty code counts as absent. The root code and the record it wraps are both consulted, so a hop needs each to authorize one and a root hard stop is never hidden behind a retryable nested record. Request-local target incompatibilities recognized by `isRequestLocalTargetIncompatibility` and `isResponseFormatCapabilityRefusal` may advance without cooling. So may a provider or gateway moderation verdict on HTTP 400/422 (`isProviderModerationRefusal`), granted on structured evidence only and only for the known shape of a refusal: a `moderation_refusal` or `content_filter` code (the caller's, or a `code`/`error_code` in the body; a `type` or an incomplete `reason` of `content_filter` alone is a model's own output filter and stays terminal) and nothing else. The walk (`moderationVerdictFields`) admits a closed set of fields: verdict codes and types on a short compatible list, a stated status of 400/422 (or a Responses `failed`/`incomplete` state), a `param` naming the prompt or input (or an AI SDK error object read as a record), bare identifiers (`id`, `request_id`, `model`, `name`...), `innererror`, Azure's per-category filter results in their own shape only (category objects of flags and numbers, a `severity` of safe/low/medium/high, bare `id`/`url`/`license` tokens and compatible codes; any other text, or a key naming a state, status, error or message, stops), and a gateway's `providerMetadata` holding plain routing tokens under keys that name no state. Any other field stops. Prose (`message`, a string `error`, plain text with a caller's code) must be known refusal copy as a whole, after whitespace is collapsed: one verdict sentence (OpenAI's "The input was refused by moderation", Azure's content-management sentence, a bare "filtered"...) optionally followed by the category list, the advice to change the prompt and retry, and Azure's documentation pointer; anything else, an account, model, parameter or billing problem in any phrasing, keeps dev's decision. A Responses event's own `response.*` type is read as the carrier, whose response object is read without the fields that echo the caller's request (`instructions`, `tools`, `text`, `reasoning`, `input`, `output`, `usage`...); its `metadata` must be empty. Prose alone never hops (owner decision on #8428). It never outranks a stop: an envelope root verdict code, a hard-refusal token in any spelling (JSON-escaped, camelCase, or with hyphens, dots, slashes or spaces for underscores), safety or terminal-refusal copy, a malformed `response_format` diagnostic, subscription-gate wording, or any text the shared `classifyError` files more specifically than a generic invalid request keeps the terminal decision and its cooldown, and quota, billing or account-state evidence (including such wording beside a moderation code) still cools the provider. The verdict needs the whole body: `consumeComboFailure`, the responses stream preflight, the Messages native preflight and `policy-fallback.ts` judge the complete bounded body or event and pass `providerModerationRefusal`; a preflight that rebuilds a slim envelope attaches the whole event as combo failure evidence whenever either reads as a moderation verdict, and an event that states a non-400/422 status of its own is never a moderation refusal; and without it a classification text of 500 characters or more (possibly cut) never hops. -Within a category list, `and` can name a category or separate two names. The parser accepts a reading only if the rest of the message matches the expected grammar. - +`src/combos/failover.ts` recognizes a bounded, exact HTTP 400 plan/model refusal, not credential or entitlement evidence. It also permits OpenRouter's exact opaque numeric-400 wrapper (`Provider returned error` with `metadata.raw: "ERROR"`, without `type`) to try another combo target. Typed uncoded 400s, malformed `response_format` schema errors and other terminal `invalid_request_error` cases stop and cool the target. An envelope root that states a terminal code of its own stops too (`origin_rejected`, `content_policy_violation`, `context_length_exceeded`, `invalid_request_error`, the shared terminal-refusal set and the non-replayable post-send codes, not a blanket inequality); a root that states only an ordinary hop signal adds no verdict, and an empty code counts as absent. The root code and the record it wraps are both consulted, so a hop needs each to authorize one and a root hard stop is never hidden behind a retryable nested record. Request-local target incompatibilities recognized by `isRequestLocalTargetIncompatibility` and `isResponseFormatCapabilityRefusal` may advance without cooling. So may a provider or gateway moderation verdict on HTTP 400/422 (`isProviderModerationRefusal`), granted on structured evidence only and only for the known shape of a refusal: a `moderation_refusal` or `content_filter` code (the caller's, or a `code`/`error_code` in the body; a `type` or an incomplete `reason` of `content_filter` alone is a model's own output filter and stays terminal) and nothing else. The walk (`moderationVerdictFields`) admits a closed set of fields: verdict codes and types on a short compatible list, a stated status of 400/422 (or a Responses `failed`/`incomplete` state), a `param` naming the prompt or input (or an AI SDK error object read as a record), bare identifiers (`id`, `request_id`, `model`, `name`...), `innererror`, Azure's per-category filter results in their own shape only (category objects of flags and numbers, a `severity` of safe/low/medium/high, bare `id`/`url`/`license` tokens and compatible codes; any other text, or a key naming a state, status, error or message, stops), and a gateway's `providerMetadata` holding plain routing tokens under keys that name no state. Any other field stops. Prose (`message`, a string `error`, plain text with a caller's code) must be known refusal copy as a whole, after whitespace is collapsed: one verdict sentence (OpenAI's "The input was refused by moderation", Azure's content-management sentence, a bare "filtered"...) optionally followed by the category list (where `and` can be a name or a separator), the advice to change the prompt and retry, and Azure's documentation pointer; anything else, an account, model, parameter or billing problem in any phrasing, keeps dev's decision. A Responses event's own `response.*` type is read as the carrier, whose response object is read without the fields that echo the caller's request (`instructions`, `tools`, `text`, `reasoning`, `input`, `output`, `usage`...); its `metadata` must be empty. Prose alone never hops (owner decision on #8428). It never outranks a stop: an envelope root verdict code, a hard-refusal token in any spelling (JSON-escaped, camelCase, or with hyphens, dots, slashes or spaces for underscores), safety or terminal-refusal copy, a malformed `response_format` diagnostic, subscription-gate wording, or any text the shared `classifyError` files more specifically than a generic invalid request keeps the terminal decision and its cooldown, and quota, billing or account-state evidence (including such wording beside a moderation code) still cools the provider. The verdict needs the whole body: `consumeComboFailure`, the responses stream preflight, the Messages native preflight and `policy-fallback.ts` judge the complete bounded body or event and pass `providerModerationRefusal`; a preflight that rebuilds a slim envelope attaches the whole event as combo failure evidence whenever either reads as a moderation verdict, and an event that states a non-400/422 status of its own is never a moderation refusal; and without it a classification text of 500 characters or more (possibly cut) never hops. `src/server/responses/core-combo-failure.ts` captures its finite classification before display truncation; `src/server/responses/combo-stream-preflight.ts` preserves it before rebuilding terminal SSE errors. `src/server/responses/core-options.ts` carries the value to the combo decision. An inspected non-match