Repository navigation
fix(scheduler): soft-deleted agent's schedules stop firing on the sync path (#1427) - #1436
Merged
Merged
Conversation
…ync path Soft-deleting an agent (#834) sets agent_ownership.deleted_at and removes the container, but leaves the child schedule row untouched (enabled=1, deleted_at NULL, same updated_at). The standalone scheduler's live-sync (_sync_agent_schedules) reads list_all_schedules(), whose query filtered only the schedule's OWN deleted_at — no agent_ownership join. So the transition diff saw no change and never removed the already-registered APScheduler job: it kept dispatching into the nonexistent container, HTTP ConnectError every cron tick (26 failed executions on eu2 ff-scorer/ff-auto, polluting failure analytics). list_all_enabled_schedules() (the startup load) already joins agent_ownership and skips these; this closes the same gap on the live-sync path. Rather than mutate schedule rows, list_all_schedules() now LEFT JOINs agent_ownership and reports a schedule as DISABLED when its agent is soft-deleted, so the existing enabled->disabled transition removes the job — and because agent recovery clears agent_ownership.deleted_at, the disabled->enabled transition re-adds it. Symmetric with #834 recovery, no schedule-row soft-delete, no recovery churn. The method is called only by _sync_agent_schedules, so the effective-enabled override is contained to the sync view. Verified: tests/scheduler_tests/test_1427_soft_deleted_agent_schedules.py (4, against the real SchedulerDatabase + schema) — live agent -> enabled; soft-deleted agent -> schedules report disabled while DB rows stay enabled=1; recovery -> re-enabled; parity with list_all_enabled_schedules. Related to #1427 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
vybe
approved these changes
Jul 3, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Validated via /validate-pr: surgical LEFT-JOIN fix on the sync read path, rows untouched (recovery-symmetric with #834), named regression tests incl. recovery + startup-path parity. All required checks green, security sweep clean.
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
On eu2, agent
ff-scorerwas soft-deleted (agent_ownership.deleted_atset, container removed) but its scheduleff-autostayedenabled=1/deleted_at IS NULL, so the scheduler kept dispatching it into the nonexistent container — 26 failed executions (HTTP error: ConnectError) over three days, polluting failure analytics.Root cause
Soft-deleting an agent (#834) leaves the child schedule row untouched (enabled=1, deleted_at NULL, same
updated_at). The standalone scheduler's live-sync (_sync_agent_schedules) readslist_all_schedules(), whose query filtered only the schedule's owndeleted_at— noagent_ownershipjoin. So the transition diff saw no change and never removed the already-registered APScheduler job; it kept firing every cron tick.list_all_enabled_schedules()(the startup load) already joinsagent_ownershipand skips these — the gap was only on the live-sync path a running scheduler uses after the agent is deleted mid-run.Fix (
src/scheduler/database.py)list_all_schedules()nowLEFT JOINsagent_ownershipand reports a schedule as disabled when its parent agent is soft-deleted. This makes the existingenabled→disabledtransition in_sync_agent_schedulesremove the job — and because agent recovery clearsagent_ownership.deleted_at, thedisabled→enabledtransition re-adds it. Symmetric with #834 recovery, no schedule-row mutation, no recovery churn. The method is called only by the sync loop, so the effective-enabled override is contained to the sync view.Companion to #1423 (same #834 gap on the webhook trigger path).
Acceptance criteria
agent_schedules.deleted_atset.Verification
tests/scheduler_tests/test_1427_soft_deleted_agent_schedules.py(4, against the realSchedulerDatabase+ schema):enabled=1;deleted_at) → re-enabled;list_all_enabled_schedules(startup set already excludes them).Note: verified at the sync-view/DB layer (the exact fix point); the full running-scheduler loop reconciliation (
enabled→disabled⇒_remove_job) is pre-existing, covered behavior. The issue also flagged thatPUT .../schedules/{id}is accepted for a soft-deleted agent — left as-is (out of scope; not the firing bug).Related to #1427
🤖 Generated with Claude Code
Closes #1427