From 657c4f97d904d796c806c7bd612ac5929307dcaf Mon Sep 17 00:00:00 2001 From: li Date: Fri, 10 Jul 2026 09:56:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(openai):=20=E5=8D=87=E7=BA=A7=20Codex=20?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=89=88=E6=9C=AC=E8=87=B3=200.144.?= =?UTF-8?q?1=EF=BC=8C=E4=BF=AE=E5=A4=8D=20gpt-5.6-luna=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3895 --- .../internal/service/account_usage_service.go | 2 +- .../openai_codex_version_consistency_test.go | 21 +++++++++++++++++++ .../service/openai_gateway_service.go | 4 ++-- .../service/setting_gateway_runtime.go | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 backend/internal/service/openai_codex_version_consistency_test.go diff --git a/backend/internal/service/account_usage_service.go b/backend/internal/service/account_usage_service.go index d9f6200359..4add6310c6 100644 --- a/backend/internal/service/account_usage_service.go +++ b/backend/internal/service/account_usage_service.go @@ -111,7 +111,7 @@ const ( apiQueryMaxJitter = 800 * time.Millisecond // 用量查询最大随机延迟 windowStatsCacheTTL = 1 * time.Minute openAIProbeCacheTTL = 10 * time.Minute - openAICodexProbeVersion = "0.125.0" + openAICodexProbeVersion = "0.144.1" ) // UsageCache 封装账户使用量相关的缓存 diff --git a/backend/internal/service/openai_codex_version_consistency_test.go b/backend/internal/service/openai_codex_version_consistency_test.go new file mode 100644 index 0000000000..48883032aa --- /dev/null +++ b/backend/internal/service/openai_codex_version_consistency_test.go @@ -0,0 +1,21 @@ +//go:build unit + +package service + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCodexVersionConstants_Consistency(t *testing.T) { + require.Equal(t, codexCLIVersion, openAICodexProbeVersion, + "codexCLIVersion and openAICodexProbeVersion must stay in sync") + + require.True(t, strings.Contains(codexCLIUserAgent, "codex_cli_rs/"+codexCLIVersion), + "codexCLIUserAgent must embed codexCLIVersion") + + require.True(t, strings.Contains(DefaultOpenAICodexUserAgent, codexCLIVersion), + "DefaultOpenAICodexUserAgent must embed codexCLIVersion") +} diff --git a/backend/internal/service/openai_gateway_service.go b/backend/internal/service/openai_gateway_service.go index af8ae3ffe5..0d03d83dcf 100644 --- a/backend/internal/service/openai_gateway_service.go +++ b/backend/internal/service/openai_gateway_service.go @@ -35,7 +35,7 @@ const ( // 与真实 Codex CLI 的 User-Agent 结构对齐: // {originator}/{version} ({OS} {OS_version}; {arch}) {terminal} // 旧值 "codex_cli_rs/0.125.0" 缺少 OS/架构/终端后缀,易被上游指纹识别为非官方客户端。 - codexCLIUserAgent = "codex_cli_rs/0.125.0 (Ubuntu 22.4.0; x86_64) xterm-256color" + codexCLIUserAgent = "codex_cli_rs/0.144.1 (Ubuntu 22.4.0; x86_64) xterm-256color" // codex_cli_only 拒绝时单个请求头日志长度上限(字符) codexCLIOnlyHeaderValueMaxBytes = 256 @@ -49,7 +49,7 @@ const ( openAIWSRetryBackoffMaxDefault = 2 * time.Second openAIWSRetryJitterRatioDefault = 0.2 openAICompactSessionSeedKey = "openai_compact_session_seed" - codexCLIVersion = "0.125.0" + codexCLIVersion = "0.144.1" // Codex 限额快照仅用于后台展示/诊断,不需要每个成功请求都立即落库。 openAICodexSnapshotPersistMinInterval = 30 * time.Second // 配额自动暂停时,超过该时长仍未刷新的 used% 快照视为陈旧,不再据此暂停账号。 diff --git a/backend/internal/service/setting_gateway_runtime.go b/backend/internal/service/setting_gateway_runtime.go index ea4037d990..3ed4f39def 100644 --- a/backend/internal/service/setting_gateway_runtime.go +++ b/backend/internal/service/setting_gateway_runtime.go @@ -83,7 +83,7 @@ const antigravityUserAgentVersionErrorTTL = 5 * time.Second const antigravityUserAgentVersionDBTimeout = 5 * time.Second // DefaultOpenAICodexUserAgent OpenAI Codex 默认 User-Agent(用于规避 Cloudflare 对浏览器 UA 的质询) -const DefaultOpenAICodexUserAgent = "codex-tui/0.125.0 (Ubuntu 22.4.0; x86_64) xterm-256color (codex-tui; 0.125.0)" +const DefaultOpenAICodexUserAgent = "codex-tui/0.144.1 (Ubuntu 22.4.0; x86_64) xterm-256color (codex-tui; 0.144.1)" // cachedOpenAICodexUserAgent 缓存 OpenAI Codex UA(进程内缓存,60s TTL) type cachedOpenAICodexUserAgent struct {