Skip to content

🐛 fix(agent-runtime): always persist assistant reasoning to DB#15687

Merged
arvinxx merged 2 commits into
canaryfrom
fix/persist-assistant-reasoning
Jun 11, 2026
Merged

🐛 fix(agent-runtime): always persist assistant reasoning to DB#15687
arvinxx merged 2 commits into
canaryfrom
fix/persist-assistant-reasoning

Conversation

@arvinxx

@arvinxx arvinxx commented Jun 11, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • ✅ test
  • 📝 docs
  • 🔨 chore

🔗 Related Issue

Regression introduced by #13494.

🔀 Description of Change

#13494 added a preserveThinking feature for Qwen3.7 Max, but it also gated the DB persistence of assistant reasoning behind the same condition (chatConfig.preserveThinking === true and model extendParams includes preserveThinking / qwen-zhipu provider fallback).

That gate conflates two distinct concerns:

  1. Payload replay — whether reasoning is fed back into the next LLM call (state.messages). This should be gated by model capability, since most providers reject or ignore replayed thinking.
  2. DB persistence — whether reasoning is saved to the messages table 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.reasoning was null). The interrupted-stream persistence path was never gated, making the happy path inconsistent with it as well.

This PR:

  • Restores unconditional reasoning: finalReasoning in the messageModel.update call.
  • Keeps the preserveThinking gate only for the state.messages push (payload replay), renaming shouldPersistAssistantReasoningshouldReplayAssistantReasoning to match its actual semantics.
  • Updates the test suite: the existing replay-gate assertions are preserved, and new assertions verify the DB update always receives reasoning even when the gate is off.

🧪 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.

  • Tested locally
  • Added/updated tests
  • No tests needed

📝 Additional Information

Behavior matrix after this fix:

Scenario DB reasoning Replayed into next payload
preserveThinking on + supported model saved yes
preserveThinking off / unsupported model saved no (unchanged)

🤖 Generated with Claude Code

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>
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Canceled Canceled Jun 11, 2026 2:27pm

Request Review

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. feature:agent Assistant/Agent configuration and behavior labels Jun 11, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@arvinxx

arvinxx commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

@sxjeru

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/server/src/modules/AgentRuntime/RuntimeExecutors.ts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.55%. Comparing base (77e4d04) to head (6ce038d).
⚠️ Report is 13 commits behind head on canary.

❗ There is a different number of reports uploaded between BASE (77e4d04) and HEAD (6ce038d). Click for more details.

HEAD has 17 uploads less than BASE
Flag BASE (77e4d04) HEAD (6ce038d)
packages/web-crawler 1 0
packages/utils 1 0
packages/context-engine 1 0
packages/conversation-flow 1 0
packages/model-runtime 1 0
packages/agent-runtime 1 0
packages/ssrf-safe-fetch 1 0
packages/memory-user-memory 1 0
packages/types 1 0
packages/trpc 1 0
packages/app-config 1 0
builtin-tools 1 0
packages/model-bank 1 0
packages/agent-manager-runtime 1 0
packages/eval-rubric 1 0
packages/fetch-sse 1 0
packages/eval-dataset-parser 1 0
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     
Flag Coverage Δ
app 48.38% <ø> (?)
builtin-tools ?
database 98.12% <ø> (ø)
packages/agent-manager-runtime ?
packages/agent-runtime ?
packages/app-config ?
packages/context-engine ?
packages/conversation-flow ?
packages/eval-dataset-parser ?
packages/eval-rubric ?
packages/fetch-sse ?
packages/file-loaders 87.89% <ø> (ø)
packages/memory-user-memory ?
packages/model-bank ?
packages/model-runtime ?
packages/prompts 72.51% <ø> (ø)
packages/ssrf-safe-fetch ?
packages/trpc ?
packages/types ?
packages/utils ?
packages/web-crawler ?
server 69.58% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 68.70% <ø> (∅)
Services 54.15% <ø> (∅)
Server 97.15% <ø> (+82.86%) ⬆️
Libs 54.13% <ø> (+14.32%) ⬆️
Utils 82.29% <ø> (+23.54%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arvinxx arvinxx merged commit a810bf3 into canary Jun 11, 2026
34 of 36 checks passed
@arvinxx arvinxx deleted the fix/persist-assistant-reasoning branch June 11, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:agent Assistant/Agent configuration and behavior size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant