Skip to content

fix(codex): strip image_gen namespace tools - #1328

Merged
ding113 merged 5 commits into
ding113:devfrom
Brisbanehuang:codex/fix-codex-image-namespace-strip
Jul 12, 2026
Merged

fix(codex): strip image_gen namespace tools#1328
ding113 merged 5 commits into
ding113:devfrom
Brisbanehuang:codex/fix-codex-image-namespace-strip

Conversation

@Brisbanehuang

@Brisbanehuang Brisbanehuang commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • recognize Codex image generation tools declared as the image_gen namespace
  • strip image declarations from both top-level tools and Responses Lite input[].additional_tools when a provider forces image generation off
  • normalize related tool_choice and allowed_tools references while preserving unrelated tools and response history
  • add audit coverage for embedded additional tools

Problem

CCH's provider override only recognized the legacy { "type": "image_generation" } declaration. Newer Codex requests can expose image generation as { "type": "namespace", "name": "image_gen" }, including inside Responses Lite additional_tools carriers. As a result, a provider configured to force image generation off could still receive the image namespace and forward it upstream, where accounts without image access reject the request.

Related

Solution

When image generation is forced off, this change removes only image tool declarations and matching tool choices. It keeps other namespaces, ordinary tools, historical image_generation_call input items, and include fields intact. Empty additional_tools carriers are removed. The transformation remains copy-on-write.

When image generation is forced on, existing namespace declarations are reused for allowed_tools instead of injecting a mismatched legacy reference.

Key implementation points in src/lib/codex/provider-overrides.ts:

  • toImageGenerationToolReference now recognizes both { type: "image_generation" } and { type: "namespace", name: "image_gen" }.
  • applyInputImageGenerationToolPreference strips image tools from input[].additional_tools and drops emptied carriers.
  • isImageGenerationToolChoice covers additional tool_choice shapes (namespace object, nested tool, function.name), and summarizeImageGenerationToolChoice emits matching audit values.
  • Force-on path reuses the existing same-shape reference (via findImageGenerationToolReference) for allowed_tools injection rather than always inserting the legacy form.

This follows the complete-blocking behavior introduced in Sub2API v0.1.151 (d3a1835e).

Changes

  • src/lib/codex/provider-overrides.ts (+168/-16) - namespace detection, Responses Lite additional_tools stripping, expanded tool_choice handling, and a new input.additional_tools.image_generation audit path.
  • tests/unit/proxy/codex-provider-overrides.test.ts (+284) - force-on idempotency, same-shape allowed_tools reuse, force-off stripping across top-level and Responses Lite carriers, multiple tool_choice forms, and a negative test ensuring an unrelated imagegen function is not misidentified.

No breaking changes - internal helpers only; no exported signatures, schema, or migrations affected.

Testing

Automated Tests

  • Unit tests added (tests/unit/proxy/codex-provider-overrides.test.ts, +284)
  • Focused provider override tests: 33/33 passed

Validation

  • bun run lint
  • bun run lint:fix
  • bun run typecheck
  • LC_ALL=C bun run test (743 files passed, 6731 tests passed, 13 skipped)
  • bun run build

Manual Testing

No UI changes; this is proxy-pipeline logic. To verify end-to-end: send a Codex Responses request carrying { type: "namespace", name: "image_gen" } (in tools or input[].additional_tools) through a provider with codexImageGenerationPreference=false, and confirm the namespace (and any matching tool_choice) is stripped before the request is forwarded upstream.

Checklist

  • Code follows project conventions
  • Self-review completed
  • Tests pass locally
  • Documentation updated (if needed)

Description enhanced by Claude AI

Follow-up fixes

  • skip image-tool scans in both the direct override path and the production audit wrapper when image generation is inherited, before reading tools or input
  • add a getter-based regression test through applyCodexProviderOverridesWithAudit to cover the real forwarding path
  • include the existing OpenAPI optional-chaining safety fix required by Biome 2.5.3 CI (tests/api/api-openapi-spec.test.ts)

Follow-up validation: full Biome 2.5.3 check passed; local full suite 6732 passed / 13 skipped; production build passed.

Greptile Summary

This PR closes a gap in the Codex provider image-generation override: the existing logic only recognised the legacy { type: "image_generation" } declaration, so requests using the newer { type: "namespace", name: "image_gen" } form — including inside Responses Lite input[].additional_tools carriers — could slip through a force-off provider and reach upstream accounts that reject image access. The fix adds namespace detection across all relevant shapes, strips image tools from both the top-level tools array and embedded additional_tools carriers, normalises associated tool_choice references, and reuses the same-shape reference (legacy or namespace) when force-on injects into allowed_tools.

  • toImageGenerationToolReference / isImageGenerationTool: now recognises { type: \"image_generation\" }, { type: \"namespace\", name: \"image_gen\" }, and { type: \"namespace\", namespace: \"image_gen\" }, covering both field spellings for the namespace form.
  • applyInputImageGenerationToolPreference: new function that strips image tools from input[].additional_tools carriers on force-off; carriers with no remaining tools are dropped, others are preserved.
  • isImageGenerationToolChoice / summarizeImageGenerationToolChoice: extended to handle namespace objects and the nested-tool wrapping; the depth check is a single one-level unwrap (calls isImageGenerationTool, not itself), so there is no recursive risk.
  • Audit path: beforeInputImageGeneration / afterInputImageGeneration scans are now guarded behind the early-exit hit check, eliminating unnecessary property reads when all preferences are inherited.

Confidence Score: 5/5

Safe to merge — the change is scoped entirely to internal helper functions, preserves copy-on-write semantics, and carries comprehensive test coverage across all new code paths.

Both gaps flagged in the previous review round are correctly addressed. isImageGenerationToolChoice calls isImageGenerationTool (not itself), eliminating any recursive risk. toImageGenerationToolReference handles both name and namespace field spellings uniformly so filtering is consistent everywhere. The 284 new test lines cover force-on idempotency, force-off stripping across both carriers, same-shape reference reuse, multiple tool_choice shapes, and the inherit-path early-exit. No exported API, schema, or migration is touched.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/codex/provider-overrides.ts Extended image-generation override logic to strip namespace tools from both top-level tools and Responses Lite input[].additional_tools, normalize multiple tool_choice shapes, and reuse same-shape references on force-on. Copy-on-write discipline maintained throughout.
tests/unit/proxy/codex-provider-overrides.test.ts +284 lines of new unit tests covering force-on idempotency, same-shape allowed_tools reuse, force-off stripping across both carriers, multiple tool_choice shapes, negative test for unrelated namespace, and a getter-based regression for the inherit early-exit path.
tests/api/api-openapi-spec.test.ts Minor Biome 2.5.3 lint fix: extracts publicStatusOperation?.parameters into a local variable to satisfy optional-chaining rules before the map call.

Reviews (2): Last reviewed commit: "fix(codex): narrow image tool choice mat..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

扩展 Codex provider 覆写对 image_generation 的识别与处理,覆盖顶层 toolsinput.additional_tools 和多种 tool_choice 结构,并将 input 相关变化纳入审计记录与单元测试。

Changes

Codex 图像生成工具处理

Layer / File(s) Summary
工具引用识别与 input 清理
src/lib/codex/provider-overrides.ts
统一识别 image_generationimage_gen namespace 引用,并支持清理 input.additional_tools 中的图像工具声明。
tool_choice 覆写与调用链集成
src/lib/codex/provider-overrides.ts
启用时复用请求中的图像工具引用形状,禁用时识别并移除多种图像工具选择结构。
审计记录与行为测试
src/lib/codex/provider-overrides.ts, tests/unit/proxy/codex-provider-overrides.test.ts, tests/api/api-openapi-spec.test.ts
审计 input.additional_tools.image_generation 的前后状态,并覆盖继承、启用、禁用、命名空间及多种 tool_choice 场景;同时调整 public-status 参数测试的数据复用方式。

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: ding113

🚥 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.
Title check ✅ Passed 标题简洁且准确概括了核心变更:移除 Codex 的 image_gen 命名空间工具。
Description check ✅ Passed 描述与变更内容一致,准确说明了 image_gen 识别、剥离与相关审计/测试更新。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@github-actions github-actions Bot added bug Something isn't working area:provider area:OpenAI labels Jul 12, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request enhances the Codex provider overrides logic to support image generation tools declared within the input.additional_tools field (Responses Lite format) and as namespace tools (e.g., image_gen). It introduces helper functions to identify, extract, and filter these tool definitions and choices, ensuring consistent behavior when enabling or disabling image generation capabilities. Additionally, comprehensive unit tests have been added to verify these new behaviors and audit logging. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@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 `@src/lib/codex/provider-overrides.ts`:
- Around line 378-383: 在调用 applyImageGenerationToolChoicePreference 前先判断
imageGeneration 是否为 null;为 null 时跳过整个调用及其参数构造,避免执行
findImageGenerationToolReference 和 hasAvailableTool 的全量扫描。保持非 null 偏好下现有调用行为不变。
🪄 Autofix (Beta)

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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3adcdc2-c019-4f14-9aea-82a4b9981bf7

📥 Commits

Reviewing files that changed from the base of the PR and between 595a7d9 and df7d04f.

📒 Files selected for processing (2)
  • src/lib/codex/provider-overrides.ts
  • tests/unit/proxy/codex-provider-overrides.test.ts

Comment thread src/lib/codex/provider-overrides.ts Outdated
@Brisbanehuang
Brisbanehuang marked this pull request as ready for review July 12, 2026 06:58

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83989621ca

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/lib/codex/provider-overrides.ts Outdated
@github-actions github-actions Bot added the size/L Large PR (< 1000 lines) label Jul 12, 2026

@github-actions github-actions 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.

Code Review Summary

No significant issues identified in this PR. The namespace-detection gap in the Codex image-generation provider override is closed cleanly: detection, Responses Lite additional_tools stripping, expanded tool_choice handling, and a new audit path are all internally consistent and well-tested. The copy-on-write discipline and the inherit short-circuit (avoiding tools/input reads) are preserved correctly.

PR Size: L

  • Lines changed: 517 (494 additions / 23 deletions)
  • Files changed: 3
  • Note: Technically L by line count, but ~317 of the 494 added lines are unit tests. The substantive production change is ~195 lines in a single module (provider-overrides.ts) plus a 3-line Biome-driven test refactor. This is one cohesive fix with appropriate coverage and does not warrant splitting.

Issues Found

Category Critical High Medium Low
Logic/Bugs 0 0 0 0
Security 0 0 0 0
Error Handling 0 0 0 0
Types 0 0 0 0
Comments/Docs 0 0 0 0
Tests 0 0 0 0
Simplification 0 0 0 0

Review Notes

  • Force-on path correctly reuses the existing same-shape reference (findImageGenerationToolReference) for allowed_tools injection instead of always emitting the legacy { type: "image_generation" } form. The reference is normalized (only type/name), which matches the test expectations and is appropriate for an allowed_tools entry.
  • Force-off path strips image tools from both top-level tools and input[].additional_tools, drops emptied carriers, and preserves unrelated namespaces, historical image_generation_call items, and include fields — verified by dedicated tests.
  • isImageGenerationToolChoice covers the additional shapes (namespace object via name/namespace, nested tool, function.name) and summarizeImageGenerationToolChoice emits matching audit values; the two stay consistent across all parameterized forms.
  • The inherit short-circuit (if (imageGeneration !== null)) correctly skips tool/input scans in both the direct override path and the audit wrapper; the getter-based regression test confirms zero reads.
  • The audit changes array is typed generically (Array<{ path: string; ... }>), so the new input.additional_tools.image_generation entry is type-safe and the sole consumer (forwarder.ts) persists it opaquely. No exported signatures changed.
  • The OpenAPI test refactor (extracting publicStatusOperation?.parameters to a local) is the correct fix for Biome 2.5.3's redundant optional-chaining access rule.

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean (pure synchronous transform, no I/O)
  • Type safety - Clean
  • Documentation accuracy - Clean (docstring updated to reflect input.additional_tools)
  • Test coverage - Adequate
  • Code clarity - Good

Automated review by Claude AI

Comment thread src/lib/codex/provider-overrides.ts Outdated
Comment thread src/lib/codex/provider-overrides.ts Outdated
@coderabbitai
coderabbitai Bot requested a review from ding113 July 12, 2026 07:23
@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

@ding113
ding113 merged commit 6fcb827 into ding113:dev Jul 12, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Claude Code Hub Roadmap Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:OpenAI area:provider bug Something isn't working size/L Large PR (< 1000 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants