AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

v0.3.6 / v0.3.7: Partial text continuation (partialContinuationPrompt / continuationPrefixStripper) causes truncated replies, degraded quality & leaked internal tokens compared to rock-solid v0.3.5

Open Madarchik09 opened this issue 2 weeks ago • 1 comments

Summary / 问题描述

First of all, thank you for your great work on AIStudio2API!

I use AIStudio2API heavily with OpenCode (intensive multi-step agentic coding sessions with tool calls).

  • On ** 0.3.5**, I worked for 24 hours straight non-stop without a single bug: responses were clean, complete, high-quality, and tool calls worked reliably.
  • Right after upgrading to ** 0.3.6** (and the exact same logic remains in ** 0.3.7**), responses started getting cut off / awkwardly stitched mid-stream, overall answer quality dropped noticeably, and strange internal delimiter characters (such as U+1290 U+1F4AD thought markers and duplicated text fragments) started leaking directly into the visible assistant text.
  • Rolling back to ** 0.3.5** immediately fixed everything — zero bugs again.

Root Cause Analysis in Code / 代码根因定位

Comparing 0.3.5 vs 0.3.6 / 0.3.7 in internal/aistudio/generate.go (introduced in PR #143 / commits d3c4801 and ef05bb0):

  1. In 0.3.5 (internal/aistudio/generate.go): egenerable(ctx, err, finish, committed) strictly required !committed. Once visible text had already been emitted to the client (committed == true), 0.3.5 never attempted to silently stitch a second generation on top of an already-streamed partial text response.

  2. In 0.3.6 and 0.3.7 (internal/aistudio/generate.go, lines 963–1014 & 1176–1310): When committed == true and committedTextOnly(output) is non-empty, the regeneration loop intercepts mid-stream failures (malformed_function_call, unexpected_tool_call, stream cutoffs) and silently sends a synthetic continuation request with:

    • RoleAssistant: emittedText
    • RoleUser: partialContinuationPrompt(emittedText, finish) (<partial_reply>...</partial_reply> Continue immediately right after <partial_reply> without repeating it...)
    • continuationPrefixStripper trying to strip repeated prefixes via exact string matching (strings.HasPrefix).
  3. Why this breaks output quality and leaks strange symbols:

    • In the hidden second round, the model starts from a synthetic <partial_reply> prompt, altering its internal reasoning/thinking state (Thought) and reasoning depth mid-turn.
    • Internal thought delimiter tokens (U+1290 U+1F4AD) or malformed partial chunks leak into EventText.
    • Whenever the model slightly rephrases even one word or punctuation mark of the prefix in the continuation round, continuationPrefixStripper fails exact prefix matching and flushes s.pending into the live stream, resulting in truncated/garbled sentences and degraded response quality.

Request / 建议

Could you please remove this mid-stream partial text continuation (partialContinuationPrompt + continuationPrefixStripper when committed == true) and restore the rock-solid ** 0.3.5 behavior (!committed)**, or at least make it disabled by default behind an optional config flag?


中文总结

非常感谢开发 AIStudio2API! 我在 OpenCode 中高强度使用本程序进行 Agent 工具调用:

  1. 在 ** 0.3.5** 版本下,我连续无休工作了 24 小时,没有任何一个 Bug,回答完整、质量极高,也没有任何乱码符号。
  2. 升级到 ** 0.3.6** 后(该逻辑在 ** 0.3.7** 中依然保留),回答经常出现被截断、拼接错位、回答质量明显下降,甚至在正文中漏出奇怪的内部符号(如 U+1290 U+1F4AD 思考分隔符和重复片段)。切回 ** 0.3.5** 后问题立刻彻底消失。
  3. 排查对比 internal/aistudio/generate.go 发现:问题出在 0.3.6(PR #143,d3c4801 / ef05bb0)新增的“已输出纯文本后的异常续写”(committedTextOnly + partialContinuationPrompt <partial_reply> + continuationPrefixStripper)。
    • 在 0.3.5 中, egenerable() 严格要求 !committed(一旦已经向客户端输出可见正文,绝不强行在半截正文后静默拼接第二次请求)。
    • 而在 0.3.6 / 0.3.7 中,向模型插入 <partial_reply> 提示词让其接着半句话续写,会导致模型思考状态错乱、漏出内部控制符;且只要模型在续写轮稍微改动一个词,continuationPrefixStripper 就会把缓冲文本直接刷进客户端流里,造成回答截断和质量严重下降。

恳请作者去掉这个 committed == true 时的半截文本续写拼接逻辑(恢复 0.3.5 的纯净行为),或者将其设为默认关闭的可选开关!

Madarchik09 avatar Nov 13 '26 05:11 Madarchik09

it's my fault. I used opus to help merge the PR, even though I had already rejected this implementation in https://github.com/Mag1cFall/AIStudio2API/issues/92#issuecomment-6534448023, so either way, it was caused by my stupidity. I'll delete it cleanly in the next version.

Mag1cFall avatar Nov 13 '26 11:11 Mag1cFall