Skip to content

fix(replay): give every assistant turn a thinking block before the upstream call - #111

Open
chrisnestrud wants to merge 1 commit into
ZhiYi-R:mainfrom
chrisnestrud:fix/replay-thinking-assistant-text
Open

chrisnestrud wants to merge 1 commit into
ZhiYi-R:mainfrom
chrisnestrud:fix/replay-thinking-assistant-text

Conversation

@chrisnestrud

Copy link
Copy Markdown

Summary

Fixes a replay gap that makes every later request in a session fail once that
session contains a text-only assistant turn.

  • Give every assistant turn a thinking block before the upstream call, not only
    turns that contain tool_use.
  • Reuse the plugin's existing order: tool-call cache, then assistant-text cache,
    then the empty boundary block.
  • Warn when the empty boundary block is used, so missing replay history is
    visible in the log instead of silent.
  • Correct candidate_routing_test.go, whose expectation that a text-only
    assistant turn stays bare encoded the defect, and add coverage for the
    text-only turn, an existing thinking block, and tool-call cache preference.

Fixes #110

Root cause

prependCachedThinking skipped assistant messages without a tool_use block.
The provider requires a thinking block on every assistant turn while thinking
is enabled; the plugin path already handled any assistant turn, the adapter
path did not.

Validation

CGO_ENABLED=0 go test -p 1 ./...
CGO_ENABLED=0 go build -trimpath -o /tmp/moonbridge ./cmd/moonbridge

Replaying the captured failing request against the provider: as-is returns 400,
adding an empty thinking block to the plain assistant turn returns 200, and
without that block it returns 400 again. Running this build on a live proxy:
zero content[].thinking 400s across 185 streamed requests where the failure
was previously constant, and a four-turn tool-call probe that previously died
completes.

Note: this branch is based on main, independently of #103; the two fixes do
not interact.

…stream call

DeepSeek rejects a thinking-enabled conversation whose assistant turn carries no
thinking block, with "The content[].thinking in the thinking mode must be passed
back to the API". That applies to text-only assistant turns as well as
tool-call turns.

prependCachedThinking skipped every assistant message without a tool_use block,
so a conversation whose earlier assistant turn was plain text reached the
provider bare and was rejected. Verified against the provider with the captured
failing request: the captured body returns 400, and the same body returns 200
once the plain assistant message gains a thinking block (empty or filled),
while dropping that message also returns 200.

The adapter path now applies the same rule the plugin already applies on its own
path: tool-call cache, then assistant-text cache, then the empty boundary block.

Refs: ZhiYi-R#102 ZhiYi-R#63
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.

bug(replay): a text-only assistant turn without a thinking block is rejected upstream

1 participant