fix(automation): keep completed once tasks completed on schedule re-anchor (#504) - #514
Draft
TYRMars wants to merge 1 commit into
Draft
fix(automation): keep completed once tasks completed on schedule re-anchor (#504)#514TYRMars wants to merge 1 commit into
once tasks completed on schedule re-anchor (#504)#514TYRMars wants to merge 1 commit into
Conversation
…-anchor (#504) `recomputeNextRun` hard-coded `previousRun = undefined` when re-seeding `next_run_at`. For an `interval` schedule that's harmless, but for a `once` schedule `last_run_at` is the only "already fired" signal, so passing `undefined` resurrected a finished one-shot: it wrote the original, now-past `run_at` back into `next_run_at`, making the task immediately due again on the next tick. The caller fires on any PATCH carrying a `schedule` key — including a UI that re-sends the unchanged object on save — so editing an unrelated field (rename, model change) would silently re-execute the one-shot prompt's real side effects (backup / report / deploy). Anchor on the task's own `last_run_at` instead. A never-run task still has `last_run_at === undefined`, so interval re-anchoring is unchanged; a completed `once` now stays completed. Adds a regression test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ShHwvKnfC9aaPhXxn5kpMp
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
Fixes #504.
recomputeNextRun(packages/automation/src/task.ts) hard-codedpreviousRun = undefinedwhen re-seedingnext_run_atafter a schedule edit. For anintervalschedule that's harmless, but for aonceschedulelast_run_atis the only "already fired" signal — so passingundefinedresurrected a finished one-shot: it wrote the original, now-pastrun_atback intonext_run_at, making the task immediately due again on the next tick.The single caller (
automation-routes.tsPATCH handler) fires on any request carrying aschedulekey — including a UI that re-sends the unchanged object on save — so editing an unrelated field (rename, model change) would silently re-execute the one-shot prompt's real side effects (backup / report / deploy).Fix
Anchor on the task's own
last_run_atinstead ofundefined:last_run_at === undefined, sointervalre-anchoring is byte-for-byte unchanged.once:last_run_atis present →scheduleNextAfterreturnsundefined→ the task stays completed.last_run_at + interval; the existing skip-forward loop still guarantees a result strictly afternow.Tests
oncestaysnext_run_at === undefined/ not-due afterrecomputeNextRun.node --test packages/automation/src/task.test.ts→ all 22 tests pass. (The unrelatedstore.test.tsfailure is pre-existing in this environment —@jarvis/storeis not installed — and reproduces on the untouched tree.)🤖 Generated with Claude Code
https://claude.ai/code/session_01ShHwvKnfC9aaPhXxn5kpMp
Generated by Claude Code