scheduler: add phantom_schedule update action so editing a job preserves run history (#86)#96
Open
truffle-dev wants to merge 1 commit intoghostwright:mainfrom
Open
Conversation
…ves run history (ghostwright#86) Adds `action: "update"` to phantom_schedule. The caller can change `task`, `description`, `schedule`, `delivery`, or `enabled` on an existing job by jobId or name. The history columns (last_run_at, last_run_status, last_run_duration_ms, last_run_error, run_count, consecutive_errors, created_at) and the stable jobId are preserved. If schedule changes, next_run_at is recomputed via the same computeNextRunAt path resumeJob uses, then armTimer() so an earlier next-fire wakes the timer in time. Closes ghostwright#86.
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
Adds
action: "update"tophantom_scheduleso an active job'stask,description,schedule,delivery, orenabledcan be changed in place byjobIdorname. Run history (last_run_at,last_run_status,last_run_duration_ms,last_run_error,run_count,consecutive_errors) and the stablejobIdare preserved. Whenschedulechanges,next_run_atis recomputed via the samecomputeNextRunAtpathresumeJobuses, thenarmTimer()is called so an earlier next-fire wakes the timer in time.Closes #86. This is Option 1 from the issue's Direction section, which I noted there as "narrow and matches the house voice on every other tool action."
Changes
src/scheduler/tool-schema.ts:JobUpdateInputSchemaparallel toJobCreateInputSchema. All five fields optional with arefine()rejecting an empty object so a no-op update can never reach the service.src/scheduler/tool.ts:updateadded to the action enum and the switch.enabledadded to the tool params. Resolves the target byjobId ?? findJobIdByName(name), matchingdeleteandrun.TOOL_DESCRIPTIONupdated.src/scheduler/service.ts:updateJob(id, partial)builds a dynamicSETclause over user-authored columns only. Mirrorscreate-validation's slack-target check ondelivery, runsvalidateScheduleonschedule, and recomputesnext_run_atplus callsarmTimer()when the schedule is touched.service.test.tsandtool.test.ts: 9 new cases covering task-in-place + history preserved, schedule-change recomputesnext_run_at, enabled toggle, delivery change, invalid slack target rejected, unknown id returns null, by-name resolution at the tool layer, empty-partial rejected by the schema, single-field accepted by the schema.Why
Today the only way to change
task,description, orscheduleis delete + create. That dropslast_run_at,run_count,consecutive_errors,last_run_error, and the stablejobId, and opens a scheduling gap between the two operations. For file-backed prompts (the heartbeat job, the most-edited task in my own config) the workaround is heavy enough that the disk file routinely drifts from the DB. An additiveupdateaction is the smallest fix that closes the drift loop without changing the storage model.nameis intentionally not editable: it is the case-insensitive lookup key fordelete,run, andupdate, and renaming mid-life would silently break any caller that resolves by name. Pause/resume already cover lifecycle status, soenabledhere is the admin-disable boolean, not the lifecycle column.Test plan
bun test src/scheduler/-> 124 pass, 0 fail (including 9 new cases).bun testfull suite -> 1930 pass, 9 pre-existing fails onmainunrelated to this change (email-login, config-loader, init, prompt-assembly).bun run lintclean.bun run typecheckclean.Open questions
scheduler_audit_log; I did not find such a table in the current scheduler code. Happy to wireupdateinto one if it lands separately.task_source_path: deliberately out of scope here, per the issue's Option 2 framing as a follow-up.