Repository navigation
feat(jobs): schedule the daily hard delete on the Worker and the server - #343
Merged
Merged
Conversation
schedules.rs holds SCHEDULES (the outbox sweep every minute and the hard delete at `0 0 * * *`, ADR-0072), job_for_cron, run_job and run_cron, and next_utc_midnight_after, the time a timer that stands for the midnight cron wakes at. A cron string that is not in the table runs no job, so a trigger nobody wired cannot become a second sweep. Nothing calls it yet: the Worker's handler and the server's timers come in the next commit. tests/schedules.rs has 16 tests: the table is the one the ADR and the issue name; each job has one schedule; a trigger runs the job of its schedule, and no string that is not exactly a cron of the table runs one (generated near misses: a space more, a field fewer, other numbers, the empty string); the hard delete's cron deletes the old work item and publishes nothing, the sweep's publishes and deletes nothing, and an unlisted cron changes nothing; and next_utc_midnight_after is the first midnight strictly after any instant, with the instants at a midnight and just before one weighted in, and no midnight after the last day the type has. Control: mutant_cron_ignored (the trigger is not read, so every cron runs the sweep) fails 4 of the 16 and is row 66 of scripts/mutants.sh, which the driver reports KILLED on its needle. The row count in test.yml and cicd.md is 66. Refs: #59 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…'s timer The Worker's `scheduled` handler swept whatever fired. It now hands the trigger's own cron string to run_cron and runs the job of the schedule that has it; a string the table lacks runs nothing and is logged. Each wrangler file that carries triggers (wrangler.toml, the deploy template and the two Stage configs) gets `0 0 * * *` beside the every-minute one. The native server has no cron: a task sleeps to the first 00:00 UTC strictly after the last it ran for, so a wake a moment early cannot run a day twice, and after a late wake (a suspended host) it carries on from now and does not replay the days it slept through. It is always on, as the Worker's trigger is. The sweep timer is unchanged but for calling run_job, which drops the second copy of 100. deploy_parity.py reads the `cron: "..."` literals of schedules.rs (comment lines dropped first) and requires every file's triggers.crons to be exactly them: in the two-file comparison, and for the two Stage files, which nothing compared, through `--crons`. test-deploy-template.sh shows each way it can be wrong (56 checks, 11 new, under dash and bash): a trigger or a schedule missing, one extra, one twice, a cron added to both files and not to the code, a table that gains a third schedule (the same files are then right, so the check follows the code and not a number), a cron quoted in a comment, and a source that cannot be read or has none. The `other-cron` control could no longer match a two-entry list, and is rewritten. Refs: #59 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… not on the sweep's worker_cron_scheduled_handler_runs_the_hard_delete fires the two crons of SCHEDULES at the Worker's `scheduled` handler through --test-scheduled. A work item that is deleted and past its window is still there after the sweep's cron (the one that delivers its events first, so that nothing is handled after the work item is gone) and gone after the hard delete's. It reads the window from /_info and fails on a Worker whose window is not 0 days, which is how it could not pass for want of an old enough row. scripts/contract.sh starts the `cron` pass, and no other, with THRUST_HARD_DELETE_AFTER_DAYS=0, and unsets both windows for every pass so that a developer's own never reach a target (the `sweeper` pass reads its window from /_info). worker-dev.sh forwards both. The `cron` pass is 2 tests in contract.sh and in stage2-contract.sh, which check-contract-counts.sh agrees with. Run here, on worker-memory with wrangler 4.151.2 and worker-build 0.9.0: 2 of 2 pass. Control, by hand: the handler made to read no cron (it passes "* * * * *" whatever fired) fails the new test after its 20 s wait and leaves the old sweep test passing, which could not have told. The worker-cf cells run in CI. Refs: #59 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Dated "Update - issue #59" sections in ADR-0072 (the table is built; no build script, a parity guard instead; one place runs a job; the job runs inline in bounded batches and does not enqueue; the server's timer needs no leader election), ADR-0046 (the 90-day purge of dispatched outbox rows; an undispatched row is never purged) and ADR-0043 (the purge rule, what goes with a work item, what stays; the header of migration 0014 is stale and is not edited, for its checksum). TRACEABILITY's F-D10 row was cut off mid-parenthesis in two cells and is restored, and says what is built; FEATURES and PLAN.md say so too. status.md has G-50 with what is covered, what was shown failing, and five things that are not shown (a real daily trigger on a deployed Worker, the server's timer loop, a large first backlog, the four tables not purged, the worker-cf cells run in CI only). infra.md, flows/app.md, architecture/app.md and the contract-suite page describe the second cron, the schedules table, the hard delete's rules and the `cron` pass's window of 0. Refs: #59 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
temporarily deployed
to
preview-control-plane
November 20, 2026 21:17 — with
GitHub Actions
Inactive
…-delete # Conflicts: # docs/src/testing/status.md
aRustyDev
temporarily deployed
to
preview-control-plane
November 20, 2026 22:07 — with
GitHub Actions
Inactive
aRustyDev
added a commit
that referenced
this pull request
Nov 22, 2026
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
added a commit
that referenced
this pull request
Nov 22, 2026
… stage 8) #343 made the Worker's cron handler hand the trigger's own cron string to thrust_core::run_cron, so the sentence that said its only effect is a log line over the sweeper was no longer exactly right. What a trigger runs is tested natively (crates/core/usecases/tests/schedules.rs and outbox.rs) and by the contract suite's cron pass on the Worker, which now also has worker_cron_scheduled_handler_runs_the_hard_delete. `cargo mutants --list` on the merged tree gives the same 52 mutants as before, with only scheduled's line moved (428 to 432); they were not run again, and the documents say so. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
added a commit
that referenced
this pull request
Nov 22, 2026
…phase, stage 8, G-6) (#345) * test(worker): wasm32 unit tests of the Worker's glue (Test phase, stage 8, G-6) The Worker's configuration reading, composition root, queue consumer and fetch entry point exist only on wasm32, so nothing native reached them: only the worker-memory and worker-cf cells did, over HTTP. crates/worker/src/wasm_tests.rs holds 14 #[wasm_bindgen_test] functions, run by wasm-bindgen-test-runner on Node through nextest's new `workers` profile (scripts/wasm-tests.sh: one runner process per test, and a count guard that every declared test ran). cargo-mutants on crates/worker/src/lib.rs through the same runner, by hand (.cargo/mutants-wasm.toml): 52 mutants, 43 caught, 8 unviable, 1 missed (`scheduled`, whose only effect is a log line; the contract suite's cron pass covers it). Before the fetch and queue tests it was 33 caught and 11 missed. scripts/wasm-test-runner.sh is cargo's runner for wasm32: it refuses a runner that is not the lock's wasm-bindgen exactly (asked of `cargo pkgid --locked`) and loads scripts/lib/workerd-stubs.cjs, which stands in for the workerd-only modules, and the FixedLengthStream global, that the Worker's wasm imports. [profile.wasm-test] drops debug info: 20 s a test with it, 1.85 s without. The host is Node, not workerd as ADR-0123 names: no public runner hosts Rust unit tests inside workerd. Cargo.lock gains 10 packages, all from wasm-bindgen-test, a wasm32-only dev-dependency of thrust-worker. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * ci(test): the workers job runs the Worker's wasm32 tests, in the plan and the gate (Test phase, stage 8) A job in test.yml that runs scripts/wasm-tests.sh: Node from web/.node-version, the wasm32 target, and wasm-bindgen-test-runner installed at the version `cargo pkgid --locked wasm-bindgen` reads from Cargo.lock (taiki-e/install-action, checksummed). Cache key wasm-workers, saved on main only. ADR-0102 allows no advisory job in a called workflow, so it is in the planner from the start (JOBS, WORKFLOWS, planned when thrust-worker is affected, and a rule for its scripts), in the verdict's needs and jobs, and in the dispatch default plan. Tests, each with controls: test-wasm-tests.sh (46 checks, in the ci-scripts list; sh and dash), test_plan_ci.py, test_workflow_wiring.py, test-ci-scripts.sh (workers among test.yml's jobs: 209 cases) and mutate_gate.py (270 of 270 mutants killed, none survived). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs: the workers job and G-6 (Test phase, stage 8) running.md (the workers profile, the script, the job and a runbook for a red one), cicd.md (the job, how it is planned, and the examples table run again through the planner, which showed two rows already out of date), status.md G-6 (what is built, the cargo-mutants result with its one survivor, what is still open, and the departure from ADR-0123), the defect matrix X8, real-backends.md, AGENTS.md's Commands table and the workflows README. The phase document gets its stage 8 section: the survey, the custom code with its probes, the measurements and the pass log. The plan's status lines said no stage of the phase had started; they now say where it stands. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs: the numbers of stage 8 after merging main (15 tests, the retention windows) 15 tests and not 14: the new one covers the two retention windows #340 added to the Worker's configuration. Run again on the merged tree: 15 of 15 pass, and cargo-mutants on crates/worker/src/lib.rs has the same result (52 mutants, 43 caught, 8 unviable, 1 missed, `scheduled`, now at line 428). The times are recorded as measured, both runs: the same script took 4.5 s on 14 tests and 7.6 s on 15, and the same 52 mutants 6 m 25 s and 11 m 32 s, and the phase document says that it is not known whether that is load or the merged code. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * ci(test): run the workers job on Node 26, which can load the Worker's cloudflare: imports The first CI run of the job failed all 15 tests on Node 22.22.0, the web jobs' pin (web/.node-version), with ERR_INTERNAL_ASSERTION ("a bug in Node.js") at ModuleLoader.getModuleJobForRequire. Everything had passed locally, on Node 26.9.0. The runner's glue is CommonJS and require()s the Worker's inline JavaScript snippets, which are ES modules that import `cloudflare:workers` and its like. Node's require(esm) path asserts that an import specifier's protocol is file:, node: or data:, before any resolve hook is asked, so scripts/lib/workerd-stubs.cjs cannot help. Reading lib/internal/modules/esm/loader.js of every release from 22.15 to 25.9: every 22 and 23 asserts (22.23.5 is the last 22), 24 asserts before 24.12.0, 25 before 25.2.0, and 26 has no such code. The job pins Node 26.13.1. scripts/wasm-test-runner.sh refuses an older Node in words, so that nobody reads "a bug in Node.js"; test-wasm-tests.sh holds each boundary with stand-in nodes and a broken copy of the wrapper for each (66 checks), test_workflow_wiring.py holds the pin to 26 or later, and mutate_gate.py changes it three ways (272 of 272 mutants killed). The runbook, the status row and the phase document say what happened. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs: the first CI numbers of the workers job (Test phase, stage 8) Run 44825424412, green in every job, gate included: the workers job took 92 s with a cold cache (the cache is saved on main only), 35 s of it the wasm build and 19 s the 15 tests on the runner's 4 cores; it is on no critical path (the run took 8 m 41 s, set by the cells). The first run, 44822700250, failed workers alone on Node 22.22.0; that is in the phase document already. Passes 2 and 5 of the stage are updated: 2 holds, 5 has its cold number and waits for a run on main for the warm one. The helper counts are the ones after the Node guard (66 checks, 168 wiring checks, 272 mutants). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs: what scheduled does after #343, and what covers it (status G-6, stage 8) #343 made the Worker's cron handler hand the trigger's own cron string to thrust_core::run_cron, so the sentence that said its only effect is a log line over the sweeper was no longer exactly right. What a trigger runs is tested natively (crates/core/usecases/tests/schedules.rs and outbox.rs) and by the contract suite's cron pass on the Worker, which now also has worker_cron_scheduled_handler_runs_the_hard_delete. `cargo mutants --list` on the merged tree gives the same 52 mutants as before, with only scheduled's line moved (428 to 432); they were not run again, and the documents say so. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * fix(deps): url 2.5.9 and form_urlencoded 1.2.3 (RUSTSEC-2026-0592) url 2.5.8 and earlier overflow the stack in `Url::origin()` on a nested `blob:` URL, which aborts the process and which catch_unwind does not catch. The advisory appeared after the last green run, so `cargo deny` fails on main's own Cargo.lock too: security / deny, and so gate, is red for any change that touches Cargo.lock or a manifest. `cargo update -p url --precise 2.5.9`: a plain `cargo update -p url` locks nothing, and the precise form moves url and its one dependency form_urlencoded (1.2.2 to 1.2.3), four lines each way in the lock and no other package. url is reached through ammonia, bollard, lettre and oauth2. It is unrelated to the stage-8 work of this pull request and was folded in at the owner's word, as its own commit. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs: say that the url bump is in this pull request and the stage changed no package (stage 8) The phase document's Cargo.lock row said no existing package changed. The stage still changed none; the url and form_urlencoded bump for RUSTSEC-2026-0592 is in the same pull request, as its own commit, and the row says so and says why. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 22, 2026
Merged
This branch was previously deployed
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.
What
The third of three PRs for #59 (the daily hard delete, F-D10, D-001). #336 added the database half and #340 the job, its two windows and the admin routes. Until now the job ran only when
POST /internal/retentioncalled it. This schedules it, and it is the one that finishes the issue.schedules.rs(crates/core/usecases):SCHEDULES(the outbox sweep,* * * * *, and the hard delete,0 0 * * *),job_for_cron,run_job,run_cron, andnext_utc_midnight_after. A cron string that is not exactly one of the table's runs no job.scheduledhandsevent.cron()torun_cron. It used to sweep whatever fired. A cron the table lacks runs nothing and is logged.0 0 * * *is in the four wrangler files that carry triggers (wrangler.toml, the deploy template and the two Stage configs; the memory and measure configs have none, and tests fire a cron at them with--test-scheduled).run_job.deploy_parity.pyreads thecron: "…"literals ofschedules.rsand requires every file'striggers.cronsto be exactly them, in the two-file comparison and, through a new--cronsmode, for the two Stage files, which nothing compared before.cronpass is 2 tests incontract.shandstage2-contract.sh; it is the only pass started withTHRUST_HARD_DELETE_AFTER_DAYS=0, andcontract.shunsets both windows for every pass so a developer's own never reach a target.worker-dev.shforwards both.status.mdG-50, and the infra, flows and contract-suite pages.ADR-0072's sketch had a build script that renders the table into wrangler, jobs that enqueue, and leader election for the self-hosted timer. Built instead: the parity guard (the crons stay literal in the files), the job inline in bounded batches (50 of 100 work items and 100 of 1,000 outbox rows a run,
complete: falsewhen it stops there, the next day carries on), and no election (one process holds the database, ADR-0070). The ADR update says why.Tests
crates/core/usecases/tests/schedules.rs, 16 tests: the table is the one the ADR and the issue name; each job has one schedule; a trigger runs its schedule's job and no string that is not exactly a cron of the table runs one (generated near misses: a space more, a field fewer, other numbers, the empty string); the hard delete's cron deletes the old work item and publishes nothing, the sweep's publishes and deletes nothing, an unlisted cron changes nothing; andnext_utc_midnight_afteris the first midnight strictly after any instant, with exact midnights and the last second before one weighted in, and no midnight after the last day the type has.worker_cron_scheduled_handler_runs_the_hard_delete(worker_only.rs, thecronpass): fires the sweep's cron and then the hard delete's at the Worker through--test-scheduled. A work item that is deleted and past its window is still there after the sweep's cron and gone after the hard delete's. It reads the window from/_infoand fails on a Worker whose window is not 0.test-deploy-template.sh: 56 checks (11 new), under dash and bash. A trigger or a schedule missing, one extra, one twice; a cron added to both files and not to the code (the files agree with each other, so only the table can say it is wrong); a table that gains a third schedule, which makes the same files right (so the check follows the code and not a number of crons); a cron quoted in a comment, which is not a schedule; a source that cannot be read or has none. Theother-croncontrol could no longer match a two-entry list and is rewritten.Shown failing
mutant_cron_ignored(the trigger is not read): fails 4 of the 16 and is row 66 ofscripts/mutants.sh, which the driver reports KILLED on its needle (its trigger ran OutboxSweep). The row count is 66 (test.yml,cicd.md).* * * * *whatever fired), by hand, asmutants.shbuilds no Worker: the new Worker test fails after its 20 s wait and the old sweep test still passes, so it could not have told.contract.shdrops the panic text of a failing contract test, so that it is the last wait that failed is an inference: the first wait is the same call the unmutated run passed in under a second.Run here:
cargo fmt,clippy --workspace --all-targetsand the Worker's wasm32 clippy, 4,882 hermetic tests and the doctests; everyci-scriptsanddepscommand, 59 of 60 (test-deploy-target.shfails here with 39 bad as it did before this PR's changes, and passed in CI on #340; it reads none of the files this PR changes); theworker-memorycronpass, 2 of 2, on wrangler 4.151.2 andworker-build0.9.0. Theworker-cfcells run in CI.Not shown (G-50)
0 0 * * *trigger firing on a deployed Worker. The handler is shown through--test-scheduled, as the sweep's was in round 26, and the every-minute trigger has a Stage 2 test of the real firing; a daily one cannot be waited for the same way.After this
projects,states,labelsandassetsalso carrydeleted_atand are not purged: the owner scoped #59 to work items and the outbox, and a follow-up issue for the four is drafted, to be filed on the owner's say. #59's own text mentions listing withscope=with_deleted, which has no route; the read the tests use isGET /internal/work-items/{id}.Closes #59
🤖 Generated with Claude Code