You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2157677
Browse filesBrowse the repository at this point in the historyBrowse files
authored
[Fix] DeepSeek/OpenAI requests fail permanently when task history contains a lone UTF-16 surrogate (Zoo-Code-Org#1831)
* fix(api): sanitize lone UTF-16 surrogates in OpenAI-chat request bodies
DeepSeek rejects the entire request body when any string contains a lone
UTF-16 surrogate (e.g. after history text was sliced through an
astral-plane character), permanently breaking the affected task. Apply
the same sanitization pattern PR Zoo-Code-Org#1605 added for the VS Code LM provider
to the shared OpenAI-chat transforms, covering the DeepSeek and OpenAI
providers (and other providers on the same shared path):
- Move sanitizeSurrogates/sanitizeIdentifierSurrogates/
sanitizeSurrogatesDeep into a shared transform module; vscode-lm-format
re-exports them.
- convertToOpenAiMessages/convertToR1Format: sanitize message text,
tool_result content, tool_use ids (injective, composed with
normalizeToolCallId so call/result pairing survives), tool names,
nested tool argument strings, and reasoning_content.
- OpenAiHandler: sanitize the system/developer prompt.
- BaseProvider.convertToolsForOpenAI: sanitize tool definition
name/description/parameters.
completePrompt is intentionally out of scope, matching Zoo-Code-Org#1605.
FixesZoo-Code-Org#461
* test(api): make lone-surrogate body assertions effective and close coverage gaps
JSON.stringify escapes lone surrogates as \udXXX text, so the copied
regex-over-serialized-body assertions could never fail. Replace them with a
shared expectNoLoneSurrogates helper that walks raw values recursively and
fails on any unpaired UTF-16 surrogate (ES2022-safe, no isWellFormed).
Also close the coverage gaps from review:
- OpenAiHandler: cache_control system block with prompt caching, non-streaming
system prompt, and both o3 developer-message paths, with exact sanitized text.
- convertToR1Format: assistant string sanitization, assistant string merge,
and user string merge into the previous user message.
- convertToOpenAiMessages: text merged into the last tool message after
tool_result blocks, and reasoning_content on the array-content assistant path.
- convertToolsForOpenAI: mcp__srv__tool name with a lone surrogate nested in
parameters, still sanitized while strict stays false.
- normalizeToolCallId composition tests now use a lowercase normalizer, so
swapping the sanitize/normalize order makes them fail.
Ref Zoo-Code-Org#461
* test(api): cover surrogate sanitization of reasoning block extraction
---------
Co-authored-by: Roomote <[email protected]>
Co-authored-by: Elliott de Launay <[email protected]>
0 commit comments