fix(openai): require replay for HTTP continuations after SSE fallback (#756)

Co-authored-by: Zyy <zyycn@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Zyy
2026-11-20 22:20:56 +08:00
committed by GitHub
co-authored by Zyy Codex
parent 4b5443d2f2
commit 0df6c40091
4 changed files with 39 additions and 33 deletions
@@ -1019,17 +1019,13 @@ impl CodexProvider {
{
return Err(continuation_replay_required_error("scope_unavailable"));
}
if upstream_request
.downstream_websocket_connection_id
.is_some()
&& upstream_request.previous_response_id().is_some()
if upstream_request.previous_response_id().is_some()
&& upstream_request.generate()
&& previous_session.as_ref().is_some_and(|state| {
state.continuation_scope == OpenAiContinuationScope::ReplayRequired
})
{
// HTTP store=false 没有原生续链,完整历史仍由客户端持有;不能把 delta
// 当作独立新请求发送,也不能用 previous_response_id 猜测上游存储状态
// 上一轮已确认需要重放,只有客户端持有完整历史
return Err(continuation_replay_required_error("scope_unavailable"));
}
let trace = context.trace();
@@ -5687,30 +5687,39 @@ async fn oversized_websocket_http_response_continues_with_client_tool_history_re
),
("store".to_owned(), json!(false)),
]);
let error = Arc::clone(&provider)
.execute(
planned_request("openai", ws_operation(delta, "ws_first", Some(state))),
pinned_continuation_context(
"req_large_ws_delta",
"acct_provider_contract",
"resp_large_ws_http",
"resp_large_ws_http",
1,
ContinuationAttempt::Native,
),
)
.await
.err()
.expect("HTTP store=false delta requires client replay");
assert_eq!(error.send_state(), UpstreamSendState::NotSent);
assert_eq!(
error.client_visible_upstream_error().unwrap().code(),
Some("previous_response_not_found")
);
assert_eq!(
error.continuation_recovery_disposition(),
Some(ContinuationRecoveryDisposition::ClientReplayRequired)
);
let http_delta = GenerateRequest::from_protocol_payload(
ProtocolPayload::json_object("openai", delta.clone()).unwrap(),
)
.with_provider_session_state(state.clone());
for operation in [
ws_operation(delta, "ws_first", Some(state)),
Operation::Generate(http_delta),
] {
let error = Arc::clone(&provider)
.execute(
planned_request("openai", operation),
pinned_continuation_context(
"req_large_ws_delta",
"acct_provider_contract",
"resp_large_ws_http",
"resp_large_ws_http",
1,
ContinuationAttempt::Native,
),
)
.await
.err()
.expect("HTTP store=false delta requires client replay");
assert_eq!(error.send_state(), UpstreamSendState::NotSent);
assert_eq!(
error.client_visible_upstream_error().unwrap().code(),
Some("previous_response_not_found")
);
assert_eq!(
error.continuation_recovery_disposition(),
Some(ContinuationRecoveryDisposition::ClientReplayRequired)
);
}
assert_eq!(server.received_requests().await.unwrap().len(), 1);
let input = body.get_mut("input").unwrap().as_array_mut().unwrap();
+3 -2
View File
@@ -678,8 +678,9 @@ OpenAI Responses 上游 WS 按握手响应头 `x-codex-websocket-max-message-byt
该上限只属于当前上游连接;响应头缺失或无效时不预判超限。显式 warmup 保持 WS 合同,超限时
返回 `websocket_message_too_large`,不重复发送或改用 HTTP
超过当前连接上限的 connection-local WS 续接,以及 HTTP `store=false` 成功后标记为 `ReplayRequired`
的 WS 增量,均在发送前返回 `status: 400 / previous_response_not_found`。客户端应清除旧 ID,
超过当前连接上限的 connection-local WS 续接会在发送前返回 `400 previous_response_not_found`。
上游 HTTP/SSE 在 `store=false` 下成功后,若网关已记录该响应需要完整重放,HTTP 和 WS 客户端携带其
`previous_response_id` 继续生成时也会收到同一错误。客户端应清除旧 ID,
携带完整历史及工具调用/输出重试。官方 Codex 支持重连 WS 后完整重发,也可能按自身重试预算
切到 HTTP;其他客户端需要自行实现此合同。代理不缓存 transcript,不把增量输入当作独立新链,
连接内续接失去原连接时仍需客户端恢复
+1 -1
View File
@@ -698,7 +698,7 @@ Continuation 受原请求的 Client Key、账号范围、Provider 和发送/交
- native continuation 固定创建它的 Provider 与账号
- OpenAI Provider 在发送前按上游握手声明的消息大小上限检查最终出站帧,新链可选择 HTTP;超限的 connection-local
续接和 HTTP `store=false` 后不可原生续写的 WS 增量返回 `ClientReplayRequired`,由客户端重发
续接和已标记为需要重放的 HTTP/WS 增量返回 `ClientReplayRequired`,由客户端重发
完整历史。预检拒绝先释放连接及租约,不消耗 WS 故障预算;Provider session state 只携带元数据,不保存 transcript
- OpenAI 在有效输出交付前收到可安全重放的明确额度拒绝时,先隔离账号,再投影 `ClientReplayRequired`;
丢弃未交付的原错误帧,由客户端提交完整历史开启新链,不把原增量输入交给其他账号。