Skip to content

knowledge/lease: #20614 follow-ups — in-flight source overlap after lease loss, a second _REFRESH_LUA, client factory outside the try #20766

Open

Description

@mrveiss

Follow-ups from #20614's review (#20556)

Three findings, not blocking #20614:

  1. A source in flight when the lease is lost can overlap with the next run. fix(knowledge): one sync at a time per connector, and say when one didn't start (#20556) #20614 stops a sync before its next source once the lease is lost (raise_if_sync_lease_lost). A source already being fetched or ingested finishes after the loss, and a new run that took the expired key can process the same source at the same time. Ingest is keyed by source id, so this is a double write, not a loss. One-sync-per-connector still isn't strict in that window. Options: check ownership again before the ingest write of each source, or make the per-source write conditional on the lease.
  2. _REFRESH_LUA is written twice. autobot_shared/leader_lease.py holds the canonical compare-and-extend script (tech-debt(schedulers): leader-election logic duplicated verbatim across two schedulers #12835 consolidated it). autobot-backend/llc/sync/outbound_sync.py:48 keeps its own copy and its own _try_acquire_or_refresh. This is the same twice-defined pattern tech-debt(schedulers): leader-election logic duplicated verbatim across two schedulers #12835 removed. outbound_sync should use LeaderLease. LeaderLease.update_leadership ends leadership on a Redis error, not only on a lost lease #20736 covers its update_leadership semantics.
  3. LeaderLease._attempt calls get_async_redis_client outside its try. In autobot_shared/leader_lease.py, a client factory that raises, rather than returning None, escapes as an exception instead of the "unknown" (None) result that hold_or_refresh turns into 503 or a retry. Move the call inside the try.

Acceptance criteria

  • A source in flight at lease loss can't be written by two runs at once, with a test.
  • One _REFRESH_LUA: outbound_sync uses LeaderLease.
  • A raising Redis client factory reads as unknown (None) in _attempt, with a test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't workingphase:M1.8Knowledge base: upload, web sources and chat retrieval work end to endpriority: medium

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions