Skip to content

fix(server): sanitize reasoning content in v1 compact endpoint#248

Merged
lidge-jun merged 1 commit into
lidge-jun:devfrom
Wibias:codex/fix-compact-reasoning-sanitizer
Jul 22, 2026
Merged

fix(server): sanitize reasoning content in v1 compact endpoint#248
lidge-jun merged 1 commit into
lidge-jun:devfrom
Wibias:codex/fix-compact-reasoning-sanitizer

Conversation

@Wibias

@Wibias Wibias commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Issue #234: Threads mixing routed models (Kimi) with native OpenAI models permanently brick when remote compaction triggers. The error is 400 array_above_max_length on input[201].content.

Root cause

The bridge emits reasoning items with content: [{ type: "reasoning_text", text: ... }] for routed models. The regular /v1/responses path applies sanitizeReasoningInputContent via the adapter's buildRequest, which strips this non-standard content before forwarding to OpenAI.

But the /v1/responses/compact endpoint (v1 remote compaction) forwarded the request body verbatim, bypassing the sanitizer entirely. When Codex tried to compact a thread containing routed-model reasoning items, OpenAI rejected it because it expects reasoning items to have empty content arrays.

Fix

Export sanitizeReasoningInputContent from src/adapters/openai-responses.ts and apply it to the compact body in src/server/responses.ts before forwarding, matching the regular /v1/responses path behavior.

Impact

This fixes both new threads going forward and already-bricked threads, since the sanitizer runs on every compact request. No bridge changes needed.

Verification

  • bun x tsc --noEmit passes
  • The fix is a 7-line change across 2 files

The /v1/responses/compact handler forwarded the request body verbatim to
the ChatGPT backend, bypassing the adapter's buildRequest which applies
sanitizeReasoningInputContent. Routed-model reasoning items with
content: [{type: 'reasoning_text', ...}] caused 400 array_above_max_length
errors during remote compaction, permanently bricking threads that mixed
routed and native models.

Export sanitizeReasoningInputContent from the openai-responses adapter
and apply it to the compact body before forwarding, matching the regular
/v1/responses path behavior.
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.

2 participants