Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(codex): 跨供应商切模型后剔除 Responses 拒绝的历史 message/reasoning id(#4738) (#4752)
FicoWang39b71c6b2d04
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.tsindex b1267d5e9d..578750fe1e 100644--- a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts@@ -120,8 +120,16 @@ vi.mock('@cindy/anthropic-compat-proxy', async (importOriginal) => {/image generation items without [`']?id[`']? are not supported/i.test(text),strip: () => null,}),+ createResponsesItemIdPrefixRecoveryRule: () => ({+ id: 'responses_item_id_prefix',+ enabled: () => true,+ matches: (text: string) =>+ /Invalid\s+["']input\[\d+\]\.id["']:\s*["'](?!(?:fc|fco|ctc|ctco)_)[^"']+["']\.?\s+Expected an ID that begins with ["'](?:msg|rs)["']/i.test(text),+ strip: () => null,+ }),stripEncryptedContentFromBody: () => null,stripImageGenerationItemsWithoutIdFromBody: () => null,+ stripNonCanonicalResponsesItemIdsFromBody: () => null,stripNonAnthropicFields: mockState.stripNonAnthropicFields,// 视觉桥 transform:默认短路(controller 未注入 → shouldBridge 恒 false → null 透传)。createVisionBridgeTransform: () => (() => null),@@ -2730,13 +2738,13 @@ describe('codex proxy host', () => {// upstream 是函数形态(每请求现取,model-access 下发可运行期换 endpoint);// 断言其当前求值 = 网关 base + /v1upstream: expect.any(Function),- // [encrypted activeStrip, image generation activeStrip, provider-aware Guardian reviewer, locked Subagent route, instructions 注入, locked Subagent exec guard, Gateway 原生 web_search, 跨来源压缩块兼容, xAI ModelInput activeStrip, exec function adapter, strict gateway history 兼容, xAI ModelInput sanitize, DeepSeek V4 custom tool 兼容, xAI Responses 兼容, XD Gateway Grok 兼容, ByteDance Seed tool 兼容, MiniMax effort 兼容, provider model rewrite, provider 参数归一, 视觉桥(controller 未注入 → 短路透传), 工具 ID 校正, stripNonAnthropicFields]+ // [encrypted activeStrip, image generation activeStrip, provider-aware Guardian reviewer, locked Subagent route, instructions 注入, locked Subagent exec guard, Gateway 原生 web_search, 跨来源压缩块兼容, xAI ModelInput activeStrip, responses item id activeStrip(#4738), exec function adapter, strict gateway history 兼容, xAI ModelInput sanitize, DeepSeek V4 custom tool 兼容, xAI Responses 兼容, XD Gateway Grok 兼容, ByteDance Seed tool 兼容, MiniMax effort 兼容, provider model rewrite, provider 参数归一, 视觉桥(controller 未注入 → 短路透传), 工具 ID 校正, stripNonAnthropicFields]transformRequest: [expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function),expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function),expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function),expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function),- expect.any(Function), expect.any(Function), expect.any(Function),+ expect.any(Function), expect.any(Function), expect.any(Function), expect.any(Function),],transformResponse: expect.any(Function),routingTransform: expect.any(Function),@@ -2744,6 +2752,7 @@ describe('codex proxy host', () => {recoveryRules: expect.arrayContaining([expect.objectContaining({ id: 'encrypted_content' }),expect.objectContaining({ id: 'image_generation_id' }),+ expect.objectContaining({ id: 'responses_item_id_prefix' }),expect.objectContaining({ id: 'xai_model_input' }),]),}),@@ -2849,6 +2858,11 @@ describe('codex proxy host', () => {threadId: 'thread-image',message: 'Image generation items without `id` are not supported for this request.',})).toBe('image_generation_id');+ expect(host.armCodexHttpRecovery({+ sessionId: 'session-msg-id',+ threadId: 'thread-msg-id',+ message: "Invalid 'input[290].id': 'chatcmpl-8f2a1c_msg_0'. Expected an ID that begins with 'msg'.",+ })).toBe('responses_item_id_prefix');expect(proxyOpts.resolveWebSocketUpstream(ctxForThread('thread-encrypted'))).toBeNull();expect(proxyOpts.resolveWebSocketUpstream(ctxForThread('thread-image'))).toBeNull();@@ -6401,7 +6415,7 @@ describe('codex proxy host', () => {await host.ensureCodexProxyReady();const transforms = mockState.createAnthropicCompatProxy.mock.calls[0]?.[0]?.transformRequest ?? [];- expect(transforms).toHaveLength(23); // encrypted activeStrip, image generation activeStrip, provider-aware Guardian reviewer, locked Subagent route, instructions 注入, locked Subagent exec guard, Gateway 原生 web_search, 跨来源压缩块兼容, xAI ModelInput activeStrip, exec function adapter, strict gateway history 兼容, xAI ModelInput sanitize, DeepSeek V4 custom tool 兼容, xAI Responses 兼容, XD Gateway Grok 兼容, ByteDance Seed tool 兼容, MiniMax effort 兼容, provider model rewrite, provider 参数归一, 视觉桥(短路), 工具 ID 校正, stripNonAnthropicFields, dump+ expect(transforms).toHaveLength(24); // encrypted activeStrip, image generation activeStrip, provider-aware Guardian reviewer, locked Subagent route, instructions 注入, locked Subagent exec guard, Gateway 原生 web_search, 跨来源压缩块兼容, xAI ModelInput activeStrip, responses item id activeStrip(#4738), exec function adapter, strict gateway history 兼容, xAI ModelInput sanitize, DeepSeek V4 custom tool 兼容, xAI Responses 兼容, XD Gateway Grok 兼容, ByteDance Seed tool 兼容, MiniMax effort 兼容, provider model rewrite, provider 参数归一, 视觉桥(短路), 工具 ID 校正, stripNonAnthropicFields, dumpconst ctx = {method: 'POST',url: '/v1/responses',diff --git a/apps/desktop/src/main/maker-host/codex-proxy-host.ts b/apps/desktop/src/main/maker-host/codex-proxy-host.tsindex 571d33806e..eb69137662 100644--- a/apps/desktop/src/main/maker-host/codex-proxy-host.ts+++ b/apps/desktop/src/main/maker-host/codex-proxy-host.ts@@ -29,6 +29,7 @@ import {createActiveStripTransform,createEncryptedContentRecoveryRule,createImageGenerationIdRecoveryRule,+ createResponsesItemIdPrefixRecoveryRule,createInstructionsInjectionTransform,createInstructionsRegistry,createXaiModelInputRecoveryRule,@@ -38,6 +39,7 @@ import {sanitizeXaiModelInputFromBody,stripEncryptedContentFromBody,stripImageGenerationItemsWithoutIdFromBody,+ stripNonCanonicalResponsesItemIdsFromBody,stripNonAnthropicFields,type ForwardLifecycleFailure,type ForwardLifecycleObserver,@@ -109,6 +111,7 @@ import { xaiServerSideTools } from './xai-server-side-tools.js';import {encryptedStripController,imageGenerationStripController,+ responsesItemIdStripController,xaiModelInputStripController,} from './thread-strip-controllers.js';import { createMakerLogger } from './logger-adapter.js';@@ -200,6 +203,9 @@ const encryptedContentRecoveryRule = createEncryptedContentRecoveryRule({const imageGenerationIdRecoveryRule = createImageGenerationIdRecoveryRule({onRetry: (threadId, model) => imageGenerationStripController.markActive(threadId, model),});+const responsesItemIdPrefixRecoveryRule = createResponsesItemIdPrefixRecoveryRule({+ onRetry: (threadId, model) => responsesItemIdStripController.markActive(threadId, model),+});const xaiModelInputRecoveryRule = createXaiModelInputRecoveryRule({onRetry: (threadId, model) => xaiModelInputStripController.markActive(threadId, model),});@@ -207,6 +213,7 @@ const vllmResponsesCompatibilityRule = createVllmResponsesCompatibilityRule();const CODEX_BODY_RECOVERY_RULES = [encryptedContentRecoveryRule,imageGenerationIdRecoveryRule,+ responsesItemIdPrefixRecoveryRule,xaiModelInputRecoveryRule,vllmResponsesCompatibilityRule,] as const;@@ -2900,6 +2907,13 @@ function createTransformRequestChain(enabled: () => true,strip: sanitizeXaiModelInputFromBody,}),+ // issue #4738: 上游拒绝过一次不合规 message/reasoning id 后, 该 thread 后续每次发送+ // 前都预洗, 避免每轮先 400 再重试。+ createActiveStripTransform({+ controller: responsesItemIdStripController,+ enabled: () => true,+ strip: stripNonCanonicalResponsesItemIdsFromBody,+ }),// Providers that explicitly lack Responses custom tools still accept ordinary// functions. Adapt before provider sanitizers, then restore custom_tool_call// events on the matching response stream.diff --git a/apps/desktop/src/main/maker-host/thread-strip-controllers.ts b/apps/desktop/src/main/maker-host/thread-strip-controllers.tsindex 16705e2e43..1088a35113 100644--- a/apps/desktop/src/main/maker-host/thread-strip-controllers.ts+++ b/apps/desktop/src/main/maker-host/thread-strip-controllers.ts@@ -11,6 +11,10 @@ export const encryptedStripController = createThreadStripController();// 缺 id 的 image generation 历史 item 主动剥离 —— always-on(只删上游已拒绝过的坏历史项)。export const imageGenerationStripController = createThreadStripController();+// Responses 历史 message/reasoning item 不合规 id 前缀主动剥离(issue #4738: Gemini 历史+// 切 GPT 后 `chatcmpl-…_msg_0` 被 Responses 拒绝)—— always-on; 恢复一次后该 thread 发送前预洗。+export const responsesItemIdStripController = createThreadStripController();+// 空 thinking 块主动剥离 —— always-on(删空块零成本)。必须与上面是独立实例。export const emptyThinkingStripController = createThreadStripController();diff --git a/packages/anthropic-compat-proxy/src/index.ts b/packages/anthropic-compat-proxy/src/index.tsindex 848b1a0f4b..81af9b7118 100644--- a/packages/anthropic-compat-proxy/src/index.ts+++ b/packages/anthropic-compat-proxy/src/index.ts@@ -44,6 +44,7 @@ export {createEmptyThinkingRecoveryRule,createEncryptedContentRecoveryRule,createImageGenerationIdRecoveryRule,+ createResponsesItemIdPrefixRecoveryRule,createToolExchangeAdjacencyRecoveryRule,compactOversizedImageHistory,createToolUseProviderSpecificFieldsRecoveryRule,@@ -59,6 +60,7 @@ export {stripEncryptedContentFromBody,stripImageGenerationItemsWithoutIdFromBody,stripNonAnthropicFields,+ stripNonCanonicalResponsesItemIdsFromBody,stripToolUseProviderSpecificFields,stripToolUseProviderSpecificFieldsFromBody,} from './transform.js';diff --git a/packages/anthropic-compat-proxy/src/transform.test.ts b/packages/anthropic-compat-proxy/src/transform.test.tsindex 5289d127d0..e3e088288f 100644--- a/packages/anthropic-compat-proxy/src/transform.test.ts+++ b/packages/anthropic-compat-proxy/src/transform.test.ts@@ -23,6 +23,8 @@ import {stripEncryptedContentFromBody,stripImageGenerationItemsWithoutIdFromBody,stripNonAnthropicFields,+ stripNonCanonicalResponsesItemIdsFromBody,+ createResponsesItemIdPrefixRecoveryRule,stripToolUseProviderSpecificFields,stripToolUseProviderSpecificFieldsFromBody,} from './transform.js';@@ -502,6 +504,78 @@ describe('stripImageGenerationItemsWithoutIdFromBody', () => {});});+describe('stripNonCanonicalResponsesItemIdsFromBody (issue #4738)', () => {+ it('drops chat-completions style message ids and bare reasoning ids from input history, keeping canonical ids and tool pairing', () => {+ const body = buf({+ model: 'gpt-6-astra',+ input: [+ { type: 'message', role: 'user', content: 'hi' },+ { type: 'message', id: 'chatcmpl-abc123_msg_0', role: 'assistant', content: [{ type: 'output_text', text: 'gemini said' }] },+ { type: 'reasoning', id: '0d5f1c2e-bare-uuid', summary: [] },+ { type: 'message', id: 'msg_ok_1', role: 'assistant', content: [{ type: 'output_text', text: 'fine' }] },+ { type: 'reasoning', id: 'rs_ok_1', summary: [] },+ { type: 'function_call', id: 'fc_1', call_id: 'call_1', name: 'tool', arguments: '{}' },+ { type: 'function_call_output', call_id: 'call_1', output: 'ok' },+ ],+ });+ const out = stripNonCanonicalResponsesItemIdsFromBody(body);+ expect(out).not.toBeNull();+ const parsed = JSON.parse(out!.toString('utf8'));+ expect(parsed.input).toEqual([+ { type: 'message', role: 'user', content: 'hi' },+ { type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'gemini said' }] },+ { type: 'reasoning', summary: [] },+ { type: 'message', id: 'msg_ok_1', role: 'assistant', content: [{ type: 'output_text', text: 'fine' }] },+ { type: 'reasoning', id: 'rs_ok_1', summary: [] },+ { type: 'function_call', id: 'fc_1', call_id: 'call_1', name: 'tool', arguments: '{}' },+ { type: 'function_call_output', call_id: 'call_1', output: 'ok' },+ ]);+ });++ it('returns null when every history id is already canonical or absent, and for non-JSON', () => {+ expect(stripNonCanonicalResponsesItemIdsFromBody(buf({+ input: [+ { type: 'message', role: 'user', content: 'hi' },+ { type: 'message', id: 'msg_1', role: 'assistant', content: [] },+ { type: 'function_call', id: 'ctc_1', call_id: 'call_1', name: 't', arguments: '{}' },+ ],+ }))).toBeNull();+ expect(stripNonCanonicalResponsesItemIdsFromBody(Buffer.from('not json', 'utf8'))).toBeNull();+ });++ it('does not touch ids outside the top-level Responses input array (tools / metadata / nested input payloads)', () => {+ expect(stripNonCanonicalResponsesItemIdsFromBody(buf({+ tools: [{ type: 'function', name: 'x', id: 'chatcmpl-not-input' }],+ metadata: { type: 'message', id: 'chatcmpl-meta' },+ input: [{ type: 'message', role: 'user', content: 'hi' }],+ }))).toBeNull();+ // 嵌套同名 input 数组是业务 payload, 里面的 {type:'message', id} 不是协议历史 item+ const nested = {+ input: [+ { type: 'message', role: 'user', content: 'hi' },+ {+ type: 'function_call_output',+ call_id: 'call_1',+ output: JSON.stringify({ input: [{ type: 'message', id: 'business-id' }] }),+ },+ { type: 'message', id: 'msg_ok', role: 'assistant', content: [] },+ ],+ metadata: { input: [{ type: 'message', id: 'business-id-2' }] },+ };+ expect(stripNonCanonicalResponsesItemIdsFromBody(buf(nested))).toBeNull();+ // 顶层 input 命中时, 嵌套 payload 里的业务 id 仍原样保留+ const out = stripNonCanonicalResponsesItemIdsFromBody(buf({+ ...nested,+ input: [...nested.input, { type: 'message', id: 'chatcmpl-x_msg_0', role: 'assistant', content: [] }],+ }));+ expect(out).not.toBeNull();+ const parsed = JSON.parse(out!.toString('utf8'));+ expect(parsed.metadata).toEqual({ input: [{ type: 'message', id: 'business-id-2' }] });+ expect(parsed.input[1].output).toContain('business-id');+ expect(parsed.input[3]).toEqual({ type: 'message', role: 'assistant', content: [] });+ });+});+describe('stripEmptyThinkingFromBody', () => {it('removes an empty-content thinking block, keeping the sibling text', () => {const body = buf({@@ -989,6 +1063,22 @@ describe('recovery rule factories', () => {expect(rule.strip(buf({ input: [{ encrypted_content: 'x' }] }))).not.toBeNull();});+ it('responses item id prefix rule matches the OpenAI msg/rs prefix error only and strips non-canonical ids (issue #4738)', () => {+ const rule = createResponsesItemIdPrefixRecoveryRule();+ expect(rule.id).toBe('responses_item_id_prefix');+ expect(rule.enabled()).toBe(true);+ // 2026-09-20 实测原文(Codex 上游 400, invalid_request_error / invalid_value)+ expect(rule.matches("Invalid 'input[290].id': 'chatcmpl-8f2a1c_msg_0'. Expected an ID that begins with 'msg'.")).toBe(true);+ expect(rule.matches(JSON.stringify({ error: { message: "Invalid 'input[3].id': 'b1c2d3-uuid'. Expected an ID that begins with 'rs'.", type: 'invalid_request_error', code: 'invalid_value' } }))).toBe(true);+ // 工具 id 方言错配由 codex-proxy-host 的 tool_item_id 路径处理, 本规则不接管+ expect(rule.matches("Invalid 'input[5].id': 'fc_123'. Expected an ID that begins with 'ctc'.")).toBe(false);+ // 带工具前缀的 id 被要求 msg: 是工具项类型方言错配, 删 id 无用, 不接管+ expect(rule.matches("Invalid 'input[2].id': 'fc_old'. Expected an ID that begins with 'msg'.")).toBe(false);+ expect(rule.matches('invalid_encrypted_content')).toBe(false);+ expect(rule.strip(buf({ input: [{ type: 'message', id: 'chatcmpl-x_msg_0', role: 'assistant', content: [] }] }))).not.toBeNull();+ expect(rule.strip(buf({ input: [{ type: 'message', id: 'msg_x', role: 'assistant', content: [] }] }))).toBeNull();+ });+it('empty-thinking rule matches only its error text, is always-on by default, and strips empty thinking', () => {const rule = createEmptyThinkingRecoveryRule();expect(rule.id).toBe('empty_thinking');diff --git a/packages/anthropic-compat-proxy/src/transform.ts b/packages/anthropic-compat-proxy/src/transform.tsindex 5d8f1f188d..71b91ab5fc 100644--- a/packages/anthropic-compat-proxy/src/transform.ts+++ b/packages/anthropic-compat-proxy/src/transform.ts@@ -2,6 +2,8 @@export {createVllmResponsesCompatibilityRule,stripToolUseProviderSpecificFieldsFromBody,+ stripNonCanonicalResponsesItemIdsFromBody,+ createResponsesItemIdPrefixRecoveryRule,stripToolUseProviderSpecificFields,stripEncryptedContentFromBody,stripImageGenerationItemsWithoutIdFromBody,diff --git a/packages/model-compat/src/cindy/proxy/transform.ts b/packages/model-compat/src/cindy/proxy/transform.tsindex 11c083199e..056ac8f02d 100644--- a/packages/model-compat/src/cindy/proxy/transform.ts+++ b/packages/model-compat/src/cindy/proxy/transform.ts@@ -327,6 +327,71 @@ export function stripImageGenerationItemsWithoutIdFromBody(rawBody: Buffer): Buf}}+/**+ * Responses 历史 item 的规范 id 前缀。OpenAI Responses 会校验 `input[n].id`:+ * message 必须 `msg_`、reasoning 必须 `rs_`(function_call 系列另有 fc/ctc 方言校正, 不在此处)。+ */+const RESPONSES_ITEM_ID_PREFIXES: Readonly<Record<'message' | 'reasoning', string>> = {+ message: 'msg_',+ reasoning: 'rs_',+};++function nonCanonicalResponsesItemType(item: unknown): 'message' | 'reasoning' | null {+ if (!isPlainObject(item)) return null;+ const type = item.type;+ if (type !== 'message' && type !== 'reasoning') return null;+ const id = item.id;+ if (typeof id !== 'string' || id.length === 0) return null;+ return id.startsWith(RESPONSES_ITEM_ID_PREFIXES[type]) ? null : type;+}++/**+ * 只清洗顶层 `body.input`(Responses 协议历史容器)。嵌套的同名 `input` 数组(消息+ * payload / 工具参数 / 扩展字段)是不透明业务数据, 其中的 `{type:'message', id}` 不是+ * 协议 item, 不能被当成历史清洗(Greptile P2)。+ */+function deleteNonCanonicalResponsesInputIds(body: unknown): number {+ if (!isPlainObject(body) || !Array.isArray(body.input)) return 0;+ let removed = 0;+ for (const item of body.input) {+ if (nonCanonicalResponsesItemType(item) !== null) {+ delete (item as Record<string, unknown>).id;+ removed += 1;+ }+ }+ return removed;+}++/**+ * 剔除 Responses 请求体 input 历史里前缀不合规的 message / reasoning item `id`。+ *+ * 背景(issue #4738): 同一会话先用 Gemini(chat-completions 上游, 由代理合成+ * `chatcmpl-…_msg_0` 这类 id)再切到 openai-api 的 GPT 模型, Codex 把历史按原 id 回放,+ * OpenAI Responses 直接 400:+ * "Invalid 'input[290].id': 'chatcmpl-…_msg_0'. Expected an ID that begins with 'msg'."+ * 之后每次发送都被同一条历史拦住, 旧会话永久不可用。+ *+ * 历史 message / reasoning item 的 id 对继续对话没有配对语义(Responses 接受不带 id 的+ * 输入 item), 因此直接删掉不合规 id 而不是改写 —— 改写成 `msg_` 前缀仍可能撞上上游对+ * 未知 id 的校验。function_call / function_call_output 的 id 与 call_id 配对一律不动。+ * 只扫顶层 `body.input` 数组, 已是 `msg_` / `rs_` 前缀的不改; 没有可改的返回 null。+ */+export function stripNonCanonicalResponsesItemIdsFromBody(rawBody: Buffer): Buffer | null {+ let parsed: unknown;+ try {+ parsed = JSON.parse(rawBody.toString('utf8'));+ } catch {+ return null;+ }+ const removed = deleteNonCanonicalResponsesInputIds(parsed);+ if (removed === 0) return null;+ try {+ return Buffer.from(JSON.stringify(parsed), 'utf8');+ } catch {+ return null;+ }+}+/** thinking 块的 `thinking` 字段是否为空(空串 / 缺失 / 非字符串都算空)。 */function isEmptyThinkingBlock(block: unknown): boolean {if (!isPlainObject(block)) return false;@@ -1459,6 +1524,14 @@ const EMPTY_TEXT_RE = /text content blocks must (?:be non-empty|contain non-whit// 只匹配不变的 role + 校验短语,不锚定会变的 position 数字。const EMPTY_ASSISTANT_MESSAGE_RE = /with role 'assistant' must not be empty/i;+// OpenAI Responses 400(issue #4738, 2026-09-20 实测):+// "Invalid 'input[290].id': 'chatcmpl-…_msg_0'. Expected an ID that begins with 'msg'."+// 只匹配 message(msg)/reasoning(rs) 的前缀校验; fc/fco/ctc/ctco 工具 id 方言由+// codex-proxy-host 的 isRepairableToolItemIdError 单独处理, 不在此规则内; 被拒 id 本身带+// 工具前缀(fc/fco/ctc/ctco)时同样不接管 —— 那是工具项被当成 message 的方言错配, 删 id 无用。+const RESPONSES_ITEM_ID_PREFIX_RE =+ /Invalid\s+\\?["']input\[\d+\]\.id\\?["']:\s*\\?["'](?!(?:fc|fco|ctc|ctco)_)[^"'\\]+\\?["']\.?\s+Expected an ID that begins with \\?["'](?:msg|rs)\\?["']/i;+// Azure/LiteLLM 400: "Image generation items without `id` are not supported for this request."const IMAGE_GENERATION_WITHOUT_ID_RE =/image generation items without [`']?id[`']? are not supported/i;@@ -1540,6 +1613,25 @@ export function createImageGenerationIdRecoveryRule(opts: {};}+/**+ * Responses 历史 item id 前缀校验 400 恢复规则(issue #4738): 剔除不合规的+ * message / reasoning item id 后重发。默认 always-on; 只在明确命中上游错误时触发。+ */+export function createResponsesItemIdPrefixRecoveryRule(opts: {+ enabled?: () => boolean;+ onRetry?: (threadId: string, model: string) => void;+ threadIdHeaders?: readonly string[];+} = {}): RecoveryRule {+ return {+ id: 'responses_item_id_prefix',+ enabled: opts.enabled ?? (() => true),+ matches: (text) => RESPONSES_ITEM_ID_PREFIX_RE.test(text),+ strip: stripNonCanonicalResponsesItemIdsFromBody,+ onRetry: opts.onRetry,+ threadIdHeaders: opts.threadIdHeaders,+ };+}+/*** `tool_use.provider_specific_fields` 400 恢复规则:清理历史后透明重试一次。* 主动 transform 通常会先移除该字段;该规则覆盖 transform 未接入、旧会话