Repository navigation
Conversation
Exit summaries snapshot the whole session branch, not "messages since the last summary". Quitting, resuming the same session, and quitting again therefore summarizes the identical transcript twice and appends it to the daily log twice. That is not just noise: today's daily log is re-injected into every new session, so the duplicate is paid for in context on every subsequent turn. Compare the newest message in the branch against the last summary already recorded for the session, and skip the LLM call entirely when nothing was added. The scan reads the `<!-- <ts> [<sid>] -->` headers in today's and yesterday's daily logs; pre-compaction handoffs use the same header shape and also snapshot the whole branch, so they count as well. Only `message` entries count. Bookkeeping entries (plan-mode-state, compact-thinking-duration, agent-summary, ...) are appended on every session transition and would otherwise defeat the check — in the observed duplicate, the only entries between the two summaries were three plan-mode-state rows. The guard fails open: an unidentifiable session, missing branch, or unparseable timestamp summarizes as before, because losing a summary is worse than writing a duplicate. Signed-off-by: MiFaZhan <198522268+MiFaZhan@users.noreply.github.com>
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.
Problem
Exit summaries snapshot the whole session branch, not "messages since the last summary". So quitting, resuming the same session, and quitting again summarizes the identical transcript a second time and appends it to the daily log again.
This is not just cosmetic noise. Today's daily log is re-injected into the system prompt on every new session, so the duplicate is paid for in context on every subsequent turn — and it keeps resurfacing through
memory_search.Observed in the wild: one session id appearing twice in a single daily log, ~4 minutes apart, with byte-similar content in two different languages:
The only entries added to the branch between those two summaries were three
plan-mode-staterows. The session file ends at 13:07:07, and pi callsprocess.exit(0)aftersession_shutdown, so the second summary could only have come from a resume of the same session.Fix
Before generating a summary, compare the newest
messageentry in the branch against the last summary already recorded for that session, and skip the LLM call entirely when nothing was added.<!-- <ts> [<sid>] -->headers from today's and yesterday's daily logs, so a session resumed across midnight is still covered.messageentries count. Bookkeeping entries (plan-mode-state,compact-thinking-duration,agent-summary, …) are appended on every session transition and would otherwise defeat the check — in the observed case above, those threeplan-mode-staterows were exactly what a naive timestamp comparison would trip over.getSessionIdSafe()also keepssession_shutdownfrom throwing on teardown paths where the context is bare — the rest of that handler already treats a missing session manager as "no data, carry on".Verification
197 → 208tests,0failures.tsc -p tsconfig.json --noEmitandbiome check .are both clean.The 11 new tests cover timestamp parsing round-trips, session-id matching (including non-hex prefixes, since
shortSessionId()only slices 8 chars), the bookkeeping-only tail, fail-open cases, and two end-to-endsession_shutdownassertions — one that the LLM call is skipped, one that it still fires when the branch moved on.The tests genuinely detect the bug: forcing
hasNewMessagesSince()to always returntruemakes 3 of them fail.I also replayed the real captured session (
01a13d57, 370 messages) against the patched handler with the daily log truncated to its pre-duplicate state: summary count4 → 4, handler returns in 4 ms with no LLM call.Note on
/quitWhile investigating I noticed the
inputhandler at the bottom of the file that setsexitSummaryReason = "slash-quit"appears to be dead code:interactive-mode.jsintercepts/quitand callsshutdown()directly, so the text never reachessession_input→_runInputHandlers→ theinputevent. In a real daily log, every entry readsexit: session-end— none read/quit. I left it alone since it's cosmetic and out of scope, but it may be worth either removing or fixing separately.