Skip to content

refactor(llc/scheduler): extract PollLoopScheduler base (start/stop/_loop/is_running duplicated across 4+ schedulers) #9842

Description

@mrveiss

Duplication: LLC schedulers re-implement identical poll-loop scaffolding

Each LLC background scheduler hand-rolls the same start/stop/poll-loop lifecycle:
self._running flag, self._task: Optional[asyncio.Task], start() → asyncio.create_task(self._loop(), name=...), stop() → cancel task, is_running property, and _loop() → while self._running: <work>; await asyncio.sleep(self._poll_interval).

Verified near-identical across:

  • llc/scheduler/budget_watchdog.py
  • llc/scheduler/liveness_monitor.py
  • llc/scheduler/routine_scheduler.py
  • llc/scheduler/session_checkpointer.py
    (heartbeat_scheduler.py is richer but follows the same shape.)

Proposed fix

Extract a PollLoopScheduler base (e.g. llc/scheduler/base.py) owning start/stop/is_running/_loop + a configurable poll interval and task name; subclasses implement only _check_once() (the per-tick work). Mirrors the SubprocessLifecycleAdapter consolidation (#9834).

Labels: enhancement · backend · priority: low

Activity

  1. mrveiss commented on Jun 11, 2026

    @mrveiss
    OwnerAuthor

    Closed — merged to Dev_new_gui via PR #10003 (squash commit 333d60bcc).

    Criteria met:

    • PollLoopScheduler base (llc/scheduler/base.py): start/stop/is_running/_loop + configurable poll interval and task name; subclasses implement only _tick()
    • BudgetWatchdog, LivenessMonitor, SessionCheckpointer migrated — scaffolding removed, tick bodies untouched; all original semantics preserved line-by-line (stop without await, CancelledError breaks, exceptions logged-and-continue, sleep always runs, exact task names); tick failures still attributed to each module's own logger
    • RoutineScheduler deliberately excluded: different lifecycle contract (async startup/shutdown, ensure_future, awaited shutdown) — reviewer-verified justification; heartbeat_scheduler out of scope per issue
    • 11 new base tests (idempotent start, stop-before-start, naming, tick-exception survival, clean cancellation); scheduler suites byte-identical pre/post; rebased cleanly over feat(llc/budget): token-based budget mode with shadow cost tracking (#8997) #9998's watchdog token-mode changes (24/24 combined)
    • Review verdict APPROVE; its double-start re-log finding fixed via start() created-flag

    Discoveries: health-probe session_checkpointer_running KeyError failures are pre-existing on base (noted by reviewer; same family as #9995 isolation issues).

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions