Skip to content

[AISAGE-759] fix(ai-gateway): normalize ChatGPT-route Responses requests - #8555

Merged
chrarnoldus merged 3 commits into
mainfrom
fix/openai-chatgpt-responses-robustness
Oct 22, 2026
Merged

chrarnoldus merged 3 commits into
mainfrom
fix/openai-chatgpt-responses-robustness

Conversation

@chrarnoldus

@chrarnoldus chrarnoldus commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On the "Sign in with ChatGPT" route (openai-chatgpt provider on POST /responses), OpenAI rejects some requests that the gateway could easily send in an accepted form. The delegated transform now fixes two of them:

  • service_tier: subscription sharing accepts only auto and default, which behave the same as sending no tier. Any other value gets 400 subscription_sharing_unsupported_capability. The transform now always drops the field.
  • max_output_tokens: OpenAI rejects values below 16 with 400 integer_below_min_value. The transform now raises them to 16.
  • temperature / top_p: the recent reasoning models served on this route reject sampling parameters with 400 unsupported_parameter. The transform now drops both.

The token-refresh change that was originally part of this PR now lives in #8557, so it can be reviewed separately. The remaining error classes are tracked in AISAGE-759.

Verification

  • Checked production logs for this route: both rejections occur, with exactly the error codes and parameters this change handles.
  • Ran all openai-chatgpt/ suites and upstream-attempt.test.ts against local PostgreSQL; all pass.
  • Ran pnpm --filter @kilocode/web-shared typecheck and oxlint on the changed files; both are clean.
  • No manual end-to-end test: it needs a live ChatGPT subscription-sharing connection.

Visual Changes

N/A

Reviewer Notes

  • Dropping temperature and top_p unconditionally also affects older non-reasoning models (for example gpt-4o) if they are served on this route. For those models it removes a caller preference rather than fixing an error.
  • Dropping auto and default assumes they behave the same as sending no tier on this route. Since subscription sharing allows no other tier, sending one gains nothing.

…es rejections

Drop service_tier values other than auto/default and raise max_output_tokens
below 16 to 16 on the delegated route, both of which OpenAI rejects with 400.

Expire the stored delegated access token after an upstream 401 token_expired
or token_revoked, so the next request refreshes it instead of replaying the
dead token until its stored expiry.
@chrarnoldus chrarnoldus self-assigned this Oct 22, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental commit drops temperature and top_p on the delegated ChatGPT Responses route alongside the existing service_tier and max_output_tokens normalization, and adds a focused test; the ordering leaves no later step re-adding the removed fields.

Assumptions: [INFERENCE] Tests and typecheck were not executed in this read-only review (no code execution permitted), so verification is by reading the changed code and its callers. Dropping sampling parameters also affects any non-reasoning model served by the partner project; the PR description already records this tradeoff. Whether the partner project currently serves non-reasoning models such as gpt-4o could not be confirmed from the repository.

Verification Notes

  • provider.transformRequest runs last in apply-provider-specific-logic.ts:409, and no earlier helper re-adds temperature or top_p after the deletes at routing.ts:292-293.
  • fixResponsesRequest, removeUnsupportedRequestServiceTier, and the model-setting helpers all run before the provider transform, so the removals are the final write to those fields.
  • The new test uses the same transformResponsesRequest helper as the neighboring service_tier and max_output_tokens cases and asserts absence with in checks, so it fails if either field is reintroduced.
Files Reviewed (2 files)
  • packages/web-shared/src/lib/ai-gateway/openai-chatgpt/routing.ts
  • packages/web-shared/src/lib/ai-gateway/openai-chatgpt/routing.test.ts
Previous Review Summaries (2 snapshots, latest commit df5b912)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit df5b912)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental change narrows the PR to two files: service_tier is now dropped unconditionally on the delegated route and the token-expiry work is fully reverted out of the branch.

Assumptions: [INFERENCE] node_modules is not present in the review sandbox, so pnpm --filter @kilocode/web-shared typecheck and the Jest suites could not be re-run; findings are based on reading the changed code and its callers. max_output_tokens: null still passes through untouched, but that matches pre-change behavior on this route.

Verification Notes

  • Dropping service_tier remains the last write to it: removeUnsupportedRequestServiceTier and applyKiloExclusiveModelSettings run before provider.transformRequest in apply-provider-specific-logic.ts:371-409, so no later step re-adds a tier.
  • The reverted token-refresh code left no dangling references: no remaining imports of rejected-token.ts or expireOpenAiChatGptAccessToken exist in the repository.
  • The new clamp only touches numeric values below 16 and leaves absent (undefined) or non-numeric values untouched, consistent with the added tests.
Files Reviewed (2 files)
  • packages/web-shared/src/lib/ai-gateway/openai-chatgpt/routing.ts - no issues
  • packages/web-shared/src/lib/ai-gateway/openai-chatgpt/routing.test.ts - no issues

Previous review (commit d16453c)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The three delegated-route fixes are small, well-scoped, and consistent with the existing ChatGPT connection handling; the token-expiry compare-and-set under the row lock correctly avoids clobbering a concurrent refresh or reconnect.

Assumptions: [INFERENCE] node_modules is not present in the review sandbox, so pnpm --filter @kilocode/web-shared typecheck and the Jest suites could not be re-run; the review is based on reading the changed code and its callers. max_output_tokens: null and replica lag on readDb are unproven edge cases noted but not flagged, since neither is demonstrably wrong on the changed lines.

Files Reviewed (6 files)
  • packages/web-shared/src/lib/ai-gateway/openai-chatgpt/rejected-token.ts - no issues
  • packages/web-shared/src/lib/ai-gateway/openai-chatgpt/routing.ts - no issues
  • packages/web-shared/src/lib/ai-gateway/openai-chatgpt/routing.test.ts - no issues
  • packages/web-shared/src/lib/ai-gateway/openai-chatgpt/store.ts - no issues
  • packages/web-shared/src/lib/ai-gateway/providers/upstream-attempt.ts - no issues
  • packages/web-shared/src/lib/ai-gateway/providers/upstream-attempt.test.ts - no issues

Reviewed by deepseek-flash-latest · Input: 36.5K · Output: 7.2K · Cached: 680.6K

Review guidance: REVIEW.md from base branch main

@chrarnoldus chrarnoldus changed the title [AISAGE-759] fix(ai-gateway): avoid avoidable ChatGPT Responses rejections [AISAGE-759] fix(ai-gateway): normalize ChatGPT-route Responses requests Oct 22, 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.

2 participants