emrg: persist and pass back DeepSeek thinking-mode reasoning - #937
Merged
Conversation
…26-08-22T17:25:02)
argszero
commented
Aug 22, 2026
argszero
left a comment
Owner
Author
There was a problem hiding this comment.
✅ LGTM — cycle 2026-08-22T19:26:07. Fix is correct and complete:
- Root cause verified: reasoning_content accumulated in llm.py streaming but dropped on session persistence and message reassembly, so subsequent rounds lack the verbatim reasoning DeepSeek thinking mode requires (400 error).
- daemon.py covers all four message-building paths (final answer, in-loop tool_calls round, _reflect, _consolidate_session_memories) — reasoning persisted as 'reasoning' and re-injected as 'reasoning_content'.
- session.py get_messages_for_llm() maps persisted reasoning → reasoning_content; old records without the field are skipped naturally (no regression).
- Tests cover plain pass-back, tool-call rounds, and legacy-record compatibility.
- CI green (test + test-windows, run 32566754537).
argszero
commented
Aug 22, 2026
argszero
left a comment
Owner
Author
There was a problem hiding this comment.
✅ LGTM — cycle 47. Re-verified: head unchanged (8858728), diff covers all four assistant-message paths (final answer / tool-call round / _reflect / task-handler) with reasoning persisted + re-injected as reasoning_content, session.py maps persisted reasoning back with natural skip for legacy records. 3 regression tests added; local pytest 1010 passed + 1 skipped; CI green (test + test-windows, run 32566754537).
argszero
added a commit
that referenced
this pull request
Aug 22, 2026
argszero
added a commit
that referenced
this pull request
Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes DeepSeek thinking-mode 400 error: "The reasoning_content in the thinking mode must be passed back to the API" (LLM stream error in round N).
Root cause (verified against source + logs):
llm.pycorrectly accumulatesreasoning_contentintofull_reasoningduring streaming;append_messagecalls indaemon.pypersisted assistant messages with only content + tool_calls (reasoning went only to llm.jsonl);session.get_messages_for_llm()rebuilt assistant messages without reasoning;reasoning_contentverbatim — missing it triggers the 400 inside tool loops.Fix (4 changes):
daemon.py×3 main-loopappend_messagesites: persistreasoningwhen not None (old records untouched);daemon.pymain-loop in-memory messages:reasoning_contentadded to the assistant message appended for the next round — closes the within-tool-loop path (round N error);daemon.pymemory-reflection + task-handler tool loops: pass backreasoning_contentfromllm.chatresponses (same bug class);session.pyget_messages_for_llm: maps persistedreasoning→reasoning_content; records without the field are skipped naturally (old histories unaffected).Compatibility: folded placeholder assistant messages (no tool_calls) are not required by DeepSeek to carry reasoning; history size grows slightly (API hard requirement) — a reasoning-window fold can be a follow-up.
Verification: pytest 1010 passed + 1 skipped (1011 collected, +3 new regression tests); import/help OK; Agent.md count synced to 1011.