Skip to content

fix(claude): sanitize WebSearch domain filters for routed models - #383

Merged
Ingwannu merged 1 commit into
devfrom
fix/claude-websearch-domains
Jul 24, 2026
Merged

Ingwannu merged 1 commit into
devfrom
fix/claude-websearch-domains

Conversation

@Wibias

@Wibias Wibias commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Sanitize Claude Code WebSearch / web_search* tool_use inputs from routed models: omit empty allowed_domains / blocked_domains, and if both are non-empty keep allowed_domains only.
  • Apply on both JSON and SSE outbound paths (SSE buffers WebSearch args and emits one sanitized input_json_delta).

Fixes #381.

Test plan

  • bun run typecheck
  • bun test tests/claude-outbound.test.ts (25 pass)
  • Manual: Claude Code + routed GPT (gpt-5.6-sol) asking for a domain-filtered web search no longer 400s on empty domain arrays

Summary by CodeRabbit

  • Bug Fixes
    • Improved WebSearch domain filter handling for more reliable requests.
    • Removes empty or ambiguous domain filters and prioritizes allowed domains when conflicting filters are provided.
    • Applies consistent sanitization to both streamed and non-streamed WebSearch results.

Omit empty allowed_domains/blocked_domains and resolve mutual exclusion before
Claude Code sees tool_use input, so GPT-routed WebSearch calls stop tripping
Anthropic/Claude Code validation (#381).
@github-actions github-actions Bot added the bug Something isn't working label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 31e2c18a-7988-41ff-b034-63acabae3bce

📥 Commits

Reviewing files that changed from the base of the PR and between 9f953d8 and ed9e4ee.

📒 Files selected for processing (2)
  • src/claude/outbound.ts
  • tests/claude-outbound.test.ts

📝 Walkthrough

Walkthrough

Adds WebSearch domain-filter sanitization to Claude JSON and SSE translation. Empty filters are omitted, conflicting non-empty filters favor allowed_domains, and streamed arguments are buffered before one sanitized delta is emitted.

Changes

WebSearch translation

Layer / File(s) Summary
WebSearch sanitization and JSON translation
src/claude/outbound.ts
Adds WebSearch name detection and input normalization, then applies it to constructed and JSON-translated tool inputs.
Buffered SSE WebSearch emission
src/claude/outbound.ts
Buffers WebSearch argument deltas and emits one sanitized input_json_delta when the tool block closes.
Sanitization and translation tests
tests/claude-outbound.test.ts
Tests empty-filter removal, conflicting-filter handling, JSON translation, and SSE buffering behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant OpenAIResponsesSSE
  participant SSETranslator
  participant closeOpenBlock
  participant AnthropicStream
  OpenAIResponsesSSE->>SSETranslator: function_call and argument delta frames
  SSETranslator->>SSETranslator: buffer WebSearch arguments
  OpenAIResponsesSSE->>SSETranslator: output_item.done
  SSETranslator->>closeOpenBlock: close buffered tool_use
  closeOpenBlock->>AnthropicStream: one sanitized input_json_delta
Loading

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: sanitizing routed-model WebSearch domain filters.
Linked Issues check ✅ Passed The changes satisfy #381 by omitting empty filters, enforcing one domain filter, and applying sanitization in both JSON and SSE paths.
Out of Scope Changes check ✅ Passed No unrelated code changes are indicated beyond the WebSearch sanitization and its supporting test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/claude-websearch-domains

Comment @coderabbitai help to get the list of available commands.

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Verified against current dev. The reported Claude Code failure is real: routed WebSearch calls may contain empty or mutually exclusive domain filters, and this patch sanitizes both JSON and SSE translation paths without weakening terminal handling. I also reran the focused suite (25/25) and TypeScript typecheck at ed9e4ee; both passed, and required CI is green.

@Ingwannu
Ingwannu merged commit b758556 into dev Jul 24, 2026
12 checks passed
@lidge-jun
lidge-jun deleted the fix/claude-websearch-domains branch July 25, 2026 17:37
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…domains

fix(claude): sanitize WebSearch domain filters for routed models
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