Repository navigation
fix(memorize): drop resent messages a memcell already holds - #609
Conversation
gloryfromca
left a comment
There was a problem hiding this comment.
Blocking: split retries can duplicate same-timestamp messages, a public import is removed, and the unit suite fails.
I found three concrete issues, marked inline.
Coverage performed: repository rules in CLAUDE.md and all path-scoped .claude/rules; the complete diff; boundary/service/persistence callers; relevant history; backward compatibility; test changes for weakened or missing coverage; and architecture constraints. The architecture contracts and all lint/policy/OpenAPI checks pass. I also tried to refute each finding with the implementation and tests before retaining it.
Verification:
make cicould not start becausemakeis unavailable in the environment, so its non-mutating commands were run directly withuv.- Full unit run: 4,101 passed, 4 skipped, 11 failed. Ten failures were only missing declared NLTK data; after installing
punkt_tabandstopwords, all 13 tokenizer tests pass. The remaining concurrency property failure is deterministic and branch-caused, as noted inline. - Integration: 230 passed, 9 skipped, 7 deselected.
- Direct identity reproduction: initial same-timestamp
[A, B]gives B..._001_<digest>; retrying[B]gives..._000_<digest>.
gloryfromca
left a comment
There was a problem hiding this comment.
Blocking: the split-retry identity and public import compatibility issues still have to change.
The new commit fixes the stale concurrency property model; that thread is now resolved. No additional finding emerged from the new delta. The two earlier code findings remain unchanged and open: direct checks still show a same-timestamp split resend changing the message ID, and gen_message_id still raises ImportError from the advertised facade.
Coverage this round: repository guidance, the complete new delta and full diff, affected ingest/boundary/persistence callers, relevant history, backward compatibility, test-strength changes, and architecture constraints. Verification: Ruff check and format check passed; 21 targeted unit/property/persistence tests passed, including the formerly failing concurrency property. The previous revision's full integration run remains applicable because this revision changes only that unit test.
|
Approved. One edge case, found by reading The summary says a split or regrouped resend keeps its ids. That holds unless several messages in the request share a timestamp.
The two ids differ, so Options: (a) accept it and say in Option (b) keeps the case this PR targets (identical messages in one request stay distinct) and removes the dependence on the other messages in the request. |
A client that retries /memory/add after a timeout resends messages the first call may have cut into a memcell. Deduplication only looked at the session buffer, which a cut empties, so the retry cut them again: a second memcell and episode with the same messages (#274). The boundary stage now drops fresh messages that a memcell of the session already lists. The memcell rows are the record: the cut inserts them in the same transaction that empties the buffer, and a session delete removes them, so no new table or extra write is needed. Message ids no longer depend on where a message sits in its request: m_<session>_<ts>_<n>_<digest>, n counting the request's messages that share the timestamp (so they keep their order) and digest covering sender_id, role, content, tool_call_id and tool_calls. A regrouped resend keeps its ids, and two different messages sent in separate requests with one timestamp no longer share an id (the second used to be dropped). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The concurrency jitter property test built message ids by hand in the old m_<session>_<ts>_<idx> format; it now asks ingest.message_ids. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The id carried the message's position among same-millisecond messages of its request, so resending [A, B] as [B] gave B a new id and it could be cut into a second memcell. The id is now session + timestamp + a digest of who said what; a verbatim repeat within one request adds its repeat count to the digest. Order among same-millisecond messages is kept by a stable timestamp sort and by reading buffered rows in write order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
946a27d to
52dfa7e
Compare
gloryfromca
left a comment
There was a problem hiding this comment.
No blockers; this can merge as far as I am concerned.
The same-timestamp split-resend defect is fixed by content-derived IDs plus stable timestamp ordering, and its focused unit/integration regressions pass. The earlier compatibility concern is withdrawn after checking the clarified internal API boundary, documented replacement, and repository-wide consumers. All three threads opened in prior rounds are resolved, and no new finding survived review.
Coverage: repository guidance; the live-base full diff and new revision delta; ingest, boundary, persistence and service callers; relevant history; backward compatibility; tests for weakening or missing coverage; and architecture constraints. Verification: all lint, formatting, import-architecture, repository-policy and OpenAPI checks passed; unit 4,153 passed / 4 skipped; integration 231 passed / 9 skipped / 7 deselected.
Summary
Fixes #274: a client that retries
/memory/addafter a timeout produced a second memcell (and episode) holding the same messages.Cause. Deduplication only compared fresh messages with the session buffer (
merge_dedupe_sort). A cut moves messages out of the buffer into a memcell, so a resend of those messages looked new and was cut again.Fix.
bufferanddetect) drops fresh messages that a memcell of the session already lists (SessionBufferStore.already_cut). A buffered message is kept, since the tail may share rows with the last cell.memcellrows are the record. The cut inserts them in the same transaction that empties the buffer (fix(storage): make session writes atomic under contention #579), and a session delete removes them, so a resend after/memory/deletewith thatsession_idis memorized again.m_<session>_<ts>_<n>_<digest>.ncounts the request's messages sharing that timestamp (so they keep request order when rows sort by(timestamp, id)), anddigestis 8 hex chars of SHA-256 oversender_id,role,content,tool_call_idandtool_calls(sender_nameexcluded). A split or regrouped resend therefore keeps its ids, and two different messages sent in separate requests with one timestamp no longer share an id; on main the second one was silently dropped.How this covers the review points on #495 (#495 (comment)):
Thanks to @flyto168 for #495, which this supersedes.
Area
Verification
Tests changed because they demanded the old behavior:
test_quarantine.pypinned literalm_s1_<ts>_000ids and now derives them withmessage_ids;test_boundary_stateful.pydocumented the same-millisecond collision as a known property of the old scheme, which this removes.Checklist
main..envfiles, dependency folders, or generated output.Notes for Reviewers
already_cutscans the session's memcells withjson_each(markedponytail:); a(session, message_id)table is the upgrade path if one session ever holds enough memcells for it to show.n.CHANGELOG.md### Fixedsection will conflict textually with fix(memorize): bound the bodies failed async batches keep #607 (whichever lands second rebases).By submitting this pull request, I agree that my contribution is licensed under
the Apache License 2.0.
🤖 Generated with Claude Code