You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: avoid memory authorization and activity publication deadlocks - #1397
Changing memory recall preferences can deadlock with background activity publication. Keep the authorization rows locked while allowing publication's foreign-key checks to proceed.
AI review notes: The PostgreSQL service log identifies Memories.authorize and the activity outbox insert as the two deadlocking transactions. Authorization now uses FOR NO KEY UPDATE for the bot, conversation and membership rows. This remains incompatible with updates and deletion of those authorization rows, while permitting the foreign-key KEY SHARE locks used by publication.
The new regression calls the actual memory service while another transaction holds the conversation's foreign-key lock. It fails against the old implementation and passes with this change. A separate two-connection experiment reproduces 40P01 with the old lock mode and completes with the new one; checks also confirm bot archival and membership deletion remain blocked while authorization locks are held.
Validation: all 279 PostgreSQL runtime tests passed across 35 files. The final memory suite passed all 10 tests after correcting its transaction query typing. pnpm test passed: TypeScript/lint, 577 unit tests with 4 skipped, 2,270 chat tests, and 20 desktop tests with 1 skipped. These are isolated local database checks, not production concurrency measurements.
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
📝 Walkthrough
Transactional memory authorization now uses no key update row locks. A runtime regression test checks that enabling memory preferences does not wait on a monitored lock and verifies the resulting preference revision.
Changes: Memory preference locking
Layer / File(s)
Summary
Transactional authorization locks and regression test src/chat/server/memory.ts, harness-tests/pending-runtime/memory-runtime.test.ts
Memories.authorize uses no key update locks for selected rows in transactions. The regression test holds a conversation key-share lock, monitors for a wait, and verifies that enabling preferences completes at revision 1.
The authorization lock change has no identified merge-blocking issue; the regression test covers the reported old-mode wait.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title accurately summarizes the primary change: preventing deadlocks between memory authorization and activity publication.
Linked Issues check
Issue #1396 requires identifying the deadlock between memory authorization and activity publication, correcting the lock ordering without weakening authorization, and avoiding blanket retries. The PR …
Out of Scope Changes check
The PR changes one authorization lock mode and adds one focused regression test. Both changes directly support issue #1396 by preventing the activity publication foreign-key lock conflict while retain…
Docstring Coverage
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Linked Issues check
Explanation
Issue #1396 requires identifying the deadlock between memory authorization and activity publication, correcting the lock ordering without weakening authorization, and avoiding blanket retries. The PR changes transactional authorization locks in Memories.authorize from FOR UPDATE to FOR NO KEY UPDATE for the bot, conversation, and membership rows. The regression test holds a conversation FOR KEY SHARE lock and calls the actual setPreferences service. The reported validation also reproduces the old 40P01 failure and verifies archival and membership deletion remain blocked. No retry or Sentry filtering change is present, so the separate scope in #1327 remains intact.
Full details: Out of Scope Changes check
Explanation
The PR changes one authorization lock mode and adds one focused regression test. Both changes directly support issue #1396 by preventing the activity publication foreign-key lock conflict while retaining authorization locks. No unrelated implementation or test changes are shown.
Full details: Docstring Coverage
Explanation
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.
✨ Finishing Touches
📝 Generate docstrings
Commit to this branch
Create a new PR
🧪 Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
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
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.
Changing memory recall preferences can deadlock with background activity publication. Keep the authorization rows locked while allowing publication's foreign-key checks to proceed.
Fixes #1396.
Summary by CodeRabbit