emrg: session — recompute message_count on compact, count message records only (rant 2026-08-31T14:18:14) - #1083
Merged
Conversation
…ords only (rant 2026-08-31T14:18:14)
argszero
commented
Aug 31, 2026
argszero
left a comment
Owner
Author
There was a problem hiding this comment.
✅ LGTM — cycle (1/3)
Reviewed head ba65cee against master (1fdc606):
- Root cause confirmed:
append_message()incremented_message_countfor every persisted record includingtool_result, andSession.compact()never decremented it — the TUI/GUI 'msgs' counter inflated monotonically (e.g. 5770 shown vs 192 records in history.jsonl). - Fix is sound: compact() recomputes
_message_countfrom the surviving message-type records (same semantics as the rewind handler in daemon.py), and append_message() only countstype == "message"records (defaulting to message when absent, so existing callers are preserved); tool_result/summary records still persist to history. - Tests: 3 new (tool_result exclusion; compact recompute regression with mixed message/tool_result history; recompute survives reload from meta.json). test_session.py 66 passed; CI test + test-windows green (run 33366280252); mergeable_state clean.
No issues found.
argszero
commented
Aug 31, 2026
argszero
left a comment
Owner
Author
There was a problem hiding this comment.
✅ LGTM — cycle (2/3)
Re-verified head ba65cee against current master (4fd2b63) this cycle:
- diff unchanged and matches the intended fix:
append_message()increments_message_countonly fortype == "message"records (defaulting to message when absent — existing callers preserved; tool_result/summary still persist without inflating the count);Session.compact()recomputes_message_countfrom the surviving message-type records, aligned with the rewind handler's semantics in daemon.py. - The fix directly addresses the reported symptom (5770 msgs shown vs 192 records in history.jsonl) and prevents re-inflation between compacts.
- Tests: 3 new regression tests (tool_result exclusion; compact recompute; reload persistence) — branch test_session.py 66 passed; master baseline still green (63 passed). CI test + test-windows green (run 33366280252); mergeable_state clean.
No issues found.
argszero
commented
Aug 31, 2026
argszero
left a comment
Owner
Author
There was a problem hiding this comment.
✅ LGTM — cycle (3/3)
Re-verified head ba65cee against current master (4fd2b63) this cycle:
- diff unchanged:
append_message()counts onlytype == "message"records (tool_result/summary persist without inflating the count);Session.compact()recomputes_message_countfrom surviving message-type records (rewind-aligned). - Local test_session.py + test_doc_counts.py all pass (68 passed); CI test + test-windows green (run 33366280252); mergeable_state clean.
3 consecutive ✅ from distinct cycles (07:04:12Z / 07:11:06Z / this cycle), no ❌ — good to merge.
argszero
added a commit
that referenced
this pull request
Aug 31, 2026
…d, GUI tool/text order, LLM stream retry, session message_count) (#1085) Co-authored-by: EMRG Evolution <emrg@argszero.dev>
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.
Fix TUI/GUI message count inflation after /compact (rant 2026-08-31T14:18:14).
Problem
The status bar showed "5770 msgs" for a session whose history.jsonl held only 192 records. Root cause: session.py's counter only ever grows:
append_message()incremented_message_countfor every record — includingtool_resultrecords persisted from the tool loop (daemon.py:2778) and summaries.Session.compact()replaced the compacted messages with one summary but never decremented_message_count— the inflated value survived (e.g. 5806 = ~5700 pre-compact + ~100 after, matchinglast_compact_at).meta.message_countdirectly.Meanwhile
rewind(daemon.py:2083) already recomputed the count assum(r.type == "message")— compact simply missed the same reconciliation.Fix (Plan A — confirmed by host)
Session.compact(): after writing the new history, recompute_message_countfrom the surviving records (message-type only) — aligned with rewind semantics.Session.append_message(): increment only fortype == "message"records (missing type defaults to message, preserving existing callers) — tool_result/summary records persist but no longer inflate the user-facing count, so the count cannot re-inflate between compacts.Tests
test_append_tool_result_does_not_increment_count— tool_results persist but are excluded from the count.test_compact_recomputes_message_count— mixed message/tool_result history: count shrinks to the surviving message records after compact (regression for the rant).test_compact_count_persists_after_reload— recomputed count survives Session.load() from meta.json.Verification: pytest 1182 passed + 1 skipped; import + CLI green; Agent.md Python count synced to 1183.
Note: a display-side fallback (Plan B — fall back to the actual record count when
message_countdeviates wildly) was mentioned as optional in the rant; Plan A alone fixes the reported bug, so B is deferred.