Repository navigation
fix(outbox): page Firestore enrichment pull claims with keyset cursor (#23558) - #23565
Conversation
a51a9d2 to
53415c5
Compare
|
Verdict: the pagination fix is correct, well-tested, and the right shape; two verification notes below should be settled before merge. Correctness (verified on the current head):
Performance: one trade-off to be aware of — when the due backlog is dominated by dormant/leased/privacy-fenced rows, a single Deployment check (the one thing I could not verify): the query adds Blast radius: enrichment summary delivery pull path only; a failure mode would be delayed/missed enrichment work, not data loss. USER IMPACT: none visible directly — this fixes conversation summaries/enrichment falling behind when 100+ leased or deleted conversations sit in front of runnable work in the queue. What I'd still want as a reviewer: a confirmation (test note or deploy checklist) that the (due_at, __name__) ordering is index-compatible with production Firestore, and a maintainer call on whether Left for human maintainer review: the production Firestore index verification is the merge gate I cannot clear from CI evidence alone. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Thanks for the review @Git-on-my-level! Regarding the two verification points:
|
|
The production change here is correct and well-scoped — it properly fixes the bounded-discovery starvation described in #23558, and the tests pin all three invariants from the issue. What I verified:
Performance: per-query cost stays bounded at <=100 documents. The intended trade-off is that a pull Security/privacy: no dependency, credential, or workflow changes; the privacy-fence and lease CAS paths are unchanged and covered by the new PL-002 privacy test. USER IMPACT: users with an enrichment backlog larger than 100 due items will see delayed summaries and reprocessing catch up instead of stalling behind the first 100 rows. Still wanted before merge:
Since this touches the enrichment outbox claim path on user data, it needs a human maintainer sign-off before merge; the code itself looks ready. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
@Git-on-my-level need human response: rechecked head Also correcting my earlier reply: list_due_outbox_entries and its OUTBOX_QUERY_LIMIT ceiling are a separate path; they do not bound this enrichment due_rows generator. This generator intentionally continues pages until the claim budget is met or the due set is exhausted. I have not added a max-page cap that would reintroduce starvation. |
|
Verdict: the production fix looks correct and is nicely scoped — paged keyset discovery in Per-file:
Material notes:
USER IMPACT: conversation enrichment now catches up when many queued items are leased or privacy-retired; previously some runnable work could wait indefinitely behind them. What I'd still want: (1) the emulator/parity-lane qualification run for these exact conformance cases, (2) a maintainer decision between this PR and the other open fix for #23558 (#23569) so one can land, (3) confirmation that the unbounded total scan per claim is acceptable under production backlogs. Leaving for human maintainer review: this changes the Firestore query shape on the enrichment/privacy-fence path and there are two open competing fixes for #23558 — a maintainer should pick the winner and sign off. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
aryanorastar
left a comment
There was a problem hiding this comment.
On 53415c59ed580e7dbb789e1d72af0072a1f46f99, due_rows in backend/utils/enrichment/outbox.py calls query.start_after(cursor) with a dict. Firestore needs the document snapshot, which the sweep pager already passes as page[-1]. The unit test only accepts that dict on a fake query.
|
@aryanorastar Addressed in
|
|
Verdict: the production fix is correct and tightly scoped, and the cursor issue from the earlier maintainer review is addressed on this head - re-review plus one deployment check remain before merge. Since the earlier CHANGES_REQUESTED (on 53415c5): addressed - By file:
Performance/cost: this trades queries for correctness - a backlog prefix of leased/dormant/privacy-fenced rows now costs one extra query per ~100 stale rows per claim call (the old code silently missed runnable work past the first page, which is the bug). A per-claim page cap or persisted resume cursor is the natural follow-up if backlogs grow. USER IMPACT: after a worker outage or large backlog, enrichment now drains fully instead of stalling behind the first 100 rows; no visible app change. Still wanted before merge:
Leaving for @aryanorastar's re-review of the cursor fix; the index check above is the one deployment fact fakes cannot prove. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
2c0453e to
0068571
Compare
|
@aryanorastar Rebased cleanly onto current |
aryanorastar
left a comment
There was a problem hiding this comment.
due_rows in backend/utils/enrichment/outbox.py is still one limit() page with no start_after. This head pages with query.start_after(page[-1]). test_due_rows_passes_real_firestore_document_snapshot_cursor pins the snapshot cursor. Hygiene and the backend unit suite passed.
|
Verified on head 0068571 — the fix is correct and well-scoped; no blocking issues from my side. What I checked:
Performance: with zero actionable rows, Privacy/lease fencing is unchanged and still enforced in USER IMPACT: none directly visible — enrichment work (e.g., delayed summaries/reprocessing) that could previously stall behind a block of leased or deleted rows now drains reliably. Nice-to-haves, non-blocking: a test where the page-boundary row is deleted between pages mid-iteration (the value-based cursor should sail past it — worth pinning since the PR description claims it), and that scan-budget metric if With the maintainer approval already on this exact head, I'm clearing needs-maintainer-review and keeping positive-signal. Ready from my side; the merge call stays with a human maintainer. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
The production change here is correct and tightly scoped; nothing blocking from my side. Verified on the current head:
Performance: one watch item, not blocking — USER IMPACT: none — internal change; the user-visible effect is that enrichment backlog items no longer stall indefinitely behind leased or deleted conversations. Nothing further required from my side; @aryanorastar has already approved this head. Optional nice-to-have: a metric or log line for documents scanned per Automated review on behalf of the Omi maintainers; merge decisions remain with human maintainers. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
7f6e7ad to
f2905ea
Compare
Git-on-my-level
left a comment
There was a problem hiding this comment.
Since the last automated review (2026-10-31, pre-rebase head): addressed — the branch is now rebased onto current main, resolving the base drift · still open — nothing blocking; the optional scanned-docs-per-claim metric remains a nice-to-have · newly introduced — the rebase dropped the emulator-backed conformance tests (PL-004 has no replacement), and CI is red on a file this PR does not touch.
Verdict: the production fix remains correct and is not superseded (current main still carries the old 100-row-capped due_rows), but one coverage regression introduced by the rebase should be fixed before merge.
Re-verified on head f2905ea:
- backend/utils/enrichment/outbox.py — due_rows pages by (due_at, name) with start_after(page[-1]) (DocumentSnapshot cursor) and short-page termination; identical to the previously approved logic.
- backend/database/outbox_firestore.py — claim() keeps the n <= 0 guard, page_size = max(1, min(100, max(32, n * 4))), and the len(claims) >= n break, so paging stays bounded by the actionable claim budget.
- backend/tests/unit/test_outbox_firestore.py — the paged fake (<=100-doc pages, dict cursors rejected) plus test_pl002_live_lease_prefix_cannot_hide_runnable_work, test_pl002_retired_privacy_prefix_cannot_consume_the_claim_budget, test_pl003_explicit_backlog_budget_is_not_silently_capped_at_100, and the protobuf-level snapshot-cursor test are all present and pin the starvation and budget invariants at unit level.
What the rebase dropped: backend/tests/integration/test_outbox_conformance.py at this head is byte-identical to main. The emulator-backed PL-002/PL-003 conformance runs and the PL-004 (failed-wake vs successful-repair accounting) test cited by earlier reviews and the maintainer approval are gone, and PL-004 has no unit-level replacement. Please restore the PL-004 coverage (and ideally the emulator conformance runs), or note why they no longer apply after the rebase. The PR body also still advertises conformance tests this head no longer adds — worth aligning.
CI: Backend unit suite fails in tests/unit/test_home_transcribing_hold.py — a duration-guard trip (1.00s > 1.00s CPU on one test; all tests in the file pass), in a file untouched by this diff. That looks like main-lane timing noise rather than this change, but the suite does need to be green before merge.
Performance: unchanged from prior review — reads per claim() grow from a hard <=100 to O(due backlog) when due-but-unclaimable rows accumulate, bounded by the n-claims break; the intended trade for fixing the starvation.
USER IMPACT: none directly visible — enrichment backlog items (e.g. delayed summaries) stop stalling indefinitely behind leased or deleted rows.
Action items: (1) restore PL-004 coverage; (2) align the PR body's test-coverage claim with this head; (3) re-run or rebase past the unrelated timing-guard failure so the unit suite is green. The maintainer approval predates this rebase, so a quick re-confirm once the tests are back would close this out.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
f2905ea to
6c22a98
Compare
|
Thanks for the catch @Git-on-my-level! Addressed on
cc @aryanorastar ready for quick re-confirmation whenever convenient. |
|
Rebased onto latest |
6c22a98 to
9d8e53b
Compare
Both concerns from this review are resolved on head 9d8e53b: PL-004 coverage now has a unit replacement (test_pl004_failed_wakes_are_errors_until_a_repair_actually_succeeds), and CI is green on this head. No further changes requested.
|
Since my last review: addressed — the dropped PL-004 coverage now has a unit replacement (test_pl004_failed_wakes_are_errors_until_a_repair_actually_succeeds pins the failed-wake accounting: errors (0,0,0,3) -> repair rewoken (3,0,0,0) -> settled (0,0,0,0), with wake_check_after untouched while wakes fail), and CI is green again on this head · still open — nothing blocking · newly introduced — nothing. Verdict: the production fix is correct and tightly scoped; everything I asked for on the previous head is settled, and I have no blocking issues left. Verified on 9d8e53b:
Performance: sequential pages of <=100, pulled only until the n-claim budget fills; worst case scans a long leased/retired due-prefix, which is exactly the starvation case this fixes. Cost: Firestore reads scale with that prefix; no other spend. Blast radius: claim_key CAS lease fencing and the row filter set are unchanged, so paging cannot double-claim rows and no new data leaves the pipeline. One merge-time follow-up: #24591 added strict xfail markers to the emulator conformance runs of pl002/pl003 (backend/tests/integration/test_outbox_conformance.py, pinned to #23558). Once this lands those tests should pass — drop that xfail block in the same merge or an immediate follow-up so the suite flips green instead of XPASS-red. USER IMPACT: none — internal change; enrichment reprocessing recovers from large backlogs instead of skipping or stalling overdue work. Ready from my side — left for a maintainer to re-approve the current head (only a test-only delta plus rebase since @aryanorastar's approval) and merge. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Fixes #23558
Summary
utils.enrichment.outbox.due_rowsto stream due candidates in bounded per-query pages (<= 100) ordered by(due_at, __name__)and advance across pages viaquery.start_after(page[-1])(DocumentSnapshotcursor, matchingsweep()), surviving concurrent source-row deletion mid-scan.FirestoreEnrichmentOutbox.claim(n, ...)to guardn <= 0and consume paged candidates until the actionable claim budgetnis satisfied or the due set is exhausted, keeping per-query pages bounded while preserving privacy and lease CAS fences.backend/tests/unit/test_outbox_firestore.pycoveringPL-002(101 live-leased prefix rows and 101 privacy-fenced retired prefix rows),PL-003(explicit claim budget of 125 eligible due rows across multiple<= 100pages without silent clamping),PL-004(failed-wake error accounting vs unthrottled subsequentsweeprepair accounting across paged streams), protobuf-levelDocumentSnapshotcursor serialization, and mid-scan page-boundary row deletion. (Note: the matchingPL-002/PL-003/PL-004emulator conformance tests inbackend/tests/integration/test_outbox_conformance.pyalready landed onmainin test(backend): inventory lifecycle writers and latch invariants #24591, which is why that file has no diff after rebasing onto currentmain.)UI-Evidence: none -- Backend Firestore enrichment outbox pagination fix; no UI changes.
Failure-Class: FC-bounded-discovery-pinned-by-blocked-page