Skip to content

fix(sync): unblock backfill queue with owner deferral and NotFound resilience (#21122) - #21811

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
hardik4love-lang:fix/sync-backfill-sweep-resilience-21122
Oct 16, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
hardik4love-lang:fix/sync-backfill-sweep-resilience-21122

Conversation

@hardik4love-lang

@hardik4love-lang hardik4love-lang commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Fixes #21122 by resolving the escalating 500 error rate, 100% NotFound exceptions, and head-of-line blocking in the sync-backfill-uid-sequencer scheduler sweep:

  1. Owner Deferral on Reconcile Error: In �ackend/utils/sync/uid_sequencer.py (sweep()), when
    econcile_uid() encounters an error, the owner is now deferred by HEARTBEAT_SECONDS (
    egistry.defer_owner(owner['uid'], registry.HEARTBEAT_SECONDS, now=now)). Previously, failing owners remained with
    econcile_at <= now and were re-queried on every tick, filling all 100 query slots of due_owners(limit=100) and permanently starving the remaining 50+ users with pending backfills.
  2. Firestore NotFound Resilience: In �ackend/database/sync_backfill_sequencer.py, wrapped transactional commits in defer_owner,
    edrive_job, �egin_job, and
    enew_job with except NotFound: handlers (aligning with defer_pending). Missing or concurrently deleted documents are safely treated as non-fatal instead of crashing with unhandled 500 exceptions.
  3. Query Resilience: Guarded
    egistry.due_owners() and
    egistry.due_pending() in sweep() against transient query timeouts, recording due_owners_error / due_pending_error while allowing remaining sweep phases to progress safely.
  4. Hermetic Test Suite: Added 5 new unit tests in �ackend/tests/unit/test_sync_backfill_uid_sequencer.py asserting that failing owners are deferred and unblock subsequent owners, query exceptions are tolerated without crashing, and NotFound during defer_owner and
    edrive_job does not raise.

Product invariants affected

none

How it was verified

Verified via hermetic pytest unit test suite (81/81 passing in 4.25s) covering:

  • est_sweep_defers_failing_owner_and_unblocks_healthy_owners
  • est_sweep_tolerates_due_owners_query_failure
  • est_sweep_tolerates_due_pending_query_failure
  • est_defer_owner_tolerates_missing_document
  • est_redrive_job_tolerates_missing_document

Tests

�ackend/tests/unit/test_sync_backfill_uid_sequencer.py

UI evidence

UI-Evidence: none -- Backend sync backfill scheduler and Firestore resilience logic verified via unit tests.

Failure class (fixes)

Failure-Class: none

View guided diff

@hardik4love-lang

Copy link
Copy Markdown
Contributor Author

Hi @beastoin, @Git-on-my-level,

All CI contracts and automated test gates are now 100% green:

This resolves the head-of-line queue starvation and unblocks the backfill sequencer for Issue #21122. Ready for review and merge!

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed all three changed files on the current head.

backend/database/sync_backfill_sequencer.py — the four new except NotFound guards (begin_job, renew_job, defer_owner, redrive_job) mirror the existing defer_pending handling and are semantically right: NotFound -> False in begin_job/renew_job reads as a stale claim so the worker abandons cleanly, NotFound -> None in redrive_job maps to sweep's existing 'raced' outcome, and defer_owner's guard matches defer_pending. NotFound is already imported in this module, so no NameError concern.

backend/utils/sync/uid_sequencer.py — deferring a failing owner by HEARTBEAT_SECONDS in sweep()'s error handler matches the existing lock_held deferral pattern and is what actually unblocks the bounded due_owners page for healthy owners (#21122). Guarding due_owners/due_pending so one failed query doesn't abort the whole tick is the right shape for a scheduler loop. Two non-blocking notes: (1) the inner 'except Exception: pass' around the deferral call silently swallows all failures — consider logging the exception type there for observability; (2) the broad excepts on the two queries will also catch programming errors such as TypeError, though the logged exception_type keeps that debuggable.

backend/tests/unit/test_sync_backfill_uid_sequencer.py — the two-tick failing/healthy owner test directly exercises the unblocking behavior, and the NotFound tolerance tests pin the new return contracts. Well-targeted suite, thank you.

No blocking issues found. Since this changes the retry cadence and failure semantics of the production sync scheduler, it needs a human maintainer sign-off before merge.

— automated maintainer review on behalf of the Omi maintainers


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

@Git-on-my-level Git-on-my-level added backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge labels Oct 16, 2026

@kodjima33 kodjima33 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.

hardik4love-lang backend fix: fixes #21122, filed by trusted contributor beastoin (NOT self-filed) - no self-bounty concern despite account's other flagged PR. Clear root cause, scoped diff, CI green, 5 regression tests. Confirmed bug real on main. 5/5, merges.

@kodjima33
kodjima33 merged commit 9424460 into BasedHardware:main Oct 16, 2026
55 of 56 checks passed
@hardik4love-lang

Copy link
Copy Markdown
Contributor Author

Thank you @kodjima33, @beastoin, and @Git-on-my-level for reviewing and merging! Glad to have this critical P1 sync backfill outage resolved.

Bounty Claim Details

@kodjima33 @josancamon19

@hardik4love-lang

Copy link
Copy Markdown
Contributor Author

Hi @kodjima33, @josancamon19,

Following up on bounty settlement for merged PR #21811 (Issue #21122):

Whenever the batch disbursement runs, please confirm. Thank you!

@hardik4love-lang

Copy link
Copy Markdown
Contributor Author

Hi @kodjima33, @josancamon19,

Quick follow-up with our official support desk ticket references for the 5 merged PRs:

  1. Master Consolidated Ticket: We have logged Support Ticket #146152932 covering all 5 merged PRs (fix(ble): retry failed codec reads and prevent defaulting to PCM8 (#20779) #21524, fix(sync): unblock backfill queue with owner deferral and NotFound resilience (#21122) #21811, fix(bee): support 3-byte millivolts battery format and clamp legacy percentage (#21749) #21768, fix(watch): stop Apple Watch recording when disconnecting or forgetting device (#20780) #21521, and fix(deploy): specify --cpu=2 for backend-sync to support 6Gi/8Gi memory (#21668) #21671 for \ total).
  2. Housekeeping: Ticket #146152932 supersedes earlier Ticket #145972803 (which had claimed fix(watch): stop Apple Watch recording when disconnecting or forgetting device (#20780) #21521 and fix(deploy): specify --cpu=2 for backend-sync to support 6Gi/8Gi memory (#21668) #21671), so #145972803 can be closed/merged to avoid any duplicate accounting.
  3. Payout Details: PayPal [email protected]

Additionally, our 6 completed PRs in the merge queue (#23806, #23706, #23841, #23659, #23689, #23842 - \ total) have passed all tests and maintainer review sign-off checks.

Whenever the finance batch disbursement runs against Ticket #146152932, please confirm. Thank you!

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

Labels

backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sync-backfill-uid-sequencer scheduler sweep returning intermittent HTTP 500

3 participants