Skip to content

fix(scheduler): soft-deleted agent's schedules stop firing on the sync path (#1427) - #1436

Merged
vybe merged 1 commit into
devfrom
feature/1427-scheduler-softdelete-agent
Jul 3, 2026
Merged

vybe merged 1 commit into
devfrom
feature/1427-scheduler-softdelete-agent

Conversation

@dolho

@dolho dolho commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On eu2, agent ff-scorer was soft-deleted (agent_ownership.deleted_at set, container removed) but its schedule ff-auto stayed enabled=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) 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 firing every cron tick.

list_all_enabled_schedules() (the startup load) already joins agent_ownership and 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() now LEFT JOINs agent_ownership and reports a schedule as disabled when its parent agent is soft-deleted. This makes the existing enabled→disabled transition in _sync_agent_schedules remove 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 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

Verification

tests/scheduler_tests/test_1427_soft_deleted_agent_schedules.py (4, against the real SchedulerDatabase + schema):

  • live agent → schedules report enabled;
  • soft-deleted agent → enabled schedules report disabled (→ sync removes jobs) while the DB rows stay enabled=1;
  • recovery (clear deleted_at) → re-enabled;
  • parity with 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 that PUT .../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

…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]>
@dolho
dolho requested a review from vybe July 3, 2026 10:52

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@vybe
vybe merged commit afed02b into dev Jul 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants