Commit Graph
1 Commits
Author SHA1 Message Date
yetone d4a1b9baa7 gateway: a </think> inside code no longer ends a reply's thinking; a plugin's text keeps its <think> (#2634)
Kane-Kuroneko's Qoder replies through Codex began mid-sentence at a
backtick: the Chat decoder took any reply whose text began with <think>
as inline thinking up to the first literal </think>, even one inside an
inline-code example ("使用 `<think>...</think>` 标签"), for every Chat
upstream.

- The close is looked for only outside Markdown code (mdCode in
  chat.go): an inline span (taken to end with its line, so a stray
  backtick can't swallow the answer) or a fenced block. Backtick runs and
  a close split across chunks are held, as the tag tail was.
- A plugin's Chat reply is read as OpenCode reads it, its text as it came
  (decoderFor, used by streamTranslated, the continuation path and the
  search path): the plugin knows its vendor and gives reasoning apart.
  Qoder's plugin sends reasoning_content and has no splitter of its own.
- A reply that already gave thinking in reasoning_content/reasoning has
  no leading-tag lookup in its text.
- The line breaks after a close are left out however they're chunked:
  one character a delta used to leave "\n" at the head of the answer.
- Codex titles/descriptions/predictions (codex_titles.go) strip a leading
  block with the same close rule (afterThought), the sibling cut.
MiniMax (2ab69d0f) and Gemini's <thought> keep working: their existing
tests pass unchanged.

Tests use the reporter's literal bytes, whole, a character a delta and a
byte a delta: TestChatThinkCloseInCode, TestThinkExampleReachesClientsWhole
(Codex /v1/responses and Claude Code /v1/messages against a fake Chat
upstream), TestChatThinkTagAfterReasoningField, TestPluginThinkTagIsText
(the fake plugin as qoder, through Bun, with #2634's historical
boundary), TestAfterThoughtCloseInCode.

Broken by hand, each watched go red: close matched inside code ->
TestChatThinkCloseInCode, TestThinkExampleReachesClientsWhole,
TestAfterThoughtCloseInCode; reasoning-field rule off ->
TestChatThinkTagAfterReasoningField; plugin scope off ->
TestPluginThinkTagIsText; newline trim off -> TestChatThinkCloseInCode,
TestThinkExampleReachesClientsWhole, plus the existing MiniMax tests.

Run: gofmt -l clean; go vet ./... (darwin), GOOS=linux and GOOS=windows
go vet -tags nogui ./... clean; go test -timeout 45m ./... on this change plus the next
commit's library edit (the worktree held both while it ran): 64
packages ok, internal/gateway ok (524s), internal/library ok; internal/gui's
real-window darwin tests were killed at their 30s bar under a load
average of ~295, and internal/provider failed to link on a GOCACHE file
another run trimmed. Rerun alone: internal/provider ok (206s),
internal/gui ok (165s). No GUI files touched. Not tried
against real Qoder or MiniMax accounts.

Not changed: the plugins repo's think-tags middleware
(packages/think-tags) also ends a block at the first indexOf("</think>")
when a user turns it on.
2026-10-17 08:49:42 +08:00