Skip to content

emrg: persist and pass back DeepSeek thinking-mode reasoning - #937

Merged
argszero merged 1 commit into
masterfrom
feature/deepseek-reasoning-passback
Aug 22, 2026
Merged

emrg: persist and pass back DeepSeek thinking-mode reasoning#937
argszero merged 1 commit into
masterfrom
feature/deepseek-reasoning-passback

Conversation

@argszero

Copy link
Copy Markdown
Owner

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):

  1. llm.py correctly accumulates reasoning_content into full_reasoning during streaming;
  2. but the three append_message calls in daemon.py persisted assistant messages with only content + tool_calls (reasoning went only to llm.jsonl);
  3. on the next request, session.get_messages_for_llm() rebuilt assistant messages without reasoning;
  4. DeepSeek thinking mode requires assistant messages (especially tool-call rounds) to pass back the previously returned reasoning_content verbatim — missing it triggers the 400 inside tool loops.

Fix (4 changes):

  • daemon.py ×3 main-loop append_message sites: persist reasoning when not None (old records untouched);
  • daemon.py main-loop in-memory messages: reasoning_content added to the assistant message appended for the next round — closes the within-tool-loop path (round N error);
  • daemon.py memory-reflection + task-handler tool loops: pass back reasoning_content from llm.chat responses (same bug class);
  • session.py get_messages_for_llm: maps persisted reasoningreasoning_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.

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

✅ 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 argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

✅ 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 argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

✅ LGTM — cycle 48. Re-verified: head unchanged (8858728), CI green (test + test-windows, run 32566754537), fix covers all assistant-message paths + session mapping + legacy compat. 3rd consecutive ✅ — merging.

@argszero
argszero merged commit e6c066b into master Aug 22, 2026
2 checks passed
argszero added a commit that referenced this pull request Aug 22, 2026
#936 #937) (#939)

* emrg: revert DeepSeek thinking-mode reasoning pass-back (rant 2026-08-22T21:12:46)

* emrg: revert tool result sliding window (#936) (rant 2026-08-22T21:23:18)
@argszero
argszero deleted the feature/deepseek-reasoning-passback branch August 23, 2026 02:26
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.

1 participant