Skip to content

perf(consolidation): check for pending work without counting the bank - #6403

Merged
nicoloboschi merged 2 commits into
mainfrom
fix/pending-consolidation-probe
Nov 6, 2026
Merged

nicoloboschi merged 2 commits into
mainfrom
fix/pending-consolidation-probe

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Closes #6326. Contributor patch by @harshitgupta31415 (commit kept with their authorship), plus two follow-ups.

After a memory or document is deleted, the refresh scheduler only needs to know whether any fact is still waiting for consolidation. It used to count the whole bank to find out. It now stops at the first such fact, using idx_memory_units_unconsolidated. The filter is the same one the pending count uses, so the answer is identical.

Follow-ups on top of the original patch:

  • Newest first. Consolidation works oldest first, so permanently failed facts pile up at the old end of the index (same reasoning as b2429c65cc20). Reading oldest first would step over every one of them.
  • No Postgres-only gate. The LIMIT 1 shape rewrites cleanly on Oracle (see pg/reads.py), so Oracle no longer falls back to the full count.

Measured on 1M rows in one bank (PG16, warm cache):

Bank state Full count Probe (oldest first) Probe (newest first)
100k failed facts, nothing pending ~140 ms ~25 ms ~12 ms
Mostly failed facts, nothing pending ~115 ms ~35–45 ms —

Tests: test_pending_consolidation_probe.py (new), test_memories_extension.py, test_mental_model_retractions.py, test_delete_document_concurrency.py.

harshitgupta31415 and others added 2 commits November 6, 2026 14:38
- read idx_memory_units_unconsolidated newest first: consolidation works
  oldest first, so failed facts pile up at the old end (same reasoning as
  b2429c65cc20); measured ~25 ms -> ~12 ms with 100k failed facts
- drop the Postgres-only gate: the LIMIT 1 shape rewrites cleanly on Oracle
  (see pg/reads.py), so Oracle no longer falls back to the full count
- say in the test why it uses direct SQL
@nicoloboschi
nicoloboschi merged commit 297f5d4 into main Nov 6, 2026
223 of 224 checks passed
@nicoloboschi
nicoloboschi deleted the fix/pending-consolidation-probe branch November 6, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check for pending consolidation without counting the bank (530.76 ms → 0.68 ms, 778× faster)

2 participants