fix(conversations): compare-and-swap the denormalized message cache - #877
Open
leseb wants to merge 1 commit into
Open
fix(conversations): compare-and-swap the denormalized message cache#877leseb wants to merge 1 commit into
leseb wants to merge 1 commit into
Conversation
Concurrent item appends each rebuilt the denormalized conversation `messages` cache from the authoritative item rows and wrote it back unconditionally, so a slower writer could clobber a newer writer's cache with a stale snapshot, dropping items from the history that rehydration consumes (praxis-proxy#662). Rebuild the cache and write it with a compare-and-swap, retrying a lost race with a freshly read snapshot. Create/delete callers reuse the snapshot they already read before their row mutation; the append-back path passes none. The written value is always a fresh rebuild, so a stale snapshot only loses the swap and never writes stale data. Exhausting the bounded retries logs a warning and returns Ok: the item-row mutation is already durably committed and any later write rebuilds the cache, so failing here would report a committed create/delete as an error. Genuine store errors and a disappeared conversation still propagate. Signed-off-by: Sébastien Han <seb@redhat.com>
franciscojavierarceo
approved these changes
Sep 2, 2026
franciscojavierarceo
left a comment
Contributor
There was a problem hiding this comment.
reviewed the current head, all available comments and review threads, the architectural paths, and the completed checks. i found no actionable issues. approving this commit.
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Sep 2, 2026
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.
Summary
Concurrent conversation item appends each rebuilt the denormalized
messagescache from the authoritative item rows and wrote it back unconditionally, so a slower writer could overwrite a newer writer's cache with a stale snapshot and drop items from the history that rehydration consumes. This replaces the blind write with a compare-and-swap that retries a lost race with a freshly read snapshot, and reuses the create/delete caller's existing pre-mutation snapshot to skip a redundant cache reload; because the written value is always a fresh rebuild from item rows, a stale snapshot only ever loses the swap and never persists stale data. Exhausting the bounded retries logs and returnsOksince the row mutation is already durably committed and any later write rebuilds the cache, while genuine store errors and a disappeared conversation still propagate.Related issue
Closes #662
Validation
cargo test -p praxis-ai-apis(2592 passed, 0 failed; six Concurrent item appends can overwrite the denormalized conversation history #662 cache-sync tests covering stale-cache repair, concurrent-clobber, snapshot fast-path with no reload, stale-snapshot fresh-read fallback, missing-conversation error, and retry exhaustion)make lintandmake buildChecklist
Signed-off-bytrailer.Breaking changes
None.
sync_conversation_messagesis a crate-internal (pub(super)) helper; the signature change is not part of any public API.