Repository navigation
fix(jobs): the monthly queue has no autoRun entry, so its jobs never run - #880
Conversation
…fire
A task `schedule` only enqueues, and only while an `autoRun` cron for its own
queue ticks: Payload calls `handleSchedules({ queue })` from that cron and
nowhere else. `jobs.autoRun` named `nightly` and `screening` only, with
`loginPlugin` appending `invitations`, so the two schedules on `monthly` were
never consulted — no error, no log line, no job row. Neither had run in any
environment since they were added, which is why #715 fixed a crash on "the only
path that runs in production" while that path never ran.
`SyncLectureMetadata` now has its queue driven. The tick is hourly rather than
monthly because it is both halves of the cycle: it enqueues the due schedule
with `waitUntil` at the next occurrence, and a later tick runs that row, so the
tick interval is the worst-case lateness.
`CleanupOrphanedMedia` moves to `manual`, which nothing ticks, instead. Its
Phase A permanently deletes everything already in the media trash with no age
check at all — an editor's own hand-trashed items included — and a first run
after ten dead months would also trash up to 500 newly detected orphans. It
needs an age threshold on `deletedAt` and a reviewed dry run before it may run
unattended. The Files description claimed the opposite, so it goes too.
The pairing now lives in `src/jobs/queues.ts`, where a queue either has an entry
or carries the reason it has none.
Refs #878
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PyYVG8KQF1UnngE5RB26Vd
The defect #878 found leaves no trace: a schedule on a queue with no `autoRun` entry is never consulted, so there is nothing to notice. The spec pairs the two sides instead — every queue a task schedules onto either has an entry or sits in `UNSCHEDULED_QUEUES` with the reason nothing may start it. Four more assertions close the ways the first one could pass vacuously. An `allQueues` entry would satisfy any queue at all and silently override `queue`, so no entry may carry one. A queue may not be both driven and excused, since the reason would then read as protection while the job runs anyway. And the array the spec reads is only worth anything while the config hands that same array to Payload, which is checked as source text because importing `payload.config.ts` would build the whole config. Every assertion was watched failing against the real defect: the `monthly` entry removed, `CleanupOrphanedMedia` back on `monthly`, the config passing a slice instead, an `allQueues` entry added, `nightly` excused, and the plugin's append dropped. Refs #878 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PyYVG8KQF1UnngE5RB26Vd
… tick Three findings from the review pass on this branch. The guard read `tasks` from `src/jobs/index.ts` only, so it missed the two tasks a plugin appends to `jobs.tasks` — `resetUsageTask` and `sendInvitationsTask`. Both are fine today, but that is exactly the seam #878 came through: a plugin task scheduling onto a dead queue would have passed. It now reads all three sources, and a sweep of every `schedule: [` site under `src/` fails until a new one is added to that list, so the hand-written part cannot go quietly stale. The `monthly` tick moves to :30. Every tick rewrites the whole `payload-jobs-stats` global from the snapshot it read, so queues ticking on the same minute lose one `lastScheduledRun` to the other's write. Minute 0 already carries three tickers; this one no longer joins them. `jobs:run --queue manual` was documented as the way to run CleanupOrphanedMedia and does nothing: without `--handle-schedules` it only drains rows that already exist, and nothing enqueues onto `manual`. A command that prints nothing and exits 0 is the #878 failure mode over again, so the docs now say to queue it from the admin Jobs UI. Also drops a spec that re-proved `loginPlugin`'s autoRun append from source text while `login-plugin.spec.ts` already proves it from the executed plugin, and moves the Phase A reason to one home with pointers to it. Refs #878 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PyYVG8KQF1UnngE5RB26Vd
`jobs:run --queue monthly` claims the row the autoRun tick enqueued, and that row's `waitUntil` is the schedule's next occurrence, so it runs only in the window the tick would have run it anyway. The admin Jobs UI is the trigger for an immediate run. Refs #878 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PyYVG8KQF1UnngE5RB26Vd
|
🚅 Deployed to the SahajCloud-pr-880 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
Right size for #878, and the new module earns its place: MANUAL_QUEUE from jobs/index.ts would cycle through CleanupOrphanedMedia. The guard is the weak part — the stagger does not stagger, and the assertion that should prove it cannot fail.
Findings
- should-fix —
queues.ts:56::30collides withinvitations(*/5) andscreening(*/15) hourly. - should-fix —
job-schedules.spec.ts:93: compares cron strings, so no real collision fails it. - should-fix —
Files.ts:26:(#878)reaches an editor's screen. - should-fix —
SyncLectureMetadata.ts:30(no thread): its docblock still namesjobs:run --queue monthlyas the manual trigger. - consider —
CleanupOrphanedMedia.ts:106: deleting the schedule answers your open question.
Checked. payload/dist/index.js:237+ — handleSchedules({ queue }) runs only from that queue's cron. defaultAfterSchedule.js — the stale-snapshot rewrite is real. Every schedule: under src/ plus both plugin tasks: only these two name monthly. Arming it exposes nothing else.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`:30` is not a free minute. `screening` is `*/15` and `invitations` is `*/5`, so both fire at :30 as well — the new entry joined a three-way overlap instead of avoiding one, and every tick rewrites the whole `payload-jobs-stats` global from the snapshot it read. `:07` is a multiple of neither step. Refs #878 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fv2eRVvfiBNaaP5VKaZmuH
The collision guard compared minute fields as strings, so `0`, `30` and `*/15` read as three distinct values while `*/15` fires at :00 and :30 alike — no real collision could fail it. It also read only `JOB_AUTO_RUN`, leaving the plugin's `*/5` invisible. It now expands each field to its minutes and folds in `INVITATIONS_CRON`. The three overlaps that predate #878 are pinned as a shrink-only backlog rather than excused by the comparison. Refs #878 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fv2eRVvfiBNaaP5VKaZmuH
The collection description lands on a non-technical editor's screen, where `(#878)` reads as noise. What it pointed at — why nothing deletes orphans unattended — is in `UNSCHEDULED_QUEUES`, for a reader who can follow it. Refs #878 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fv2eRVvfiBNaaP5VKaZmuH
The docblock still named `jobs:run --queue monthly` as the manual trigger, the one place the sweep in c64753d missed. Same defect as the two it fixed: the command drains a row already past its `waitUntil` and otherwise exits 0. Refs #878 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fv2eRVvfiBNaaP5VKaZmuH
|
Addressed the adversarial review. Pushed Adopted
Asked
Lean gate green. Both touched integration specs pass. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Phase A deleted every trashed item with no age check, which is the whole reason the job sat on a queue nothing ticks. It now deletes only trash older than TRASH_RETENTION_DAYS, so an item an editor hand-trashed survives at least one full cleanup cycle, and `dryRun` counts both phases without writing — the way a window or a threshold gets reviewed against real data before a scheduled run acts on it. With that in place the job goes back on `monthly`, per review. The queue nothing ticks is gone; `UNSCHEDULED_QUEUES` stays as the dead-schedule guard's exemption, empty. The two new cases are appended rather than filed under Phase A: every fixture here creates a `files` row, and the Lexical reference scan collects upload ids without regard to collection, so inserting a case mid-file shifts later file ids onto image ids and spares them as "referenced". That aliasing is a defect in the job, reported separately. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WYbpCRvkk72EkQqLEqsyoe
|
Railway's preview build failed. I cannot read its log — no Railway credential or MCP tool reaches that dashboard — so this one needs an attended look. Nothing pushed. The code at
Evidence it is not this branch:
Two environment-side suspects I could not test: this is the first preview carrying #894, and three builds ran at once behind the 23:19Z merge to Next step: open the 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
Railway is healthy again, so this needs a redeploy, not a debug. New since my last comment: #892 built green on Railway at 23:41Z, 18 minutes after this PR's 23:23Z failure. The failure recurred nowhere else. I re-verified the code independently at Nothing pushed. There is nothing on this branch to fix, and no Railway credential reaches that dashboard from a routine. Next step: redeploy the failed build. This was CI fix 2 of 3, so the next red event spends the last one on the same finding. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
main (#880) moved `jobs.autoRun` out of `payload.config.ts` into `JOB_AUTO_RUN` in `src/jobs/queues.ts`, while this branch added a `transcription` entry to the inline array. Both sides are kept: the config takes main's `autoRun: JOB_AUTO_RUN` — which `job-schedules.spec.ts` asserts as source text — and the transcription safety net moves into `JOB_AUTO_RUN`. Its cron changes from `*/15` to `3-59/15`. #880 added the rule that two queues ticking on the same minute lose one `lastScheduledRun` to the other's write, and `*/15` collided with `screening`, `invitations` and `nightly`. :03 and every 15th minute after clears all three and `monthly`'s :07, keeping the 15-minute worst-case lateness the entry was written for. `src/payload-types.ts` and `importMap.js` regenerated: both already matched the textual merge. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01K3UtS1SCwASAkNJri3QE7w
main (#880) moved `jobs.autoRun` out of `payload.config.ts` into `JOB_AUTO_RUN` in `src/jobs/queues.ts`, while this branch added a `transcription` entry to the inline array. Both sides are kept: the config takes main's `autoRun: JOB_AUTO_RUN` — which `job-schedules.spec.ts` asserts as source text — and the transcription safety net moves into `JOB_AUTO_RUN`. Its cron changes from `*/15` to `3-59/15`. #880 added the rule that two queues ticking on the same minute lose one `lastScheduledRun` to the other's write, and `*/15` collided with `screening`, `invitations` and `nightly`. :03 and every 15th minute after clears all three and `monthly`'s :07, keeping the 15-minute worst-case lateness the entry was written for. `src/payload-types.ts` and `importMap.js` regenerated: both already matched the textual merge. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01K3UtS1SCwASAkNJri3QE7w
Summary
SyncLectureMetadatanow runs on its monthly schedule — themonthlyqueue had noautoRunentry, so nothing ever consulted it.CleanupOrphanedMediaruns monthly too, unattended, which is what the review asked for. What makes that safe is Phase A's new age threshold: it permanently deletes only trash older than 45 days, where before it deleted everything in the media trash with no age check at all.month % 3bands cancelled out against the clock, so uploads from 8 months in 12 were never scanned at all.dryRuninput counts and logs both phases without writing, so a window or a threshold can be reviewed against real data before a scheduled run acts on it.autoRunentry and no stated exemption, and on the next tick that shares a minute with another.Changes
src/jobs/queues.ts— new. TheautoRunarray, plusUNSCHEDULED_QUEUES, the dead-schedule guard's exemption registry (empty today).src/payload.config.ts—jobs.autoRunnow reads that array.src/jobs/CleanupOrphanedMedia/CleanupOrphanedMedia.ts—TRASH_RETENTION_DAYSandtrashDeletionCutoff,orphanScanWindowin place of themonth % 3bands, thedryRuninput and output, and themonthlyqueue.tests/unit/job-schedules.spec.ts— new. The dead-schedule guard, the minute-collision guard, and the cleanup job's queue, dry run, and — across two years of runs — its retention and scan coverage.tests/int/cleanup-orphaned-media.int.spec.ts— the retention cases, Phase A fixtures aged past the cutoff, and one scan-window case in place of the three per-band ones.src/collections/Files/Files.ts— the editor-facing copy, which now has an automatic cleanup to describe.src/jobs/SyncLectureMetadata/SyncLectureMetadata.ts,docs/architecture.md— the manual trigger is the admin Jobs UI, notjobs:run.Preview
monthlytick has runTest results
cleanup-orphaned-media.intManual verification
Nothing here can be tested on production before merge.
dryRunand the retention cutoff exist only on this branch, so a cleanup queued on production today runsmain's Phase A, which permanently deletes the whole media trash. Do not queuecleanupOrphanedMediaon production until this merges.Merging is safe on its own. Payload computes a schedule's first
waitUntilas the cron's next occurrence afterlastScheduledRun, which is unset for a queue that has never ticked — so there is no catch-up for missed months, and the first cleanup is 2026-11-01 00:00 UTC (checkQueueableTimeConstraints, payload 3.90.2).Before merge:
monthlyrows forcleanupOrphanedMediaandsyncLectureMetadatahavewaitUntilat the next 1st of the month. This is the same first-tick path production will take.After merge, before 2026-11-01:
waitUntilin the past, the next :07 tick runs it — delete it.payload-jobsdoc (admin-only) withtaskSlug: "cleanupOrphanedMedia",queue: "monthly"andinput: { "dryRun": true }. The next :07 tick runs it. ⚠dryRunmust be the booleantrue: the handler checks=== true, so the string"true"runs for real.deleteJobOnCompletedeletes the row on success.Orphaned media cleanup completedhas the counts, and eachWould permanently delete …/Would move orphaned … to trashline names a file. Review the names, not just the counts.syncLectureMetadatarun. It touches everyfulllecture at up to 10 concurrent Nirmala Vidya fetches with retries, and has never run before, so the backlog is the whole collection.Notes for reviewer
Three judgement calls, and two pre-existing defects I did not fix.
Hourly, not daily, for a monthly schedule. Payload's tick is both halves of the cycle — it enqueues with
waitUntilat the next occurrence, and a later tick runs the row — so the tick interval is the worst-case lateness. A daily tick gives tighter determinism for ~30 ticks a month instead of ~744; I chose hourly so a tick lost to a deploy costs an hour rather than a day. That is also whynightlyticks hourly and always has:SendSessionRemindersis itself an hourly schedule on it.45 days is the retention, and it is a constant, not an input. It has to outlast the longest month, not match the cadence. Runs fall 28 to 31 days apart, and at 30 a run after any 31-day month deleted the previous run's trash one run later — 7 runs in 12. At 45, what one run trashes survives the next run with two weeks to spare, and goes at the one after. Exposing it would make the one number that stands between an editor and an irreversible delete settable per run.
Phase B scans a span, not a band. It used to pick one of three one-month bands (0-1, 1-2 or 2-3 months old) by
month % 3. The band and the clock both advance a month per run, so all three runs of a quarter scanned the same calendar month (December, March, June, September). Each run now scans uploads from 24 hours to 3 months old. I chose that over "the previous month only": it keeps the three checks per upload the bands were meant to give, and a missed run loses nothing. The cost is that the first run scans three months of uploads rather than one.Pre-existing, worth a ticket (1):
scanCollectionForLexicalReferencesextracts every upload and relationship id out of Lexical content generically, with no regard to which collection the id belongs to, and those ids go into thefilesreferenced set and theimagesone alike. So an image referenced in a gallery block spares the file with the same numeric id, as Phase B reads it. That is a silent under-collection, not an over-collection, so nothing is deleted wrongly — orphans are just skipped forever. It surfaced here because the two new cases shifted this spec's file ids by two and one landed on a referenced image id; they are appended rather than filed under Phase A for that reason, with the⚠saying why.Pre-existing, worth a ticket (2):
defaultAfterSchedulerewrites the entirepayload-jobs-statsglobal from the snapshot its ownhandleSchedulescall read, so two queues ticking on the same minute lose one queue'slastScheduledRunto the other's write.nightly,screeningandinvitationsalready overlap at :00, andinvitationsandscreeningagain every 15 minutes. The newmonthlyentry is staggered clear of all three at7 * * * *, andKNOWN_COLLISIONSin the spec pins the existing three as a shrink-only backlog.I did not file either issue — this repo asks before creating one.
Detail
What this review round changed. The reviewer reversed the ticket: #878's Approach step 2 had
CleanupOrphanedMediamove to a queue nothing ticks, and the decision is that it should run monthly like everything else on that queue. Its own thread asked for the production testing that would make that safe.Both halves landed. The age threshold is what the earlier
UNSCHEDULED_QUEUESreason named as the blocker, so adopting the direction meant implementing the blocker rather than just deleting the guard around it. ThedryRuninput is the other half of that reason — "a dry run reviewed against production" — turned into something a human can run in one click, since a routine cannot reach production and should not try.MANUAL_QUEUEis gone with the queue it named.UNSCHEDULED_QUEUESstays, empty: it is the exemption the dead-schedule guard reads, so the next queue deliberately left undriven is one entry there rather than an edit to the spec.The spec's assertion changed shape with it.
keeps CleanupOrphanedMedia off every queue that ticksasserted the old decision. It is now three assertions: the job is onmonthlyandmonthlyis driven; the cutoff is at least 30 days back (since tightened — see below); and bothdryRunfields exist. The queue alone is no longer the safety property, so pinning it alone would have been pinning the weaker half.Watched failing.
spares trash newer than the retention cutoffwas watched red withless_than: trashCutoffremoved from Phase A's query — the exact defect, at the site that caused it — then restored. The two int Phase A cases that previously trashed their fixture atnew Date()now age it 60 days; left as they were, they passed for the wrong reason, since a just-trashed item is precisely what the threshold spares.What the earlier review passes changed. The first version of the guard read only
tasksfromsrc/jobs/index.ts, which excludes the two tasks a plugin appends tojobs.tasks:resetUsageTask(usagePlugin) andsendInvitationsTask(loginPlugin). Both are fine today, but that is the seam this ticket is about. It now reads all three sources, and a sweep of everyschedule: [site undersrc/fails until a new one is added to that list.The stagger also did not stagger at first:
:30is a multiple of both 5 and 15, so the new entry fired alongsideinvitations(*/5) andscreening(*/15) hourly. And the guard that should have caught it compared cron minute fields as strings, so0,30and*/15read as three distinct values while*/15fires at :00 and :30 alike.minutesOfnow expands each field to the minutes it fires on, andALL_CRONSfolds inINVITATIONS_CRON.Review round 3 (
cf883df6). It fixed two defects in the date arithmetic: the 30-day retention and themonth % 3scan bands, both above. Neither shows in a single run, so no existing case could catch them. The unit spec now pins both across two years of runs, and both cases were watched failing against the old arithmetic: 13 early deletions and 425 unscanned days. The three per-band int cases became one span case. It creates six files in the old order, so no file id changes outcome, and deletes them afterwards. Otherwise those files, trashed at a mocked 2025 date, read as expired trash to the throughput case's Phase A and use up its operation budget.Fixture note. The unit spec writes no fixture. Its one constructed value is
sendInvitationsTask({} as LoginCollectionConfig): the factory reads nothing off its argument to buildschedule. Everything else is the real exported task config, the realJOB_AUTO_RUN, or the realINVITATIONS_CRON. The one source-text read,autoRun: JOB_AUTO_RUNinsrc/payload.config.ts, is there because importing the config would build it; it is what stops the whole spec asserting over an array production does not use.No security findings over this round's diff. The widened surface is one boolean input that can only suppress writes, and a
whereclause that can only narrow a delete.Closes #878
🤖 Generated with Claude Code
https://claude.ai/code/session_01WYbpCRvkk72EkQqLEqsyoe