8000 fix(codex): replay only reasoning items the backend issued by ChrAlpha · Pull Request #138 · felinics/twilight · GitHub
[go: up one dir, main page]

Skip to content

fix(codex): replay only reasoning items the backend issued - #138

Draft
ChrAlpha wants to merge 1 commit into
felinics:mainfrom
ChrAlpha:fix/reasoning-replay-provenance
Draft

ChrAlpha wants to merge 1 commit into
felinics:mainfrom
ChrAlpha:fix/reasoning-replay-provenance

Conversation

@ChrAlpha
Copy link
Copy Markdown
Member

Author

Agent

Type

  • bug
  • feat
  • test

Description

Codex 后端与公开 Responses API 共用 reasoning dialect,但它只接受自己签发的 rs_ item id。会话先经 Responses 兼容的 relay(如经 relay 的 DeepSeek)产生 reasoning,再切到 Codex 时,converter 会把 relay 的 item id(UUID,来自 metadata,或回退到 block id)原样回放,后端对之后的每个请求都返回:

400 invalid_request_error invalid_value: Invalid 'input[1].id': '<uuid>'. Expected an ID that begins with 'rs'.

Memoh 生产 2026-10-28 共 53 个 run 因此失败,其中一个 session 连续失败 44 次(Linear TWI-21 / MEMOH-246)。

现在 Codex converter 解析出的 item id 不以 rs_ 开头时,丢弃整个 reasoning item,包括 summary 和 encrypted content;同一消息中由后端签发的 item 照常回放、合并。通用 Responses converter 不加这项校验:它可能连的是 relay,把 relay 自己的 id 回放给同一个 relay 是合法的。

调查后没有在 Responses/Codex 加 SameReasoningModel 守卫:ReasoningPart.Model 记录的是响应报告的模型名,relay 会把它改写成渠道的真实上游模型名,OpenAI 也会返回带日期的快照名,与请求的模型名比较会让同一模型每一步都丢掉 reasoning。模型与端点的归属由调用方用自己的稳定身份判断(Memoh 侧另行修复)。

Verification

  • mise run ci:build、vet、lint(0 issues)和完整 short test suite 通过。
  • 新增 provider/openai/codex/reasoning_replay_test.go:已签发 item 合并回放并保留 encrypted content;relay 的 UUID(在 metadata 中、或仅作为 block id)和空 id 被跳过且 assistant 文本照常发送;同一消息中外来 item 与已签发 item 并存时只回放后者。不含本修复时这些用例失败。
  • 未用真实 Codex 账号验证。Memoh 的 Codex 客户端不接受自定义 base URL,本地开发栈虽以 module replacement 加载了本分支,但其 UI 验证走 openai-responses 客户端,未经过 Codex converter。

The Codex backend shares the Responses reasoning dialect with every
compatible endpoint, but it accepts only the rs_ item ids it issued. A
conversation that switched to Codex from a relay replayed the relay's own
item ids (UUIDs, from metadata or the block id fallback), and the backend
rejected every following request with "Expected an ID that begins with
'rs'". Such items are now dropped, summary and encrypted content with
them, while issued items still replay.

Linear: TWI-21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0