Skip to content

[WRONG BRANCH] fix: avoid spreading hosted-tool indices - #45

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-rangeerror-in-hosted-tool-requests
Draft

[WRONG BRANCH] fix: avoid spreading hosted-tool indices#45
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-rangeerror-in-hosted-tool-requests

Conversation

@luvs01

@luvs01 luvs01 commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Motivation

  • A Math.min(...strippedAdditionalToolsIndices) spread of an attacker-controlled set could throw RangeError for very large additional_tools arrays, causing a denial-of-service during request build.
  • The change aims to eliminate the attacker-cardinality-dependent spread while preserving the intended single hosted image_generation restore semantics.

Description

  • Replace the Set + spread + Math.min(...) approach with constant-space tracking of the first stripped additional_tools container via firstStrippedAdditionalToolsIndex, and use that single index when restoring the hosted tool.
  • Keep request-scoped behavior so exactly one hosted image_generation declaration is restored into the first applicable container.
  • Add focused regression coverage in tests/openai-responses-passthrough.test.ts that asserts restoration does not rely on spreading indices (simulates a constrained Math.min to catch regressions).
  • Changes touch src/adapters/openai-responses.ts and tests/openai-responses-passthrough.test.ts only.

Testing

  • PATH="$PWD/node_modules/.bin:$PATH" bun test tests/openai-responses-passthrough.test.ts — passed (61 tests in that focused file).
  • PATH="$PWD/node_modules/.bin:$PATH" bun run typecheck — passed (typecheck clean).
  • PATH="$PWD/node_modules/.bin:$PATH" bun run test — attempted but the full-suite run encountered unrelated timeouts in this environment; the focused tests and typecheck that exercise the change passed.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of hosted image-generation tools across multiple tool containers.
    • Prevented request construction errors in certain multi-container scenarios.
  • Tests

    • Added regression coverage to verify image-generation requests complete successfully without exceeding argument limits.

@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.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title fix: avoid spreading hosted-tool indices [WRONG BRANCH] fix: avoid spreading hosted-tool indices Aug 7, 2026
@github-actions
github-actions Bot marked this pull request as draft August 7, 2026 11:12
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The adapter now tracks only the first additional_tools container that loses an image-generation declaration. Restoration uses that container. A regression test covers three containers and guards against unsupported multi-argument Math.min calls.

Changes

Hosted image-generation restoration

Layer / File(s) Summary
Track and restore the first stripped container
src/adapters/openai-responses.ts, tests/openai-responses-passthrough.test.ts
At lines 708–715, the adapter records the first matching additional_tools container. At lines 734–743, it restores image_generation into that container without duplicate restoration. The regression test at lines 1226–1253 validates request construction with three containers and restores the original Math.min implementation.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: lidge-jun, ingwannu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: replacing the spread of hosted-tool indices to prevent unsafe request construction.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-rangeerror-in-hosted-tool-requests

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

@github-actions github-actions Bot added the bug Something isn't working label Aug 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/openai-responses-passthrough.test.ts`:
- Around line 1241-1248: Update the test around adapter.buildRequest to capture
the returned request, then assert the restored payload contains exactly one
hosted image_generation declaration in the first stripped additional_tools
container. Also assert the second and third additional_tools containers do not
contain a duplicate, while preserving the existing no-throw check.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 23813477-4052-486b-b617-f180495315b3

📥 Commits

Reviewing files that changed from the base of the PR and between 2468502 and 5952301.

📒 Files selected for processing (2)
  • src/adapters/openai-responses.ts
  • tests/openai-responses-passthrough.test.ts

Comment on lines +1241 to +1248
try {
expect(() => adapter.buildRequest({
modelId: "provider-image-model",
context: { messages: [] },
stream: true,
options: {},
_rawBody: { model: "provider-image-model", input },
}, meta)).not.toThrow();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the restored payload, not only request construction.

This test can pass if the adapter strips all three client declarations and restores none, or restores image_generation to the wrong container. Capture the built request and assert that this input restores exactly one hosted declaration in the first stripped additional_tools container. Assert that the second and third containers do not receive a duplicate.

As per path instructions, the adapter behavior change must have a focused regression test that checks the changed behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/openai-responses-passthrough.test.ts` around lines 1241 - 1248, Update
the test around adapter.buildRequest to capture the returned request, then
assert the restored payload contains exactly one hosted image_generation
declaration in the first stripped additional_tools container. Also assert the
second and third additional_tools containers do not contain a duplicate, while
preserving the existing no-throw check.

Source: Path instructions

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

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant