Skip to content

fix(enrichment): advance cursor past excluded rows and refill pull claims (#23558) - #23569

Open
huynhnhatquandongnai-source wants to merge 1 commit into
BasedHardware:mainfrom
huynhnhatquandongnai-source:fix/firestore-enrichment-outbox-cursor-paging
Open

huynhnhatquandongnai-source wants to merge 1 commit into
BasedHardware:mainfrom
huynhnhatquandongnai-source:fix/firestore-enrichment-outbox-cursor-paging

Conversation

@huynhnhatquandongnai-source

Copy link
Copy Markdown

Summary

Fix bounded-discovery starvation in Firestore enrichment outbox pull claims (closes #23558).

  • In �ackend/utils/enrichment/outbox.py: update due_rows to page using an explicit Firestore cursor (start_after) so that full pages of live-leased or dormant rows do not hide subsequent runnable rows. Remove the silent clamp to 100 so explicit backlog budgets (e.g. 125) are honored.
  • In �ackend/database/outbox_firestore.py: update FirestoreEnrichmentOutbox.claim to refill candidate rows when earlier candidates retire via privacy-fencing or non-claim outcomes, guaranteeing that actionable claim budgets are fulfilled up to
    .
  • Add hermetic unit regression tests in �ackend/tests/unit/test_enrichment_outbox_paging.py validating all three parity invariants.

Product invariants affected

  • KB PL-002: 101 earlier live-leased rows cannot hide the next runnable row from one pull claim.
  • KB PL-002: 101 earlier privacy-fenced rows retire without consuming the actionable claim budget.
  • KB PL-003: An explicit claim budget of 125 returns all 125 eligible due rows without silent cap at 100.

Validation

  • Ran hermetic regression suite: �ackend/tests/unit/test_enrichment_outbox_paging.py (3 passed in 1.2s).
  • Ran existing outbox test suite: �ackend/tests/unit/test_outbox_firestore.py (21 passed in 1.3s).
  • Total: 24 passed clean, zero failures.

Failure-Class: FC-bounded-discovery-pinned-by-blocked-page

…aims (BasedHardware#23558)

## Summary
Fix bounded-discovery starvation in Firestore enrichment outbox pull claims (refs BasedHardware#23558).

- In `backend/utils/enrichment/outbox.py`: update `due_rows` to page using an explicit Firestore cursor (`start_after`) so that full pages of live-leased or dormant rows do not hide subsequent runnable rows. Remove the silent clamp to 100 so explicit backlog budgets (e.g. 125) are honored.
- In `backend/database/outbox_firestore.py`: update `FirestoreEnrichmentOutbox.claim` to refill candidate rows when earlier candidates retire via privacy-fencing, guaranteeing that actionable claim budgets are fulfilled up to `n`.
- Add hermetic unit regression tests in `backend/tests/unit/test_enrichment_outbox_paging.py` validating all three parity invariants.

## Product invariants affected
- KB PL-002: 101 earlier live-leased rows cannot hide the next runnable row from one pull claim.
- KB PL-002: 101 earlier privacy-fenced rows retire without consuming the actionable claim budget.
- KB PL-003: An explicit claim budget of 125 returns all 125 eligible due rows without silent cap at 100.

Failure-Class: FC-bounded-discovery-pinned-by-blocked-page
@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: the fix is correct and well scoped — no blocking issues found; two small follow-ups below.

Verified against #23558 (maintainer-filed parity report):

  • backend/utils/enrichment/outbox.py — due_rows now pages with a document-snapshot cursor (start_after), so a full page of leased/dormant rows can no longer hide later runnable rows. Firestore snapshot cursors break due_at ties by document ID, so pagination is stable, and the loop terminates on empty or short pages. Dropping the min(100, ...) clamp honors explicit budgets (the 125-row case). Cost note: due_rows keeps reading 100-doc pages until it accumulates limit eligible rows, so a claim pass over a mostly-leased backlog reads more documents per call than before — bounded by the due set, and exactly the bounded-discovery semantics the issue asked for.
  • backend/database/outbox_firestore.py — the refill loop in claim() terminates correctly: every iteration either claims (capped at n), discards (shrinks the due set), or breaks when nothing was claimed or discarded; STALE/BUSY candidates cannot livelock because a no-progress iteration exits. Privacy-fenced (DISCARDED) rows now retire without consuming the actionable budget, and the lease/privacy CAS fences in claim_key are untouched.
  • backend/tests/unit/test_enrichment_outbox_paging.py — pins all three invariants from Firestore enrichment outbox pull claims starve behind excluded rows and silently cap at 100 #23558 hermetically and restores the module global it patches. I ran this file plus tests/unit/test_outbox_firestore.py and tests/unit/test_dream_scheduler.py on this head: 50 passed.

Follow-ups (non-blocking):

USER IMPACT: none directly — internal reliability fix; users would at most notice enrichment/summaries no longer lagging behind a backlog of leased or privacy-retired rows.

Leaving for human maintainer review: this is a data-pipeline surface from a first-time contributor and emulator qualification is still open, so maintainer sign-off before merge.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8c09757 backend/utils/enrichment/outbox.py rewrites due_rows with its own cursor and leaves out the DocumentSnapshot start_after from #23565. The outbox_firestore refill loop is a second class.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Firestore enrichment outbox pull claims starve behind excluded rows and silently cap at 100

3 participants