Skip to content

fix(translator): sanitize Read tool args from non-Anthropic models - #4451

Merged
diegosouzapw merged 1 commit into
release/v3.8.32from
feat/port-pr-1144-sanitize-read-tool-args
Jun 20, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.32from
feat/port-pr-1144-sanitize-read-tool-args

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Summary

Port of decolua/9router#1144 by @GodrezJr2 — when non-Anthropic models (GPT-5.5, DeepSeek …) are used as Claude Code CLI proxies, they sometimes emit absurd Read-tool args (most notably limit: 25999999999999999). Claude Code rejects bad params and retries — wasting tokens and producing noisy output.

OmniRoute already has the buffering / single-corrective-delta machinery (hasToolCallShim / applyToolCallShimToBuffer in open-sse/translator/helpers/toolCallShim.ts, groundwork laid for pages: "" stripping). This PR extends the Read shim's sanitization rules:

  • clamp limit to 2000 (Claude Code's hard cap); drop the field if non-positive
  • clamp negative offset to 0
  • coerce numeric-string limit / offset to numbers
  • keep pages only for .pdf files matching \d+(-\d+)?

All other tools and the rest of the translator pipeline are untouched.

Differences from upstream

  • Upstream is .js; OmniRoute is .ts — sanitization helper carries explicit types.
  • Upstream introduces the buffer-and-emit-once flow inside openai-to-claude.js. OmniRoute already had it via toolCallShim.ts (used for submit_pr_review and the original Read pages strip), so this PR is a pure shim extension — no changes to openai-to-claude.ts.
  • The previous pages rule (strip when empty-string or empty-array) is subsumed by the new PDF-only rule (also strips pages on non-PDF paths and malformed PDF ranges). Existing pages tests still pass.
  • PDF extension check is case-insensitive (.pdf / .PDF).

Test plan

  • node --import tsx/esm --test tests/unit/translator-tool-call-shim.test.ts — 30/30 pass (22 baseline + 8 new, including a combined-absurd-args case mirroring upstream's integration test).
  • Adjacent translator suites: openai-to-claude-strip-empty, translator-resp-openai-to-claude, translator-openai-to-claude — 24/24 pass.
  • npm run typecheck:core — exit 0.
  • npx eslint open-sse/translator/helpers/toolCallShim.ts tests/unit/translator-tool-call-shim.test.ts — 0 errors (4 pre-existing any warnings in the test file).

Inspired-by: decolua/9router#1144

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Non-Anthropic models (GPT-5.5, DeepSeek …) sometimes emit absurd values
for Claude Code's Read-tool args — most notably `limit: 25999999999999999`,
negative offsets, stringified numbers, and stray `pages` on non-PDF files.
Claude Code rejects those params and retries, wasting tokens and producing
noisy output.

The OmniRoute tool-call shim already buffers and re-emits Read args at
finish-time (groundwork laid in #1257 for `pages: ""`); this commit extends
the Read shim's `sanitizeReadArgs` rules:

- clamp `limit` to 2000 (Claude Code's hard cap), drop if non-positive
- clamp negative `offset` to 0
- coerce numeric-string `limit`/`offset` to numbers
- keep `pages` only for `.pdf` files matching `\d+(-\d+)?`

Pure inside-the-shim change — buffering/suppression/single-corrective-delta
flow already in place. Other tools and the rest of the translator are
untouched.

Tests (TDD, all 7 added cases RED → GREEN):
- limit clamp at 2000 (the original report's value)
- non-positive limit dropped
- negative offset clamped to 0
- numeric-string coercion for limit/offset
- pages stripped on non-PDF
- pages stripped on PDF when format is malformed
- single-page form `"7"` preserved on PDF (case-insensitive `.PDF`)
- combined absurd args (mirrors upstream's integration test)

Inspired-by: decolua/9router#1144
Co-authored-by: GodrezJr2 <168538340+GodrezJr2@users.noreply.github.com>
@diegosouzapw
diegosouzapw force-pushed the feat/port-pr-1144-sanitize-read-tool-args branch from dbf884f to 4a52479 Compare June 20, 2026 23:24
@diegosouzapw
diegosouzapw merged commit 0225a0a into release/v3.8.32 Jun 20, 2026
4 checks passed
@diegosouzapw
diegosouzapw deleted the feat/port-pr-1144-sanitize-read-tool-args branch June 21, 2026 12:33
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
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.

1 participant