Skip to content

fix(combos): preserve moderation category boundaries in a single scan - #8978

Merged
lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:codex/moderation-category-boundaries
Nov 21, 2026
Merged

lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:codex/moderation-category-boundaries

Conversation

@luvs01

@luvs01 luvs01 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Parse the verdict, category lists, and optional advice in one forward scan. Keep both readings of an ambiguous category separator until the complete message determines which one fits.
  • Preserve the 2,000-character limit and the existing requirement for structured moderation evidence. The regression cases cover category names that can also appear in ordinary English advice.
  • The branch commit credits the original co-author.

Verification

  • On Bun 1.4.4, bun test tests/routing/router-combo-failover-classification.test.ts -t 'recognizes category-list boundaries|the observed gateway refusal|moderation phrases alone|recognizes explicit moderation codes|hard stops like|generic 400 errors without moderation phrasing' passed 9 tests and 86 assertions.
  • bun run typecheck passed across 2,681 files. git diff --check passed.
  • The local run used focused coverage because the Windows test worker was shared with an ongoing full-suite run. The rest of the suite was not run locally for this commit.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • The parser contract is documented in the provider and adapter structure notes.
  • Reviewed the diff for secrets, authentication changes, and unsafe defaults.

Maintainer review is pending.

Summary by CodeRabbit

  • Bug Fixes
    • Improved recognition of moderation refusal messages with varied category-list formatting and trailing text, reducing the chance that valid refusals are misclassified.
    • When documented moderation evidence is present, eligible provider refusals can proceed to another available option without cooling down the refused option. Other terminal, safety, quota, billing, and account-state signals continue to take precedence.
  • Documentation
    • Clarified that classification considers the complete bounded body or event, and when long classification text does not qualify for moderation-refusal handling.

Carry the bounded matcher from #841 and retain both category-list readings until the end of the message.

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The moderation refusal prose parser now handles varied category-list separators and trailing text. It retains the 2,000-character limit. Tests cover structured-code gating and an ambiguous input. Documentation describes the related failover conditions.

Changes: Moderation refusal parsing

Layer / File(s) Summary
Category-list parsing and validation
src/combos/failover.ts, tests/routing/router-combo-failover-classification.test.ts, structure/providers-and-adapters.md
The parser scans category-list boundaries and recognizes trailing prose. Tests cover separator variations, require the structured moderation_refusal code, and check that an ambiguous input is rejected within 250 ms. Documentation states that qualifying HTTP 400/422 refusals may advance to another combo target without cooling, subject to documented exclusions and text-length rules.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • lidge-jun/opencodex#8428: Introduced the moderation-refusal classifier and structured evidence path that this change updates.
Merge Risk: Minimal · up to f089d

This change makes moderation refusal parsing handle more category-list phrasings without exponential backtracking, and it updates the related failover documentation. No concrete merge-blocking risk was found in the reviewed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: moderation category boundary handling in the combos failover logic, parsed in a single scan. It matches the raw summary, which describes separating verdict, category-l…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: moderation category boundary handling in the combos failover logic, parsed in a single scan. It matches the raw summary, which describes separating verdict, category-list, and trailing-copy recognition in src/combos/failover.ts, and the objectives, which describe parsing the verdict, category lists, and advice in one forward scan. The title is specific, concise, and follows the conventional commit style.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6fc8e0f and f089da9.

Files selected for processing: 1

  • tests/routing/router-combo-failover-classification.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 20, 2026
…cktracking

The added category-boundary cases also matched the old regex, so nothing failed if the
scan were reverted. This case uses the CodeQL js/redos attack shape from #841:
on origin/dev it takes about 976 ms per body (Bun's backtracking limit), on this head 1.4 ms.
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration into dev (MAINTAINERS.md maintainer-integration exception; lane fb2101-queue-b).

  • Exact head: f089da922389f7e0d09317dd347345967093165b
  • Checks on this head: all completed checks pass (ci aggregate with gates and test changed, CodeRabbit, enforce-target, hygiene); none pending or failing.
  • Review: terra round 1 found that the added category-boundary cases also matched the old regex, so nothing would fail if the scan were reverted. The maintainer added f089da9, a CodeQL js/redos regression using the attack shape from fix(combos): make moderation-refusal prose matching linear (CodeQL js/redos) luvs01/opencodex#841: it fails on origin/dev source (about 976 ms per body against a 250 ms bound) and passes on this head (about 1.4 ms). Terra round 2: APPROVE; router-combo-failover-classification + combo-failure-transport-parity 233 pass, typecheck and structure:check exit 0.
  • Review threads: 0 unresolved.
  • Scope: bounded moderation-prose scan in src/combos/failover.ts plus structure doc; no auth, workflow, release, dependency or provider-preset surface.

This is maintainer integration, not an independent approval.

@lidge-jun
lidge-jun merged commit eaeba52 into lidge-jun:dev Nov 21, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants