fix(scheduler): break updated_at feedback loop in sync (#420) - #424
Closed
dolho wants to merge 1 commit into
Closed
Conversation
`update_schedule_run_times` unconditionally bumped `updated_at` to now on every call, but _sync_agent_schedules uses `updated_at` as its change- detection signal. Flow: _add_job → update_schedule_run_times (bumps updated_at) → next sync tick reads mismatched updated_at → thinks config changed → calls _add_job again → loop forever at the sync interval. With 13 schedules this produced ~545 re-adds/schedule in 8h, ~120 MB/day of log noise that grows linearly with fleet size and risks masking real scheduler bugs. Fix: `update_schedule_run_times` now updates only last_run_at/next_run_at as requested, never updated_at. Bookkeeping is not a config change. The sync loop's change detection still catches legitimate edits (cron, message, timezone, enabled) because those go through a different write path that correctly bumps updated_at. Also fixed the dead-code backend copy in db/schedules.py for consistency. Live verify: pre-fix 58 "Added schedule job" lines in 30 min with 1 schedule; post-fix 1 startup Add, then silent across 3 sync cycles. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dolho
force-pushed
the
fix/420-scheduler-sync-loop
branch
from
April 20, 2026 11:07
a98d651 to
f190c92
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #420.
The scheduler re-registered every enabled schedule once per sync tick (60s), logging ~2 lines per schedule per minute. With 13 schedules in the field that was ~780 INFO lines/hour → ~120 MB/day of log noise, wasted CPU, and a latent hazard: any real scheduler bug gets buried under the flood.
Root cause
Infinite feedback loop between
update_schedule_run_timesand_sync_agent_schedules:Fix
`update_schedule_run_times` is now strictly bookkeeping: it updates `last_run_at` / `next_run_at` as requested and never touches `updated_at`. Legitimate config edits (cron, message, timezone, enabled) go through other methods (`update_schedule`, `set_schedule_enabled`) that correctly bump `updated_at` — sync's change detection still catches those.
Secondary: if called with both args `None`, the method now no-ops instead of emitting an invalid `UPDATE SET , WHERE`.
Applied to:
Test plan
Out of scope
🤖 Generated with Claude Code