fix(openai): preserve bare gpt-5.3-codex-spark across forwarding paths#1262
Open
InCerryGit wants to merge 5 commits intoWei-Shaw:mainfrom
Open
fix(openai): preserve bare gpt-5.3-codex-spark across forwarding paths#1262InCerryGit wants to merge 5 commits intoWei-Shaw:mainfrom
InCerryGit wants to merge 5 commits intoWei-Shaw:mainfrom
Conversation
- 接入 gpt-5.4-mini/nano 模型识别与规范化,补充默认模型列表 - 增加 gpt-5.4-mini/nano 输入/缓存命中/输出价格与计费兜底逻辑 - 同步前端模型白名单与 OpenCode 配置 - 补充 service tier(priority/flex) 计费回归测试
# Conflicts: # backend/internal/service/billing_service.go
Contributor
Author
|
This work started as a fix for gpt-5.3-codex-spark being incorrectly mapped to gpt-5.3-codex, but the investigation showed it was not just a bad mapping entry. The final upstream model decision had been spread across multiple layers, so this could not be fixed by changing a single mapping value and instead required a broader cleanup of the forwarding and normalization logic. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes an OpenAI forwarding inconsistency where the final upstream model choice for
gpt-5.3-codex-sparkwas not decided in one explicit place.Previously, the actual upstream model could be implicitly changed by a mix of:
normalizeCodexModel(),applyCodexOAuthTransform(),That made bare
gpt-5.3-codex-sparkhandling inconsistent across the normal OpenAI path, OpenAI-compatible paths, WebSocket forwarding,UpstreamModelreporting, and compat prompt-cache behavior.What was wrong
The core problem was a responsibility boundary issue:
These concerns were partially mixed together.
As a result, changing one Spark mapping was not enough, because different forwarding paths could still diverge:
What changed
1. Added an explicit upstream model resolver
Introduced
resolveOpenAIUpstreamModel()in:backend/internal/service/openai_model_mapping.goThis is now the single place that decides the final upstream model for OpenAI forwarding behavior, including the bare
gpt-5.3-codex-sparkcase.2. Wired all real forwarding entry points to the same resolver
Updated these paths to use the explicit upstream resolver:
backend/internal/service/openai_gateway_service.gobackend/internal/service/openai_gateway_chat_completions.gobackend/internal/service/openai_gateway_messages.gobackend/internal/service/openai_ws_forwarder.goThis keeps the normal OpenAI path, compat paths, and WS forwarding aligned.
3. Pulled forwarding policy back out of OAuth/transform cleanup
Updated:
backend/internal/service/openai_codex_transform.goSo that
applyCodexOAuthTransform()no longer silently decides the final upstream model. It now stays focused on request cleanup / transport adaptation instead of forwarding policy.4. Aligned compat prompt-cache and reporting with the final upstream model
Updated:
backend/internal/service/openai_compat_prompt_cache_key.goSo prompt-cache derivation follows the same resolved upstream model family.
Also aligned
UpstreamModelreporting to match the actual model chosen by the new resolver.Tests
Added/updated targeted tests for:
Validated in Docker with targeted service tests:
TestResolveOpenAIForwardModel_PreventsClaudeModelFromFallingBackToGpt51TestResolveOpenAIUpstreamModelTestShouldAutoInjectPromptCacheKeyForCompatTestDeriveCompatPromptCacheKey_UsesResolvedSparkFamilyTestApplyCodexOAuthTransform_PreservesBareSparkModelTestApplyCodexOAuthTransform_TrimmedModelWithoutPolicyRewriteNotes
This change does not change billing semantics.
It only makes the final upstream forwarding decision explicit and consistent across all OpenAI forwarding surfaces.