Skip to content

fix(ai): classify OpenAI cyber_policy refusals as content policy - #64844

Merged
neriousy merged 1 commit into
anomalyco:devfrom
lu-zero:fix/openai-cyber-policy
Nov 19, 2026
Merged

neriousy merged 1 commit into
anomalyco:devfrom
lu-zero:fix/openai-cyber-policy

Conversation

@lu-zero

@lu-zero lu-zero commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #64843

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

OpenAI's cybersecurity safeguard reports its refusals with the code cyber_policy, both as an HTTP 400 and as an error frame mid-stream. That code was not in CONTENT_POLICY_CODES and the wording does not match CONTENT_POLICY_TEXT, so these refusals fell through to UnknownProvider. Adding the code makes classifyProviderFailure return ContentPolicy for both shapes, since providerCodes already reads the code from the body or from the code: message summary.

How did you verify your code works?

Added a test in packages/ai/test/provider-error.test.ts covering the 400 body and the stream error frame; it fails without the change and passes with it. bun test test/provider-error.test.ts and bun run typecheck in packages/ai pass.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I reproduced it on the base branch: running OpenAI's cyber_policy stream error frame through the Responses providerFailure path gives UnknownProvider, and with this change it gives ContentPolicy. The new test fails on the base branch and passes here. The full provider-error.test.ts suite passes, and tsc --noEmit on packages/ai is clean. The code lookup runs before the quota, auth, rate-limit and server-error checks, so both the HTTP 400 and the mid-stream shapes go through it. The public API is unchanged. No concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI cyber_policy refusals are classified as UnknownProvider instead of ContentPolicy

2 participants