feat(email): route write leases through UserMeter - #1197
Merged
Merged
Conversation
All four email paths (inbound, inbound-effects, outbound, reconcile-inbound-deliveries) now supply env to withAccountWriteLease. This is call-site coordination only; no behavior changes beyond env/holder plumbing. Mailbox legacy graph is already dropped (#1174/#1189). Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
β¦only - withAccountWriteLease: env required; remove D1 acquire/release path, D1/DO union, waitUntil param, and active_write_count plumbing - markAccountDeleting: env required; D1 deleting_at set first (gate), then UserMeter markDeleting; no D1 lease snapshot or loading - listActiveAccountWriteLeases: (env, userId) only; UserMeter page walk; no D1 union - repairAccountWriteLease: env required; DO-only prepare/finalize; D1 audit row kept; no stale D1 clear - Remove dead waitUntil params from all call sites - D1 users.deleting_at remains the permanent point gate Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
- Remove shadow types: UserMeterWriteLeaseShadow (replaced by UserMeterWriteLeaseEntry without authority field) - Remove listDoAuthorityWriteLeases, replaceLegacyWriteLeases, and assertWriteLeaseAuthority - Remove authority discriminated union behavior from acquireWriteLease, releaseWriteLease, prepareWriteLeaseRepair, finalizeWriteLeaseRepair - Keep warm authority column/shim for schema compatibility; code treats every row as authoritative DO; will drop after schema_version >= 7 - Simplify test-support/user-meter.ts to match: remove authority field from WriteLeaseRow, remove finalizeWriteLeaseRepair authority guard Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
β¦ease query - DeletionParity: drop d1ActiveLeaseCount/doAuthorityLeaseCount/doLegacyLeaseCount/ tokenSetMismatches/temporaryMirrorRetired/mirrorLeaseParity; keep d1DeletingAt, meterDeletingAt, deletingAtParity, activeLeaseCount, truncated - readDeletionParity: read D1 deleting_at + UserMeter deletingAt/countActiveWriteLeases; no D1 account_write_leases query - admin-user-meter-parity: update deletionParitySchema, description, and keywords to match new DeletionParity type - Tests: remove bootstrapDeletionState/UserMeterWriteLeaseShadow, rewrite to use meter.markDeleting and new parity shape; remove split-authority tests Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
- deletion-state.node.test.ts: rewrite for meter-only mark/list/repair; remove D1-only lease paths and waitUntil; add env-required tests; verify D1 deleting_at gate and races; add export/purge tombstone preservation test - account-deletion.node.test.ts: acquire UserMeter lease to simulate active writer; verify deletion is blocked then proceeds after lease release - user-meter.workers.test.ts: remove shadowAcquireWriteLease, listDoAuthorityWriteLeases, bootstrapDeletionState, authority field - service.node.test.ts files: remove writeLeaseDb mock hooks; batch mock runs statements directly (no D1 account_write_leases queries on runtime path) Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
- account-write-lease-repair.md: remove legacy email / D1 lease paths; describe DO-only repair flow; note D1 account_write_leases quiescent - data-storage.md: note authority column warm/ignored; all callers supply env; D1 account_write_leases quiescent; write-lease rows clear on release/repair/purge - entitlements.md: rewrite Account-deletion write fencing section; mark contract complete 2026-08-03; remove split-authority/Phase-B/mirror-retired prose; update primitives table (activeLeaseCount replaces mirrorLeaseParity/doOnly) - primitives.yaml: update User meter summary to reflect authoritative DO leases Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
π WalkthroughWalkthroughEmail inbound, outbound, and reconciliation flows now pass their worker environment to ChangesEmail lease environment propagation
Estimated code review effort: 1 (Trivial) | ~2 minutes Possibly related PRs
π₯ Pre-merge checks | β 5β Passed checks (5 passed)
β¨ Finishing Touchesπ Generate docstrings
π§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
|
π Preview deployed: https://kody-pr-1197.kody-a99.workers.dev Worker: Mocks:
|
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.
Intent
Complete the expand step for account write-lease authority by moving the final four email call sites onto UserMeter before deleting the legacy D1 path in a follow-up deployment.
Summary
envto inbound, inbound-effects, outbound, and inbound-reconciliation lease boundariesTesting
npm run typecheckβ passedSystem changes
System recap β composes existing primitives (low risk)
Mode: recap Β· Base:
main@ffb84630Β· Head:8ba23da2Classification: composes β call-site wiring routes existing email mutations through the existing UserMeter lease authority; no primitive contract changes.
Primitives touched
emailUSER_METERto four existing lease boundariesSystem map
Email mutation paths now select the UserMeter branch of the existing write-lease helper while D1 remains a rollout compatibility fence.
Legend: green = composes (wiring only) Β· amber = extended by this PR Β· red = new primitive Β· gray = context (unchanged, included only when an edge crosses it).
Invariants
Per-user isolation and account-deletion fencing remain unchanged; this PR only changes which already-existing authority branch the email paths select.
Conductor report
95f2150eat 2026-08-04 01:13Z#1174/#1189); these were call-site-only changes.e72aac17-b95c-4b3a-8afd-08e3bb9d8893). Follow-up D1 active lease count: 0.d1Only=0,legacyWithoutD1=0, deletion tombstone parity true. UserMeter remains authoritative and currently reports active DO leases independently.Summary by CodeRabbit