Repository navigation
fix(scheduler): fire-and-forget dispatch to prevent APScheduler skips (#132) - #328
Merged
Merged
Conversation
…#132) The scheduler's job function was blocking on DB polling after dispatch, causing APScheduler to skip subsequent triggers when max_instances=1. Changes: - _call_backend_execute_task() now spawns asyncio.create_task(_poll_and_finalize()) and returns immediately with "dispatched" status - _execute_schedule_with_lock() updates last_run_at immediately on dispatch (for missed-schedule detection on restart) - Background tasks tracked in _active_poll_tasks set for graceful shutdown - 4 new tests for fire-and-forget behavior The job function now returns in ~30s (dispatch timeout) instead of blocking for the full execution timeout (up to 1hr), so APScheduler never hits max_instances and never skips triggers. Co-Authored-By: Claude Opus 4.5 <[email protected]>
vybe
added a commit
that referenced
this pull request
Apr 14, 2026
Co-Authored-By: Claude Opus 4.5 <[email protected]>
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
asyncio.create_task()— no more blockinglast_run_atupdated on dispatch (not completion) for missed-schedule detectionProblem
APScheduler's
max_instances=1caused triggers to skip when the job function blocked on DB polling (up to 1hr). Even though the agent had available slots, the scheduler's Python job was still running (waiting for completion), so APScheduler refused to fire the next trigger.Solution
True fire-and-forget: after backend accepts the dispatch, spawn a background task to poll and publish WebSocket events. The job function returns in ~30s (dispatch timeout) instead of blocking for the full execution timeout.
Changes
src/scheduler/service.py_poll_and_finalize()background task,_active_poll_taskstracking, immediatelast_run_atupdatetests/scheduler_tests/test_async_dispatch.pydocs/memory/feature-flows/scheduler-service.mddocs/planning/ORCHESTRATION_RELIABILITY_2026-04.mdTest Plan
last_run_atupdate, graceful shutdownCloses #132
🤖 Generated with Claude Code