Skip to content

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
truffle-dev:fix/scheduler-update-action-86
Open

scheduler: add phantom_schedule update action so editing a job preserves run history (#86)#96
truffle-dev wants to merge 1 commit intoghostwright:mainfrom
truffle-dev:fix/scheduler-update-action-86

Conversation

@truffle-dev
Copy link
Copy Markdown

Summary

Adds action: "update" to phantom_schedule so an active job's task, description, schedule, delivery, or enabled can be changed in place by jobId or name. Run history (last_run_at, last_run_status, last_run_duration_ms, last_run_error, run_count, consecutive_errors) and the stable jobId are preserved. When schedule changes, next_run_at is recomputed via the same computeNextRunAt path resumeJob uses, then armTimer() 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: JobUpdateInputSchema parallel to JobCreateInputSchema. All five fields optional with a refine() rejecting an empty object so a no-op update can never reach the service.
  • src/scheduler/tool.ts: update added to the action enum and the switch. enabled added to the tool params. Resolves the target by jobId ?? findJobIdByName(name), matching delete and run. TOOL_DESCRIPTION updated.
  • src/scheduler/service.ts: updateJob(id, partial) builds a dynamic SET clause over user-authored columns only. Mirrors create-validation's slack-target check on delivery, runs validateSchedule on schedule, and recomputes next_run_at plus calls armTimer() when the schedule is touched.
  • Tests in service.test.ts and tool.test.ts: 9 new cases covering task-in-place + history preserved, schedule-change recomputes next_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, or schedule is delete + create. That drops last_run_at, run_count, consecutive_errors, last_run_error, and the stable jobId, 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 additive update action is the smallest fix that closes the drift loop without changing the storage model.

name is intentionally not editable: it is the case-insensitive lookup key for delete, run, and update, and renaming mid-life would silently break any caller that resolves by name. Pause/resume already cover lifecycle status, so enabled here is the admin-disable boolean, not the lifecycle column.

Test plan

  • bun test src/scheduler/ -> 124 pass, 0 fail (including 9 new cases).
  • bun test full suite -> 1930 pass, 9 pre-existing fails on main unrelated to this change (email-login, config-loader, init, prompt-assembly).
  • bun run lint clean.
  • bun run typecheck clean.
  • No em dashes.

Open questions

  • Audit log: the issue mentions scheduler_audit_log; I did not find such a table in the current scheduler code. Happy to wire update into one if it lands separately.
  • task_source_path: deliberately out of scope here, per the issue's Option 2 framing as a follow-up.

…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.
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.

scheduler: phantom_schedule has no update action, so editing a job's task drops run history

1 participant