fix: primeFold retries with demoted inline-think mirror (issue #64) - #124
Merged
Conversation
On glm/deepseek/qwen-style openai-completions profiles the host demotes unsigned thinking to text and serializes it INLINE as <think>...</think> inside the content string (no reasoning_content field). The primeFold mirror emitted reasoning pieces instead, landing the span fingerprints in a different space: every in-stream compress replay was rejected after restart and /acp showed 'Blocks: none' until the first provider request refolded. - viewToCoreStream: new opts.demoteThinking variant rebuilding the assistant content byte-exactly (tag + \n glue + text, ref tags stripped), no reasoning_content field - runtime primeFold: when the openai mirror yields zero blocks but the view contains compress calls, refold once with the demoted variant - tests: byte-exact unit test + provider-mode restart regression (verified: disabling the retry fails the new test)
This was referenced Aug 22, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #122 (issue #64, responses variant). Verified on a real glm-5.3 session: restart still showed
Blocks: noneuntil the first provider request.Root cause (this variant): on glm/deepseek/qwen-style openai-completions profiles the host demotes unsigned thinking to text (
transform-messages→renderDemotedThinking) and serializes it INLINE as a<think>…</think>tag inside thecontentstring — there is noreasoning_contentfield. The primeFold mirror (viewToCoreStream) emitted reasoning pieces instead, splitting each thinking turn into reasoning+text while the live wire carried one text piece. The span fingerprints landed in different spaces, every in-stream compress replay was rejected (fold-replay-stale reason=fp), and the blocks only re-materialized at the first provider request.Reconstruction rule verified byte-exact against a real wire dump (94/94 assistant messages match, dump
req_7080.json, 208 msgs):Fix
viewToCoreStream: newopts.demoteThinkingvariant that rebuilds assistant content byte-exactly per the rule above (noreasoning_content); default path unchanged.runtime.ts primeFold: when the openai mirror yields zero blocks but the view contains compress calls, refold once with the demoted variant (previewmakes the retry a fresh-slot full refold).Tests
wire-transform.test.ts: byte-exact unit test for the demoted serialization (multi-block glue, text-only, whitespace-only-drop, default variant unchanged).prime-provider-restart.test.ts: provider-mode restart regression with a glm-style wire (inline think tags, noreasoning_content) — block must be rebuilt before the first provider request. Verified the test guards the fix: disabling the retry fails exactly this test.Full suite: 260 pass / 0 fail;
tsc --noEmitclean.