🐛 fix(agent-runtime): always persist assistant reasoning to DB#15687
Conversation
PR #13494 gated message reasoning persistence behind preserveThinking (agent chatConfig + model extendParams / qwen|zhipu fallback). That gate is only meant to control whether reasoning is replayed into the next LLM payload — applying it to the DB write dropped thinking content for every non-qwen/zhipu reasoning model in server-side agent mode: reasoning streamed live via stream_end but vanished after refresh. Restore unconditional reasoning persistence in messageModel.update and keep the preserveThinking gate only for state.messages payload replay. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0779992e09
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## canary #15687 +/- ##
===========================================
- Coverage 80.93% 60.55% -20.39%
===========================================
Files 1536 3037 +1501
Lines 204910 265946 +61036
Branches 20622 30244 +9622
===========================================
- Hits 165847 161047 -4800
- Misses 38879 104885 +66006
+ Partials 184 14 -170
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
💻 Change Type
🔗 Related Issue
Regression introduced by #13494.
🔀 Description of Change
#13494 added a
preserveThinkingfeature for Qwen3.7 Max, but it also gated the DB persistence of assistant reasoning behind the same condition (chatConfig.preserveThinking === trueand modelextendParamsincludespreserveThinking/ qwen-zhipu provider fallback).That gate conflates two distinct concerns:
state.messages). This should be gated by model capability, since most providers reject or ignore replayed thinking.messagestable for UI display. This should not be gated.Since the merge, every server-side agent run on a non-qwen/zhipu reasoning model silently lost its thinking content: reasoning streamed live via
stream_end, but after a page refresh it was gone (messages.reasoningwasnull). The interrupted-stream persistence path was never gated, making the happy path inconsistent with it as well.This PR:
reasoning: finalReasoningin themessageModel.updatecall.preserveThinkinggate only for thestate.messagespush (payload replay), renamingshouldPersistAssistantReasoning→shouldReplayAssistantReasoningto match its actual semantics.🧪 How to Test
Run a server-side agent with any non-qwen/zhipu thinking model (e.g.
lobehub/deepseek-v4-pro), let it produce reasoning, then refresh the page — the thinking block should still render (previously it disappeared).bunx vitest run 'apps/server/src/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts'All 116 tests pass.
📝 Additional Information
Behavior matrix after this fix:
reasoning🤖 Generated with Claude Code