Skip to content

feat(retention): run_retention, its windows and its admin routes - #340

Merged
aRustyDev merged 3 commits into
mainfrom
feat/59-run-retention
Nov 20, 2026
Merged

aRustyDev merged 3 commits into
mainfrom
feat/59-run-retention

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

The second of three PRs for #59 (the daily hard-delete retention job, F-D10, D-001). #336 added the database half. This adds the use-case that drives it, the windows it reads, and the admin routes a contract test needs. Nothing schedules it yet: the Worker's cron and the server's timer are the next PR, so after this merges the job runs only when POST /internal/retention calls it.

  • run_retention, run_retention_at(now) and run_retention_with(now, limits) in crates/core/usecases/src/retention.rs. Counted back from now, it walks the purgeable work items by key in batches and, for each, deletes the blobs under {workspace}/{project}/{item}/ before the row, so a blob that will not go leaves the work item for the next run and nothing is orphaned. Then it deletes the dispatched outbox rows. A run has a budget (100 work items a batch, 50 batches; 1000 outbox rows a batch, 100 batches), says whether it is complete, and is idempotent. The limits are a parameter so the tests can use small ones.
  • CoreConfig gains hard_delete_after_days (30) and outbox_retention_days (90), from THRUST_HARD_DELETE_AFTER_DAYS and THRUST_OUTBOX_RETENTION_DAYS. A value that is not a whole number of days (negative, 1.5, 1e3, " 7", ...) is an error that names the variable: the server panics at startup (checked on the built binary), and the Worker's core_config now returns an error, so build_app fails. This is stricter than the other numbers, which fall back to their default on a bad value, because a window read as the default would delete rows the operator meant to keep. Unset or empty is the default; 0 is a window.
  • POST /internal/retention {now?} and GET /internal/work-items/{id}, behind the admin token like /internal/sweep; /_info reports both windows, so a test reads the window the target runs with.
  • A window longer than time has no cutoff and deletes nothing, and does not panic.

Tests

  • crates/core/usecases/tests/retention.rs (46 tests): a property over any window and any deletion ages in both tenants (purged exactly when strictly older, the attachments go with it, the next work item is numbered after every one the project ever had, a second run does nothing); the issue's matrix (31 d, 30 d + 1 s, 30 d, 29 d) in both tenants; an outbox property over any window and dispatched/undispatched rows, plus the issue's 91 d / 89 d / 200 d example; budgets and the next run's continuation for both kinds of row; a blob store that refuses deletes; and the config.
  • sweeper_retention_purges_only_rows_past_the_window (contract.rs), in the sweeper pass on all four targets (the pass is 4 tests now: contract.sh, stage2-contract.sh, and check-contract-counts.sh agree). It reads the window from /_info, deletes work items in both tenants after the consumer has handled their events, reads the exact deleted_at back, and stands at deleted_at + window (nothing goes), + 1 µs (the oldest goes) and later (the rest go, in both tenants, and the live one stays). It first shows that an undispatched outbox row survives a run set a year past its window. I ran it here on native-memory and native-pg; the two Worker targets run in CI.
  • Controls, each shown failing with its needle through scripts/mutants.sh: five on the use-case tests (rows 58 to 62: the window not counted back from now, a bad window read as the default, blobs left behind, and the memory adapter's <= and outbox-by-age mutants driven through thrust-core) and three on the contract test (rows 35 to 37). The row count is 65 now (test.yml and cicd.md say so).

Not in this PR

schedules.rs, the Worker dispatching on event.cron(), the 0 0 * * * trigger in the four wrangler files, the server's daily timer, the cron/wrangler parity guard, and worker_cron_scheduled_handler_runs_the_hard_delete. That PR is the one that finishes the issue.

Refs: #59

🤖 Generated with Claude Code

The use-case half of the daily hard delete (F-D10, D-001). Nothing schedules it yet.

- run_retention / run_retention_at / run_retention_with: count back from now, walk the
  purgeable work items by key in batches (the blobs under each deleted first, so a
  failed blob leaves the work item and nothing is orphaned), then delete the dispatched
  outbox rows. A run has a budget and says whether it is complete; it is idempotent.
- CoreConfig gains hard_delete_after_days (30) and outbox_retention_days (90), read from
  THRUST_HARD_DELETE_AFTER_DAYS and THRUST_OUTBOX_RETENTION_DAYS. A value that is not a
  whole number of days is an error that names the variable: the server panics at
  startup and the Worker cannot build its app. Read as the default, it would delete rows
  the operator meant to keep.
- POST /internal/retention {now?} and GET /internal/work-items/{id}, behind the admin
  token, and /_info reports both windows. The contract test
  sweeper_retention_purges_only_rows_past_the_window runs in the sweeper pass on all
  four targets (the pass is 4 tests now).

Tests: 46 on the use cases (a generated window, deletion ages and outbox rows, the issue's
boundary matrix in both tenants, budgets, a failing blob store, the config), and the
contract test, run here on native-memory and native-pg. Mutants: five on the use-case
tests (two reach the memory adapter through thrust-core) and three on the contract test,
rows 35 to 37 and 58 to 62 of scripts/mutants.sh, each KILLED with its needle.

Refs: #59
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev temporarily deployed to preview-control-plane November 19, 2026 07:16 — with GitHub Actions Inactive
aRustyDev and others added 2 commits November 19, 2026 18:24
…re are

test-mutants-shards.sh took "more shards than rows" to be 60 shards and asked for the
last one. That held while scripts/mutants.sh had fewer than 60 rows; with 65 the last
of 60 shards has a row, and the case failed ("selected no row" was never said).

The case now asks the script's own list mode how many rows there are and runs one shard
more than that, so a row added to mutants.sh cannot turn it back into a shard that has
one. The controls in the same file (broken copies that must be rejected) go through the
same function, so each takes its count from its own copy.

Refs: #59
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev temporarily deployed to preview-control-plane November 19, 2026 23:30 — with GitHub Actions Inactive
@aRustyDev
aRustyDev merged commit c08fd24 into main Nov 20, 2026
48 checks passed
@aRustyDev
aRustyDev deleted the feat/59-run-retention branch November 20, 2026 20:35
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 branch was previously deployed

1 inactive deployment
preview-control-plane — 634e822a Deployed Nov 19, 2026 by aRustyDev via reconcile #321
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.

1 participant