fix(core): batch relation search refresh cleanup - #1391
Merged
Conversation
Signed-off-by: phernandez <paul@basicmachines.co>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Why
Production relation resolution failed when one tenant accumulated 44,926 durable relation-search refresh markers.
clear_pending_search_refreshes()expanded every marker into oneDELETE ... IN (...), exceeding asyncpg's hard 32,767 query-argument limit. The sibling generation-fenced completion path had the same unbounded statement shape.Closes #1390. Tracks Logfire production issue #2589 (trace
01a05271a7f19527aad3e12f3621cd1a).What Changed
Implementation Details
The methods continue to execute inside the existing caller-owned transaction, so splitting the SQL does not change atomicity. Project scoping and the accepted-generation predicate remain on every generated statement. A 500-ID batch stays comfortably below asyncpg's 32,767 parameter ceiling and older SQLite parameter ceilings.
Testing
Passed:
./.venv/bin/pytest tests/repository/test_relation_search_refresh_batching.py tests/indexing/test_relation_search_refresh_retry.py -q(4 passed, SQLite)BASIC_MEMORY_TEST_POSTGRES=1 ./.venv/bin/pytest tests/repository/test_relation_search_refresh_batching.py tests/indexing/test_relation_search_refresh_retry.py -q(4 passed, PostgreSQL)uv run ruff check src tests test-intuv run ruff format --check src/basic_memory/repository/relation_repository.py tests/repository/test_relation_search_refresh_batching.pyjust typecheckgit diff --checkLoad-bearing proof: temporarily replacing both batching loops with a single unbounded batch made both new tests fail with the observed five-ID statement instead of the required 2/2/1 split; restoring the fix returned them to green.
Risks / Follow-ups
This changes only statement partitioning; transaction ownership and deletion predicates are unchanged. After this reaches Basic Memory Cloud, rerun the affected tenant's resolver and verify Logfire #2589 does not recur before resolving it.