Repository navigation
fix(cron): warn owners before stale-nm deletion, never auto-delete (#662) - #663
Merged
Merged
Conversation
The daily Cloudflare cron silently hard-deleted private, no-DOI nm datasets at 90 days inactive (it wiped nm000111/116/117 across GitHub, S3, and D1). Replace that with a human-gated runway: - Email the owner escalating warnings at 30/14/7/2/1 days before the deadline, tracked in D1 (staleness_warn_stage) so the daily cron does not re-spam; reset when the dataset gets fresh activity. - At the deadline the cron does NOT delete; it emails admins a ready-to-delete notice. nm deletion is now only a manual admin action. - Sandbox xx 14-day auto-deletion is unchanged (disposable). Adds services/staleness.ts (pure threshold math), migration 0027, and owner/admin email templates. Tested: staleness unit tests + email fetch-capture tests (no real Resend sends).
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR663Version: 🤖 Updated on each push. |
1 of 3 tasks
Address pr-review-toolkit findings on the cron warning runway: - Only advance staleness_warn_stage / staleness_admin_notified_at when the email was actually delivered (or there is genuinely no recipient). Previously a swallowed Resend failure or a missing RESEND_API_KEY left the column stamped "done", permanently suppressing the warning/admin notice - the same silent-failure class that lost nm000111/116/117. - sendStalenessAdminReviewEmail now returns the delivered count; the cron advances the flag only when delivered > 0. - Fetch admin emails in their own try/catch so a D1 hiccup can't abandon every owner warning; wrap each row in a per-dataset boundary. - Exclude already-notified past-deadline rows from candidates so a backlog can't starve newly-past-deadline datasets out of the LIMIT. - Use the publication_request email category, not announcements (a data-loss alert must not ride an opt-out newsletter preference). - Log when RESEND_API_KEY is absent instead of skipping silently. - Accurate email copy: owner notice shows real inactive-days; admin notice states the actual warning stage reached instead of over-claiming. Tests: add cron SQL-structural guards (reset/candidate clauses, starvation exclusion, handled-gate), an ISO-timestamp parse case, an admin-subject assertion, and a zero-delivered admin-email case.
/review-pr summary (4 agents, sonnet)Ran code-reviewer, silent-failure-hunter, pr-test-analyzer, comment-analyzer in parallel. Findings and resolution (all addressed in 6f490cd): Critical
Important
Comment/copy accuracy
Tests added
Reviewed, kept by design
22 tests pass, typecheck + Biome clean. |
This was referenced Jun 1, 2026
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.
Closes #662.
Problem
The daily Cloudflare Workers cron (
scheduledCleanup,crons = ["0 3 * * *"]) silently hard-deleted private, no-DOInmdatasets once inactive 90 days, using the same total cascade as a manual admin delete (GitHub repo + S3 + D1). On 2026-05-27 it destroyed nm000111 (ISRUC-Sleep), nm000116 (SEED-V), nm000117 (SEED-VIG) with no owner warning and no human in the loop. Recoverable only because S3 versioning was on. 103 more private/no-DOI nm datasets were exposed to the same fate.Fix
The cron never auto-deletes
nmdatasets anymore. Instead:staleness_warn_stage) so the daily run does not re-spam; tracking resets when the dataset gets fresh activity, a DOI, a pending pub request, or is made public.nemar admin delete-datasetaction.xx14-day auto-deletion is unchanged (disposable).Changes
backend/src/services/staleness.ts— pure threshold math (unit-tested).backend/src/db/migrations/0027_dataset_staleness_tracking.sql—staleness_warn_stage,staleness_admin_notified_at.backend/src/services/email.ts— owner warning + admin review templates (Resend).backend/src/index.ts— rewrites the nm branch ofscheduledCleanup.Tests
test/staleness.unit.test.ts— 12 pure-function tests (no I/O, no sends): age/days-left maths, the 30/14/7/2/1 escalation emits each threshold exactly once, never emits at/after the deadline.test/email-staleness.test.ts— captures the outbound Resend request (overrideglobalThis.fetch, no real email) to assert recipient/subject/body; plus an opt-inGET /domainsconnectivity check gated behindRESEND_API_KEY(no send, no cost).Deploy note
Migration 0027 must be applied to dev + prod D1 with the deploy (the cron queries the new columns). No at-risk datasets currently, so the old cron deletes nothing before this ships.
Recovery (separate, already done)
nm000111/116/117 fully recovered: S3 delete markers removed (versions restored), GitHub repos restored via org UI within the 90-day window, D1 rows + owner S3 grants re-registered, recovery logged to
audit_log.