refactor(entitlements): stop D1 daily counter mirror - #1133
Conversation
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>
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>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
# Conflicts: # packages/worker/src/email/inbound.ts # packages/worker/src/email/outbound.ts # packages/worker/worker-configuration.d.ts 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>
# Conflicts: # docs/contributing/architecture/data-storage.md # packages/worker/src/account/export.node.test.ts # packages/worker/src/account/export.ts 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>
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>
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>
# Conflicts: # docs/contributing/architecture/data-storage.md Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
# Conflicts: # docs/contributing/architecture/data-storage.md 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>
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>
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>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
📝 WalkthroughWalkthroughDaily entitlement counters now use UserMeter as the sole authority. D1 bootstrap, mirror writes, and retention pruning were removed. Parity reports support retired mirrors, local analytics return empty quota aggregates with warnings, and tests use UserMeter fixtures. ChangesDaily counter migration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant EntitlementService
participant UserMeter
Caller->>EntitlementService: Request daily entitlement operation
EntitlementService->>UserMeter: Initialize missing daily key at zero
EntitlementService->>UserMeter: Read or update daily usage
UserMeter-->>EntitlementService: Return usage state
EntitlementService-->>Caller: Return entitlement result
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 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 |
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
|
@coderabbitai review |
|
🔎 Preview deployed: https://kody-pr-1133.kody-a99.workers.dev Worker: Mocks:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/contributing/architecture/data-storage.md`:
- Around line 642-646: Update the D1 daily mirror documentation near the “D1
daily mirror writes stopped” statement to limit the no-read/no-write claim to
enforcement and point-read paths. Explicitly document that
loadAdminUserMeterParityReport temporarily reads entitlement_daily_counters for
admin parity comparison while the table remains, until the follow-up migration
drops it.
In `@packages/worker/src/app/admin-insights-data.ts`:
- Around line 288-291: Split the fallback in admin-insights-data.ts so local
development emits the existing local-mode reason, while a missing EMAIL_EVENTS
binding emits a distinct binding-specific reason. Update
packages/worker/src/app/admin-insights-data.node.test.ts at lines 321-325 to set
WRANGLER_IS_LOCAL_DEV for the local assertion and add coverage asserting the
missing-binding reason.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5500cf07-4fcd-43c1-a2ba-8f800ec505b9
📒 Files selected for processing (28)
docs/contributing/architecture/data-storage.mddocs/contributing/architecture/entitlements.mdpackages/worker/src/admin/user-meter-parity.node.test.tspackages/worker/src/admin/user-meter-parity.tspackages/worker/src/admin/user-usage-data.node.test.tspackages/worker/src/app/account-deletion.node.test.tspackages/worker/src/app/account-retention-dispositions.tspackages/worker/src/app/account-usage-data.node.test.tspackages/worker/src/app/admin-insights-data.node.test.tspackages/worker/src/app/admin-insights-data.tspackages/worker/src/app/handlers/account-email.node.test.tspackages/worker/src/app/retention.node.test.tspackages/worker/src/app/retention.tspackages/worker/src/email/inbound-delivery.tspackages/worker/src/email/inbound-entitlements.workers.test.tspackages/worker/src/email/inbound-spam-controls.workers.test.tspackages/worker/src/email/inbound.workers.test.tspackages/worker/src/email/outbound.tspackages/worker/src/entitlements/entitlements.node.test.tspackages/worker/src/entitlements/service.tspackages/worker/src/entitlements/test-schema.tspackages/worker/src/entitlements/user-meter-do.tspackages/worker/src/entitlements/user-meter.workers.test.tspackages/worker/src/mcp/capabilities/admin/admin-capabilities.node.test.tspackages/worker/src/mcp/capabilities/admin/admin-user-meter-parity.node.test.tspackages/worker/src/mcp/capabilities/admin/admin-user-meter-parity.tspackages/worker/src/mcp/capabilities/email/email-usage-get.workers.test.tspackages/worker/src/mcp/fetch-gateway.node.test.ts
💤 Files with no reviewable changes (4)
- packages/worker/src/email/inbound-entitlements.workers.test.ts
- packages/worker/src/app/account-deletion.node.test.ts
- packages/worker/src/mcp/capabilities/admin/admin-capabilities.node.test.ts
- packages/worker/src/app/retention.ts
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Summary
entitlement_daily_countersValidation
System recap — contracts daily mirror code paths (medium risk)
Mode: recap · Base:
main@5a4ce59a· Head:436c2723Classification: extends — removes hot-path D1 mirror/fallback behavior while retaining physical-schema guards.
Invariants
Conductor report
rows=104,total_count=48,884,max_updated_at=r/…1472), confirming mirror writes stopped after activation.0126drop anddaily.mirrorRetired === trueverification.Summary by CodeRabbit