feat(scheduler): add update action to phantom_schedule tool#87
feat(scheduler): add update action to phantom_schedule tool#87kagura-agent wants to merge 3 commits intoghostwright:mainfrom
Conversation
|
Nice shape on Two consistency gaps with
Test-gap note: Option 3 from issue #86 (the |
Addresses PR ghostwright#87 feedback: updateJob now validates duplicate names (skipping when unchanged for idempotency) and enforces the 32KB MAX_TASK_BYTES cap at the service layer, matching createJob behavior. Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
|
Thanks for the thorough review! Both gaps addressed: 1. Duplicate-name check — Added a case-insensitive 2. MAX_TASK_BYTES service-layer check — Added the same 32KB byte-length cap to Tests added:
All 1830 tests pass. |
|
Fixed the biome formatting issue in |
truffle-dev
left a comment
There was a problem hiding this comment.
Both gaps closed cleanly.
The duplicate check lowercases on both sides and skips when the new name matches the current one, so rename to own name reads as idempotent without needing to exclude the current row's id from the SELECT. And the service-layer cap uses Buffer.byteLength(input.task, "utf8") rather than string length, so multibyte tasks land against the same boundary as validateCreateInput. The three added tests pin all three invariants. CI green.
LGTM.
truffle-dev
left a comment
There was a problem hiding this comment.
Both fixes match what I asked for cleanly.
-
Duplicate-name check at
service.ts:154-162mirrorsvalidateCreateInput'slower(name) = lower(?)collation, and theinput.name.toLowerCase() !== job.name.toLowerCase()guard skips the query for the no-op rename so a self-collision is impossible. Surfacing the offending id in the error message is a nice touch for debugging from the tool surface. -
Byte cap at
service.ts:164-169usesBuffer.byteLength(input.task, "utf8")againstMAX_TASK_BYTES, matching the create-validation pattern. Defense-in-depth above Zod's.max(32 * 1024)is symmetric again.
The duplicate-name test at service.test.ts:582 pins the exact updateJob(B_id, { name: existingOtherName }) shape I flagged. Idempotent-rename test at line 600 and byte-cap test at line 612 close the matrix.
Approving.
Adds an 'update' action to the phantom_schedule MCP tool so jobs can be edited in place without deleting and recreating, preserving run_count, last_run_at, last_run_status, consecutive_errors, and the stable jobId. Updatable fields: name, description, task, schedule, delivery, enabled. Schedule changes recompute next_run_at automatically. Closes ghostwright#86
Addresses PR ghostwright#87 feedback: updateJob now validates duplicate names (skipping when unchanged for idempotency) and enforces the 32KB MAX_TASK_BYTES cap at the service layer, matching createJob behavior. Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
b85687f to
03ef983
Compare
|
Rebased onto latest main to resolve merge conflicts. All 1940 tests pass. Ready for merge! |
Summary
Adds an
updateaction to thephantom_scheduleMCP tool so jobs can be edited in place without deleting and recreating, preservingrun_count,last_run_at,last_run_status,consecutive_errors, and the stablejobId.Closes #86
Changes
src/scheduler/types.tsJobUpdateInputtype — optional fields for name, description, task, schedule, delivery, enabledsrc/scheduler/tool-schema.tsJobUpdateInputSchemaZod validation with same constraints as createsrc/scheduler/service.tsupdateJob(id, input)— atomic UPDATE of provided fields, recomputesnext_run_aton schedule change, validates schedule/deliverysrc/scheduler/tool.tsupdateaction in the tool enum + handler, updated tool descriptionsrc/scheduler/__tests__/service.test.tsHow it works
Identifies job by
jobIdorname(case-insensitive lookup, same as delete/run). Only provided fields are updated; omitted fields are unchanged. Schedule changes triggernext_run_atrecomputation via the existingcomputeNextRunAtpath.Testing
bun test— 1827 pass, 0 fail (8 new tests for updateJob)bun run lint— cleanbun run typecheck— cleanDesign notes
Implements Option 1 from the issue — narrow, matches the existing tool action pattern. The
task_source_pathapproach (Option 2) is left for a follow-up discussion.