GeezerVison is showing github.com — polish deepseek responses repair review details · lidge-jun/opencodex@eea5e3b
File treeExpand file treeCollapse file tree Open diff view settings docs-site/src/content/docs ja/reference/configuration ko/reference/configuration ru/reference/configuration
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs-site/src/content/docs/ja/reference/configuration/providers.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -205,7 +205,7 @@ Anthropic アカウント ポリシーのリスクを理解していない限り | 205 | 205 | } | 206 | 206 | ``` | 207 | 207 |
| 208 | | -プレースホルダー リストは完全に一致します。通常/ステートフル応答プロバイダーのフィールドを未設定のままにして、パススルーがバイトごとに同一になるようにします。 | | 208 | +プレースホルダー リストは完全に一致します。DeepSeek Responses のように UUID 形式の response/item ID と生の `reasoning_text` ストリームを返すゲートウェイでは `rewriteNonCanonicalIds` を有効にします。OpenCodex はそれらの ID を Codex 向けプレフィックスへ書き換え、reasoning を `encrypted_content` に正規化しつつ replay 用の平文 `content` を保持し、終端の `[DONE]` を補完します。通常/ステートフルな Responses プロバイダーではこのフィールドを未設定のままにして、パススルーがバイト単位で同一になるようにします。 | 209 | 209 |
| 210 | 210 | ## Cursor プロバイダー (`adapter: "cursor"`) | 211 | 211 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs-site/src/content/docs/ko/reference/configuration/providers.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -208,7 +208,7 @@ Anthropic 계정 정책 위험을 이해하지 못한다면 이 기능은 꺼두 | 208 | 208 | } | 209 | 209 | ``` | 210 | 210 |
| 211 | | -자리표시자 목록은 정확히 일치해야 합니다. 일반적인 상태 유지형 Responses 공급자에서는 필드를 설정하지 마십시오. 그래야 passthrough가 바이트 단위로 동일하게 유지됩니다. | | 211 | +자리표시자 목록은 정확히 일치해야 합니다. DeepSeek Responses처럼 UUID 형식 response/item id와 원본 `reasoning_text` 스트림을 반환하는 게이트웨이에서는 `rewriteNonCanonicalIds`를 켜십시오. OpenCodex는 해당 id를 Codex 친화적 prefix로 다시 쓰고, reasoning을 `encrypted_content`로 정규화하면서 replay용 평문 `content`는 유지하며, 종료용 `[DONE]`을 보장합니다. 일반/상태 유지형 Responses 공급자에서는 필드를 설정하지 마십시오. 그래야 passthrough가 바이트 단위로 동일하게 유지됩니다. | 212 | 212 |
| 213 | 213 | ## Cursor 공급자 (`adapter: "cursor"`) | 214 | 214 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs-site/src/content/docs/ru/reference/configuration/providers.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -253,7 +253,7 @@ Beijing, а `alibaba-token-plan-intl` обслуживает междунаро | 253 | 253 | } | 254 | 254 | ``` | 255 | 255 |
| 256 | | -Списки placeholder'ов сравниваются по exact-match. Для обычных/stateful Responses-провайдеров это | | 256 | +Списки placeholder'ов сравниваются по exact-match. Для gateway вроде DeepSeek Responses, которые отдают UUID-style response/item id и сырые `reasoning_text` потоки, включайте `rewriteNonCanonicalIds`: OpenCodex переписывает id в Codex-friendly prefix, нормализует reasoning в `encrypted_content` (сохраняя plaintext `content` для replay) и гарантирует terminal `[DONE]`. Для обычных/stateful Responses-провайдеров это | 257 | 257 | поле оставляйте unset, чтобы passthrough оставался byte-for-byte идентичным. | 258 | 258 |
| 259 | 259 | ## Провайдер Cursor (`adapter: "cursor"`) | |
Collapse file Copy file name to clipboardExpand all lines: src/providers/derive.ts +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -269,7 +269,14 @@ export function enrichProviderFromRegistry(name: string, prov: OcxProviderConfig | 269 | 269 | // the entry so an explicit user value stays distinguishable from the default. | 270 | 270 | if (prov.supportsServiceTier === undefined && entry.supportsServiceTier !== undefined) prov.supportsServiceTier = entry.supportsServiceTier; | 271 | 271 | if (prov.preserveResponsesReasoningContent === undefined && entry.preserveResponsesReasoningContent !== undefined) prov.preserveResponsesReasoningContent = entry.preserveResponsesReasoningContent; | 272 | | - if (prov.responsesItemIdRepair === undefined && entry.responsesItemIdRepair !== undefined) prov.responsesItemIdRepair = { ...entry.responsesItemIdRepair }; | | 272 | + if (prov.responsesItemIdRepair === undefined && entry.responsesItemIdRepair !== undefined) { | | 273 | + const repair = entry.responsesItemIdRepair; | | 274 | + prov.responsesItemIdRepair = { | | 275 | + ...repair, | | 276 | + ...(repair.message ? { message: [...repair.message] } : {}), | | 277 | + ...(repair.reasoning ? { reasoning: [...repair.reasoning] } : {}), | | 278 | + }; | | 279 | + } | 273 | 280 | if (!prov.autoToolChoiceOnlyModels && seed.autoToolChoiceOnlyModels) prov.autoToolChoiceOnlyModels = [...seed.autoToolChoiceOnlyModels]; | 274 | 281 | if (!prov.preserveReasoningContentModels && seed.preserveReasoningContentModels) prov.preserveReasoningContentModels = [...seed.preserveReasoningContentModels]; | 275 | 282 | if (!prov.reasoningSplitModels && seed.reasoningSplitModels) prov.reasoningSplitModels = [...seed.reasoningSplitModels]; | |
Collapse file Copy file name to clipboardExpand all lines: src/server/responses-item-id-repair.ts +57-7Lines changed: 57 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -235,11 +235,12 @@ function normalizeReasoningItem( | 235 | 235 | // Snapshot content-derived text into the budgeted map only when we still need it later. | 236 | 236 | if (!terminal) setReasoningText(state, outputIndex, text); | 237 | 237 | } | 238 | | - const next: Record<string, unknown> = { | 239 | | - type: "reasoning", | 240 | | - id: mapped, | 241 | | - summary: Array.isArray(item.summary) ? item.summary : [], | 242 | | - }; | | 238 | + // Preserve upstream metadata such as status; only proxy-owned reasoning fields are rebuilt. | | 239 | + const next: Record<string, unknown> = { ...item, type: "reasoning" }; | | 240 | + if (mapped !== undefined) next.id = mapped; | | 241 | + next.summary = Array.isArray(item.summary) ? item.summary : []; | | 242 | + delete next.content; | | 243 | + delete next.encrypted_content; | 243 | 244 | if (terminal || text) { | 244 | 245 | // Codex consumes encrypted_content; DeepSeek tool-call continuations need plaintext | 245 | 246 | // reasoning_text after sanitizeReasoningInputContent strips the proxy-only ocxr1 envelope. | @@ -337,6 +338,44 @@ function rewriteItemIdField( | 337 | 338 | return { event: next, changed: true }; | 338 | 339 | } | 339 | 340 |
| | 341 | +function flushRetainedReasoningIntoResponse( | | 342 | + state: ResponsesItemIdRepairState, | | 343 | + response: Record<string, unknown>, | | 344 | +): { response: Record<string, unknown>; changed: boolean } { | | 345 | + if (!state.rewriteNonCanonicalIds || state.reasoningTextByOutputIndex.size === 0) { | | 346 | + return { response, changed: false }; | | 347 | + } | | 348 | + const output = Array.isArray(response.output) ? [...response.output] : []; | | 349 | + let changed = false; | | 350 | + for (const [outputIndex, text] of [...state.reasoningTextByOutputIndex.entries()]) { | | 351 | + if (!text) { | | 352 | + releaseReasoningText(state, outputIndex); | | 353 | + continue; | | 354 | + } | | 355 | + const existing = isPlainObject(output[outputIndex]) ? output[outputIndex] as Record<string, unknown> : null; | | 356 | + if (existing?.type === "reasoning") { | | 357 | + const rewritten = normalizeReasoningItem(state, outputIndex, existing, true); | | 358 | + output[outputIndex] = rewritten; | | 359 | + changed = true; | | 360 | + continue; | | 361 | + } | | 362 | + // No reasoning item was emitted for this retained stream; synthesize one so the | | 363 | + // terminal snapshot still carries the accumulated reasoning text. | | 364 | + const synthetic = normalizeReasoningItem(state, outputIndex, { | | 365 | + type: "reasoning", | | 366 | + summary: [], | | 367 | + content: [{ type: "reasoning_text", text }], | | 368 | + }, true); | | 369 | + if (outputIndex < output.length) output[outputIndex] = synthetic; | | 370 | + else { | | 371 | + while (output.length < outputIndex) output.push({ type: "message", role: "assistant", content: [] }); | | 372 | + output.push(synthetic); | | 373 | + } | | 374 | + changed = true; | | 375 | + } | | 376 | + return changed ? { response: { ...response, output }, changed: true } : { response, changed: false }; | | 377 | +} | | 378 | + | 340 | 379 | function rewriteResponseSnapshot( | 341 | 380 | state: ResponsesItemIdRepairState, | 342 | 381 | response: Record<string, unknown>, | @@ -425,11 +464,22 @@ function repairEventPayload( | 425 | 464 | } | 426 | 465 | } | 427 | 466 | if (isPlainObject(event.response)) { | 428 | | - const rewritten = rewriteResponseSnapshot(state, event.response); | 429 | | - if (rewritten.changed) { | | 467 | + let response = event.response; | | 468 | + if (type && TERMINAL_RESPONSE_TYPES.has(type) && state.rewriteNonCanonicalIds) { | | 469 | + const flushed = flushRetainedReasoningIntoResponse(state, response); | | 470 | + response = flushed.response; | | 471 | + changed = changed || flushed.changed; | | 472 | + } | | 473 | + const rewritten = rewriteResponseSnapshot(state, response); | | 474 | + if (rewritten.changed || response !== event.response) { | 430 | 475 | nextEvent = { ...nextEvent, response: rewritten.response }; | 431 | 476 | changed = true; | 432 | 477 | } | | 478 | + } else if (type && TERMINAL_RESPONSE_TYPES.has(type) && state.rewriteNonCanonicalIds && state.reasoningTextByOutputIndex.size > 0) { | | 479 | + // Terminal events without a response snapshot still need retained reasoning released. | | 480 | + for (const outputIndex of [...state.reasoningTextByOutputIndex.keys()]) { | | 481 | + releaseReasoningText(state, outputIndex); | | 482 | + } | 433 | 483 | } | 434 | 484 |
| 435 | 485 | if (type && TERMINAL_RESPONSE_TYPES.has(type)) state.sawTerminal = true; | |
Collapse file Copy file name to clipboardExpand all lines: src/server/responses/core.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1646,6 +1646,9 @@ async function handleResponsesInner( | 1646 | 1646 | // When item-id repair rewrites response ids, the inspector still sees the raw | 1647 | 1647 | // upstream UUID while Codex chains previous_response_id with the client-visible | 1648 | 1648 | // resp_ocx_* id. Alias both keys into the local continuation cache. | | 1649 | + // mapClientResponseId is assigned only on the SSE rewrite path below. The JSON | | 1650 | + // response path currently does not apply Responses item-id repair; if JSON repair | | 1651 | + // is added later, initialize this alias before that branch records continuation state. | 1649 | 1652 | let mapClientResponseId: ((rawId: string | undefined) => string | undefined) | undefined; | 1650 | 1653 | const rememberPassthroughResponse = passthroughRecordEligible | 1651 | 1654 | ? (response: { id?: unknown; output?: unknown; status?: unknown }) => { | |
Collapse file Copy file name to clipboardExpand all lines: tests/responses-item-id-repair-deepseek.test.ts +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -187,6 +187,41 @@ describe("DeepSeek Responses item-id repair", () => { | 187 | 187 | expect(repaired.match(/data: \[DONE\]/g)).toHaveLength(1); | 188 | 188 | }); | 189 | 189 |
| | 190 | + test("preserves reasoning status metadata", async () => { | | 191 | + const upstream = [ | | 192 | + `event: response.output_item.added\ndata: {"type":"response.output_item.added","output_index":0,"item":{"type":"reasoning","id":"8da7b778-aff2-4d83-bfc3-8cd09ee79b34","status":"in_progress","summary":[]}}\n\n`, | | 193 | + `event: response.reasoning_text.delta\ndata: {"type":"response.reasoning_text.delta","output_index":0,"item_id":"8da7b778-aff2-4d83-bfc3-8cd09ee79b34","delta":"think"}\n\n`, | | 194 | + `event: response.output_item.done\ndata: {"type":"response.output_item.done","output_index":0,"item":{"type":"reasoning","id":"8da7b778-aff2-4d83-bfc3-8cd09ee79b34","status":"completed","summary":[]}}\n\n`, | | 195 | + `event: response.completed\ndata: {"type":"response.completed","response":{"id":"58786d76-18be-43d9-b6f5-8922796fbe28","status":"completed","output":[{"type":"reasoning","id":"8da7b778-aff2-4d83-bfc3-8cd09ee79b34","status":"completed","summary":[]}]}}\n\n`, | | 196 | + ].join(""); | | 197 | + const events = await parseSse(await readAll(relaySseWithResponsesItemIdRepair(streamFromText(upstream), { | | 198 | + rewriteNonCanonicalIds: true, | | 199 | + }))); | | 200 | + const added = events.find(e => e.type === "response.output_item.added")!.item as Record<string, unknown>; | | 201 | + const done = events.find(e => e.type === "response.output_item.done")!.item as Record<string, unknown>; | | 202 | + const completed = events.find(e => e.type === "response.completed")!.response as { output: Record<string, unknown>[] }; | | 203 | + expect(added.status).toBe("in_progress"); | | 204 | + expect(done.status).toBe("completed"); | | 205 | + expect(completed.output[0].status).toBe("completed"); | | 206 | + expect(String(done.encrypted_content)).toMatch(/^ocxr1:/); | | 207 | + }); | | 208 | + | | 209 | + test("flushes retained reasoning text into terminal snapshot when item.done is missing", async () => { | | 210 | + const upstream = [ | | 211 | + `event: response.output_item.added\ndata: {"type":"response.output_item.added","output_index":0,"item":{"type":"reasoning","id":"8da7b778-aff2-4d83-bfc3-8cd09ee79b34","status":"in_progress","summary":[]}}\n\n`, | | 212 | + `event: response.reasoning_text.delta\ndata: {"type":"response.reasoning_text.delta","output_index":0,"item_id":"8da7b778-aff2-4d83-bfc3-8cd09ee79b34","delta":"orphan"}\n\n`, | | 213 | + `event: response.completed\ndata: {"type":"response.completed","response":{"id":"58786d76-18be-43d9-b6f5-8922796fbe28","status":"completed","output":[]}}\n\n`, | | 214 | + ].join(""); | | 215 | + const events = await parseSse(await readAll(relaySseWithResponsesItemIdRepair(streamFromText(upstream), { | | 216 | + rewriteNonCanonicalIds: true, | | 217 | + }))); | | 218 | + const completed = events.find(e => e.type === "response.completed")!.response as { output: Record<string, unknown>[] }; | | 219 | + expect(completed.output).toHaveLength(1); | | 220 | + expect(completed.output[0].type).toBe("reasoning"); | | 221 | + expect(String(completed.output[0].encrypted_content)).toMatch(/^ocxr1:/); | | 222 | + expect((completed.output[0].content as Array<{ text: string }>)[0].text).toBe("orphan"); | | 223 | + }); | | 224 | + | 190 | 225 | test("keeps shared placeholder aliases type-scoped", async () => { | 191 | 226 | const upstream = [ | 192 | 227 | 'event: response.output_item.added\ndata: {"type":"response.output_item.added","output_index":0,"item":{"type":"reasoning","id":"shared_placeholder"}}\n\n', | |
Collapse file Copy file name to clipboardExpand all lines: tests/sse-payload-rewrite.test.ts +8-5Lines changed: 8 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | */ | 4 | 4 | import { describe, expect, test } from "bun:test"; | 5 | 5 | import { createImageGenCallRestoreRewrite } from "../src/server/responses-image-gen-repair"; | 6 | | -import { createResponsesItemIdPayloadRewrite } from "../src/server/responses-item-id-repair"; | | 6 | +import { createResponsesItemIdRepairHandlers } from "../src/server/responses-item-id-repair"; | 7 | 7 | import { | 8 | 8 | composeSsePayloadRewrites, | 9 | 9 | relaySseWithPayloadRewrite, | @@ -51,7 +51,7 @@ describe("SSE payload rewrite composition", () => { | 51 | 51 | const imageGen = createImageGenCallRestoreRewrite( | 52 | 52 | new Map([["image_gen__imagegen", { namespace: "image_gen", name: "imagegen" }]]), | 53 | 53 | )!; | 54 | | - const itemId = createResponsesItemIdPayloadRewrite({ | | 54 | + const itemId = createResponsesItemIdRepairHandlers({ | 55 | 55 | message: ["msg_0"], | 56 | 56 | repairMissingTerminalIds: true, | 57 | 57 | }); | @@ -63,13 +63,16 @@ describe("SSE payload rewrite composition", () => { | 63 | 63 | }, | 64 | 64 | (payload) => { | 65 | 65 | itemIdCalls += 1; | 66 | | - return itemId(payload); | | 66 | + return itemId.rewrite(payload); | 67 | 67 | }, | 68 | 68 | ); | 69 | 69 |
| 70 | 70 | const budget = createTestTranslatorBudget(); | 71 | | - const out = await readAll(relaySseWithPayloadRewrite(streamFromText(upstream), composed, budget)); | | 71 | + const out = await readAll(relaySseWithPayloadRewrite(streamFromText(upstream), composed, budget, { | | 72 | + trailer: itemId.trailer, | | 73 | + })); | 72 | 74 | budget.dispose(); | | 75 | + expect(out).toContain("data: [DONE]"); | 73 | 76 | expect(imageGenCalls).toBe(3); | 74 | 77 | expect(itemIdCalls).toBe(3); | 75 | 78 | expect(imageGenCalls).toBe(itemIdCalls); | @@ -78,7 +81,7 @@ describe("SSE payload rewrite composition", () => { | 78 | 81 | .trim() | 79 | 82 | .split(/\r?\n\r?\n/) | 80 | 83 | .map(block => block.split(/\r?\n/).find(line => line.startsWith("data:"))?.slice(5).trim()) | 81 | | - .filter((payload): payload is string => !!payload) | | 84 | + .filter((payload): payload is string => !!payload && payload !== "[DONE]") | 82 | 85 | .map(payload => JSON.parse(payload) as Record<string, unknown>); | 83 | 86 |
| 84 | 87 | const messageAdded = events[0].item as Record<string, unknown>; | |
|