Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
2e3e8687
Unverified
Commit
2e3e8687
authored
Mar 14, 2026
by
Wesley Liddick
Committed by
GitHub
Mar 14, 2026
Browse files
Merge pull request #993 from xvhuan/fix/codex-responses-id-prefix-hotfix-20260314
fix: 止血 Codex/Responses 原生 input id 被误改成 fc_*
parents
9350ecb6
ca42a458
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/openai_codex_transform.go
View file @
2e3e8687
...
...
@@ -339,8 +339,9 @@ func filterCodexInput(input []any, preserveReferences bool) []any {
}
typ
,
_
:=
m
[
"type"
]
.
(
string
)
// 修复 OpenAI 上游的最新校验:"Expected an ID that begins with 'fc'"
fixIDPrefix
:=
func
(
id
string
)
string
{
// 仅修正真正的 tool/function call 标识,避免误改普通 message/reasoning id;
// 若 item_reference 指向 legacy call_* 标识,则仅修正该引用本身。
fixCallIDPrefix
:=
func
(
id
string
)
string
{
if
id
==
""
||
strings
.
HasPrefix
(
id
,
"fc"
)
{
return
id
}
...
...
@@ -358,8 +359,8 @@ func filterCodexInput(input []any, preserveReferences bool) []any {
for
key
,
value
:=
range
m
{
newItem
[
key
]
=
value
}
if
id
,
ok
:=
newItem
[
"id"
]
.
(
string
);
ok
&&
id
!=
""
{
newItem
[
"id"
]
=
fixIDPrefix
(
id
)
if
id
,
ok
:=
newItem
[
"id"
]
.
(
string
);
ok
&&
strings
.
HasPrefix
(
id
,
"call_"
)
{
newItem
[
"id"
]
=
fix
Call
IDPrefix
(
id
)
}
filtered
=
append
(
filtered
,
newItem
)
continue
...
...
@@ -390,7 +391,7 @@ func filterCodexInput(input []any, preserveReferences bool) []any {
}
if
callID
!=
""
{
fixedCallID
:=
fixIDPrefix
(
callID
)
fixedCallID
:=
fix
Call
IDPrefix
(
callID
)
if
fixedCallID
!=
callID
{
ensureCopy
()
newItem
[
"call_id"
]
=
fixedCallID
...
...
@@ -404,14 +405,6 @@ func filterCodexInput(input []any, preserveReferences bool) []any {
if
!
isCodexToolCallItemType
(
typ
)
{
delete
(
newItem
,
"call_id"
)
}
}
else
{
if
id
,
ok
:=
newItem
[
"id"
]
.
(
string
);
ok
&&
id
!=
""
{
fixedID
:=
fixIDPrefix
(
id
)
if
fixedID
!=
id
{
ensureCopy
()
newItem
[
"id"
]
=
fixedID
}
}
}
filtered
=
append
(
filtered
,
newItem
)
...
...
backend/internal/service/openai_codex_transform_test.go
View file @
2e3e8687
...
...
@@ -33,12 +33,63 @@ func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) {
first
,
ok
:=
input
[
0
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"item_reference"
,
first
[
"type"
])
require
.
Equal
(
t
,
"
fc_
ref1"
,
first
[
"id"
])
require
.
Equal
(
t
,
"ref1"
,
first
[
"id"
])
// 校验 input[1] 为 map,确保后续字段断言安全。
second
,
ok
:=
input
[
1
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"fc_o1"
,
second
[
"id"
])
require
.
Equal
(
t
,
"o1"
,
second
[
"id"
])
require
.
Equal
(
t
,
"fc1"
,
second
[
"call_id"
])
}
func
TestApplyCodexOAuthTransform_ToolContinuationPreservesNativeMessageAndReasoningIDs
(
t
*
testing
.
T
)
{
reqBody
:=
map
[
string
]
any
{
"model"
:
"gpt-5.2"
,
"input"
:
[]
any
{
map
[
string
]
any
{
"type"
:
"message"
,
"id"
:
"msg_0"
,
"role"
:
"user"
,
"content"
:
"hi"
},
map
[
string
]
any
{
"type"
:
"item_reference"
,
"id"
:
"rs_123"
},
},
"tool_choice"
:
"auto"
,
}
applyCodexOAuthTransform
(
reqBody
,
false
,
false
)
input
,
ok
:=
reqBody
[
"input"
]
.
([]
any
)
require
.
True
(
t
,
ok
)
require
.
Len
(
t
,
input
,
2
)
first
,
ok
:=
input
[
0
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"msg_0"
,
first
[
"id"
])
second
,
ok
:=
input
[
1
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"rs_123"
,
second
[
"id"
])
}
func
TestApplyCodexOAuthTransform_ToolContinuationNormalizesToolReferenceIDsOnly
(
t
*
testing
.
T
)
{
reqBody
:=
map
[
string
]
any
{
"model"
:
"gpt-5.2"
,
"input"
:
[]
any
{
map
[
string
]
any
{
"type"
:
"item_reference"
,
"id"
:
"call_1"
},
map
[
string
]
any
{
"type"
:
"function_call_output"
,
"call_id"
:
"call_1"
,
"output"
:
"ok"
},
},
"tool_choice"
:
"auto"
,
}
applyCodexOAuthTransform
(
reqBody
,
false
,
false
)
input
,
ok
:=
reqBody
[
"input"
]
.
([]
any
)
require
.
True
(
t
,
ok
)
require
.
Len
(
t
,
input
,
2
)
first
,
ok
:=
input
[
0
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"fc1"
,
first
[
"id"
])
second
,
ok
:=
input
[
1
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"fc1"
,
second
[
"call_id"
])
}
func
TestApplyCodexOAuthTransform_ExplicitStoreFalsePreserved
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment