Repository navigation
fix(scheduler): write last_run_at only after backend accepts the run - #4659
trinity-ability wants to merge 1 commit into
Conversation
…4655) Previously last_run_at was set at fire time, before the HTTP call to the backend. A dispatch exception (container unavailable, queue full, network error) would leave last_run_at freshly updated — a schedule that never reached the model looked healthy to any liveness monitor reading that field. Move the last_run_at write into _dispatch_and_record_outcome, after the backend returns any response. The exception path only advances last_run_at when the backend demonstrably ran the execution (already-finalized row or pull-queue ownership); a genuinely failed dispatch (unclaimed RUNNING row, backend never received the request) leaves last_run_at unchanged. next_run_at is still advanced at fire time so the scheduling window is consumed even on dispatch failures (existing #1472 invariant preserved). Also updates test_2514_scheduler_pull_gaps._make_db to include the agent_schedules table, which is now required by the exception path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
merge-train (2026-11-19): not on this train. Validated at
#4655 says "set only once the run is accepted by the model". The scheduler cannot know that; only the backend can, at the point the run actually starts on the agent. So the fix probably belongs on the backend side, with the scheduler no longer writing the column on the dispatch path at all. Say on the issue if you read the criterion differently. Smaller: a dispatch timeout now leaves
|
Summary
last_run_atwrite from fire time to inside_dispatch_and_record_outcome, after the backend returns any responselast_run_at, so liveness monitors can detect schedules that silently fail on every ticknext_run_atis still advanced at fire time to mark the scheduling window consumed (bug: enabled schedule shows "Next: 1d ago" — stale next_run_at, cron fires silently skipped with no execution record #1472 invariant preserved)last_run_atis advanced only when the backend demonstrably ran the execution (already-finalized row or pull-queue ownership); an unclaimed RUNNING row (backend never received the request) leaves it unchangedtest_2514_scheduler_pull_gaps._make_dbto includeagent_schedules, now required by the exception pathCloses #4655
Test plan
TestPhantomFireDoesNotAdvanceLastRunAt::test_dispatch_exception_leaves_last_run_at_unchanged— core defect: exception must not advancelast_run_atTestPhantomFireDoesNotAdvanceLastRunAt::test_dispatch_exception_unclaimed_running_is_marked_failed— sanity: execution is still marked failedTestSuccessfulDispatchAdvancesLastRunAt::test_success_response_advances_last_run_atTestSuccessfulDispatchAdvancesLastRunAt::test_dispatched_response_advances_last_run_atTestSuccessfulDispatchAdvancesLastRunAt::test_failed_response_advances_last_run_at— backend ran it and failed → still advancesTestExceptionWithFinalizedRow::test_already_finalized_row_advances_last_run_at— SCHED-ASYNC-001: scheduler timeout, backend already finished → advancetest_2514_scheduler_pull_gapstests still pass🤖 Generated with Claude Code