fix(cli): dedup compact summaries on (source_id, content_hash), not source_id alone - #48
Merged
Merged
Conversation
…ource_id alone A compact summary is a running total of the session so far, so the first one is the narrowest. `--store-compact-summary` deduped on source_id alone: the first summary of a session was stored, and every later, wider one hit "already stored" and was dropped. A SessionStart hook normally discards the CLI's stdout, so nothing surfaced the loss. Scale, measured over one hook-trace archive: 190 recorded compactions across 43 sessions. 30 sessions (69.8%) compacted more than once, so 147 summaries (77.4%) could never reach the table however clean the write path was. One session compacted 55 times; 54 of those windows were never in memory at all. Dedup now keys on (source_id, content_hash). Identical content still short-circuits, so a resume replaying the same summary stays a no-op. content_hash and its index already exist (migration 004), and the hash is computed the same way storeMemory computes it for `content`. Rows written before migration 004 have no hash, so an identical replay of one of those is stored once more -- the same thing storeMemory's own dedup does for legacy rows. Checked end to end through the CLI on a scratch DB, one session id: first summary -> stored same content again -> already stored (dedup still works) wider summary -> stored (was "already stored") wider summary again -> already stored Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: 千夏 <qianxia@clawgamers.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.
What
--store-compact-summarynow dedups on(source_id, content_hash)instead ofsource_idalone.Why
A compact summary is a running total of the session so far, so the first one is the narrowest. Keying dedup on
source_idstored the first summary of a session and dropped every later, wider one ("already stored"). A SessionStart hook normally discards the CLI's stdout, so nothing surfaced the loss.Measured over one hook-trace archive: 190 recorded compactions across 43 sessions; 30 sessions (69.8%) compacted more than once, so 147 summaries (77.4%) could never reach the table. One session compacted 55 times; 54 of those windows were never stored.
Change
Identical content still short-circuits, so a resume replaying the same summary stays a no-op.
content_hashand its index already exist (migration 004); the hash is computed exactly asstoreMemorycomputes it forcontent(SHA-256 of the same string, first 16 hex chars). Rows written before migration 004 have no hash, so an identical replay of one of those is stored once more — same asstoreMemory's own dedup on legacy rows.Testing
Through the CLI on a scratch DB, one session id: first summary → stored; same content again → already stored; wider summary → stored (was "already stored"); wider summary again → already stored. CI workflow steps run locally on Windows / Node 24 with temp DBs: 23/24 pass; the one failure is
embedding-timeout, which passes 18/18 assertions then hits a libuv assertion on exit on Windows (identical on unmodifiedmain).🤖 Generated with Claude Code