emrg: fix double-accumulated reasoning in llm.jsonl (O(n²) blowup) - #943
Conversation
…nt 2026-08-23T10:15:06) daemon.py appended every per-chunk cumulative reasoning snapshot and joined them, re-accumulating what llm.py already accumulates (chunk['reasoning'] = full think text so far, llm.py:366). For 47 real thinking tokens this produced a 29640-char record (630x); the worst llm.jsonl record hit ~10MB with ~190MB across 3 rotations. Take the LAST snapshot instead: it is the complete think text.
argszero
commented
Aug 23, 2026
✅ LGTM — cycle 1287. The daemon-side double-accumulation is confirmed against the llm.py contract (chunk['reasoning'] is already the cumulative snapshot, llm.py:366); taking the last snapshot yields the complete think text. Single accumulation site in daemon.py — fix is complete. |
argszero
commented
Aug 23, 2026
✅ LGTM — cycle 1288. Fresh-eyes re-review of the final head (835ebb0, after master merge): the one-line fix correctly takes the last cumulative snapshot (chunk['reasoning'] is the full think text per llm.py:366, so [-1] is complete and O(n) instead of O(n²)). Empty reasoning_parts → None preserves the no-reasoning behavior; all three downstream full_reasoning sites (assistant-message persist + llm.jsonl logs) are unchanged. The conflict resolution also correctly kept #942's cache-pct debug line. CI test + test-windows pass on head; local pytest 1008 passed + 1 skipped. |
argszero
commented
Aug 23, 2026
✅ LGTM — cycle 1289. Third consecutive fresh-eyes review (head 835ebb0, CI test + test-windows green, MERGEABLE). The fix takes the last cumulative reasoning snapshot (chunk['reasoning'] = full think text per llm.py:366), eliminating the O(n²) double-accumulation that inflated a 47-token think to a 29,640-char llm.jsonl record; empty reasoning_parts → None preserves prior behavior. No ❌ since the first LGTM — merge condition (3 consecutive ✅ from different cycles) satisfied. |
Uh oh!
There was an error while loading. Please reload this page.
Fix double-accumulated reasoning in llm.jsonl (O(n²) blowup)
Problem
emrg/server/daemon.pyappended every per-chunk cumulative reasoning snapshot toreasoning_partsand joined them at the end. Butllm.pyalready accumulates reasoning internally and yields the full think text so far on every chunk (chunk["reasoning"] = "".join(reasoning_parts),llm.py:366).Appending N cumulative snapshots and joining them re-accumulates the text N times — O(n²) growth:
llm.jsonlrecord: 9,968,917 chars (~10 MB)Fix
Take the last snapshot — it is the complete think text:
A comment in the code documents the
llm.pyaccumulation contract so this cannot regress silently.Verification
uv run pytest tests/ -q→ 1006 passed, 1 skippedfrom emrg.client.app import run_client+python -m emrg --helpOKllm.pyaccumulation contract itself is already covered bytests/test_llm.py(test_stream_accumulates_reasoning_content,test_stream_accumulates_openai_reasoning,test_stream_no_reasoning_means_none)Ref: host rant
2026-08-23T10:15:06(P0).