Skip to content

Remove email post-drop legacy infrastructure - #1216

Merged
kody-bot merged 9 commits into
mainfrom
cursor/reap-email-postdrop-80df
Aug 4, 2026
Merged

kody-bot merged 9 commits into
mainfrom
cursor/reap-email-postdrop-80df

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Aug 4, 2026 •

Copy link
Copy Markdown
Owner

Intent

Complete the post-cutover email legacy teardown from #1069 now that migration 0135 has removed the shared email graph in production.

Summary

  • remove the one-shot Mailbox graph backup/approval workflow, binding, UI routes, shared contract, local fixture, tests, and runbook text
  • add migration 0143 to drop the consumed approval receipt and detached inbound-effects ledger, and simplify due-owner ordering to due_at, user_id (renumbered from assigned 0140 after 0141 landed on main; sibling-reserved 0142 remains untouched)
  • retain both permanent graph-authority gates and the Mailbox deletion-tombstone fence while correcting stale cutover/dual-write comments
  • include the salvaged Mailbox search regression coverage for exact 48/49-byte pattern boundaries and long queries

Testing

  • npm run validate — passed on final head
  • focused teardown/migration suites — 22 tests passed, including explicit 0143 before/after and replay-safe schema assertions
  • Mailbox search Workers suite — 4 tests passed
  • backup resources suite — 12 tests passed
  • backup control-plane dry-run build — passed with only BACKUP_WORKFLOW and RESTORE_WORKFLOW
  • migration ledger — 144 files, next free prefix 0144
  • PR CI — Validate, Static, Node, Workers, MCP, E2E, preview deploy, Cursor Bugbot, and CodeRabbit checks passed
  • production deploy — passed; migration log records 0143-drop-email-postdrop-residue.sql ✅

System changes

System recap — extends existing primitives (medium risk)

Mode: recap · Base: main @ b9f83a33 · Head: 41186fdd

Classification: extends — removes a deployed one-shot control-plane lane and contracts the final D1 email schema without adding a primitive.

Primitives touched

Primitive Group Impact
backup-control-plane storage extends — removes the completed one-shot Mailbox graph backup/approval workflow and operator routes
d1-app-db storage extends — migration 0143 drops two retired tables and rebuilds due-owner ordering
email assistant extends — final test schema and migration coverage no longer inventory retired D1 state
mailbox storage composes — preserves tombstones and clarifies their permanent delayed-writer fence

System map

The nightly backup/restore lane remains intact while migration 0143 contracts retired email state and Mailbox remains the permanent per-user authority.

Legend: green = composes (wiring only) · amber = extended by this PR · red = new primitive · gray = context (unchanged, included only when an edge crosses it).

flowchart LR
	backup["backup-control-plane<br/>Production backup control plane"]:::extended
	d1["d1-app-db<br/>D1 app database"]:::extended
	email["email<br/>Email"]:::extended
	mailbox["mailbox<br/>Mailbox"]:::touched
	backup -->|"nightly export + restore remain; one-shot approval lane removed"| d1
	email -->|"0143 drops retired receipt and effects ledger"| d1
	email -->|"per-user metadata authority unchanged"| mailbox
	classDef touched fill:#1a7f37,color:#fff
	classDef extended fill:#9a6700,color:#fff
	classDef added fill:#cf222e,color:#fff
	classDef untouched fill:#57606a,color:#fff
Loading

Invariants

  • email_user_graph_authority and system_email_graph_authority remain permanent fail-closed gates.
  • Mailbox deletion tombstones remain a permanent fence against delayed writer resurrection.
  • Nightly backup, freshness, sealing, restore drill, and production restore paths remain wired.

Conductor report

STATUS done — PR #1216 squash-merged as e090800e; local npm run validate, PR CI, preview migration, AI review, and production deploy are green; production logs show 0143-drop-email-postdrop-residue.sql applied ✅. No assigned legacy remains outside immutable migration history; issue #1069 follow-up complete.

Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes

    • Removed obsolete mailbox pre-drop backup and approval workflows.
    • Streamlined backup payload validation and deployment triggers.
    • Cleaned up residual email database tables and indexes.
  • Documentation

    • Clarified migration, backup, restore, and disaster-recovery terminology.
    • Removed outdated mailbox pre-drop workflow instructions and references.
  • Chores

    • Simplified local migration execution and backup resource reconciliation.
    • Updated migration tracking and related test coverage.

cursoragent and others added 2 commits August 4, 2026 14:03
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR removes the mailbox legacy-graph pre-drop backup workflow, approval contracts, control-plane routes, tests, documentation, and migration fixtures. It adds migration 0140 to remove related database residue and updates backup validation, deployment configuration, and mailbox terminology.

Changes

Mailbox pre-drop backup removal

Layer / File(s) Summary
Backup runtime contracts and validation
packages/backup-control-plane/backup-types.ts, packages/backup-control-plane/backup-runtime.ts, packages/backup-control-plane/backup-policy.ts, packages/backup-control-plane/mailbox-pre-drop-*.ts, packages/backup-control-plane/worker.ts
Removes mailbox pre-drop payload types, validation, workflow execution, approval helpers, and worker exports. Scheduled backup validation remains.
Control-plane routes and operational bindings
packages/backup-control-plane/control-plane-fetch.ts, packages/backup-control-plane/control-plane-ui.ts, packages/backup-control-plane/wrangler.jsonc, .github/workflows/deploy.yml, docs/contributing/disaster-recovery.md, docs/contributing/environment-variables.md, tools/ci/*
Removes mailbox pre-drop routes, dashboard actions, workflow bindings, and operational requirements. Updates deployment triggering and reconciliation messages.
Migration and local tooling cleanup
packages/worker/migrations/0140-drop-email-postdrop-residue.sql, tools/migration-ledger.json, tools/apply-local-app-migrations.ts, packages/worker/src/email/*migration*.test.ts
Adds migration 0140 to remove approval and usage-effects tables, updates migration tests and the ledger, and simplifies local migration execution.
Terminology and mailbox behavior documentation
docs/contributing/architecture/*, packages/worker/src/email/*, packages/worker/src/email/repo-search.workers.test.ts
Updates pre-migration terminology, clarifies mailbox cleanup behavior, and expands long-query search coverage.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • kentcdodds/kody#1174: Introduced mailbox pre-drop approval and control-plane workflows removed here.
  • kentcdodds/kody#1176: Added the signed mailbox pre-drop approval workflow and related migration tooling removed here.
  • kentcdodds/kody#1157: Introduced inbound email migration infrastructure updated by this PR.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: removing email post-drop legacy infrastructure related to the mailbox graph backup/approval workflow and associated state.
Description check ✅ Passed The description includes all required sections with sufficient detail: Intent explains the post-cutover teardown goal, Summary lists major changes, Testing documents validation performed, and System changes provides risk analysis and invariants.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/reap-email-postdrop-80df

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

cursoragent and others added 2 commits August 4, 2026 14:10
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kody-bot
kody-bot marked this pull request as ready for review August 4, 2026 14:20
@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-1216.kody-a99.workers.dev

Worker: kody-pr-1216
D1: kody-pr-1216-db
KV: kody-pr-1216-oauth-kv

Mocks:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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
`@packages/worker/src/email/inbound-mailbox-authority-mirror-migration.node.test.ts`:
- Around line 220-227: Update the migration test around applyMigrationsBefore
and authorityMirrorMigration to explicitly cover migration 0140’s
email_inbound_usage_effects schema or tear-down behavior. Preserve the existing
migration 0129 coverage, either by keeping that schema assertion in this test or
adding a separate targeted migration 0140 test.
🪄 Autofix

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: 422f2897-1529-484d-8f03-b2ece099f76f

📥 Commits

Reviewing files that changed from the base of the PR and between 6a77bf0 and 78537eb.

📒 Files selected for processing (45)
  • .github/workflows/deploy.yml
  • docs/contributing/architecture/data-storage.md
  • docs/contributing/architecture/run-records.md
  • docs/contributing/disaster-recovery.md
  • docs/contributing/environment-variables.md
  • docs/contributing/mailbox-legacy-graph-drop.md
  • packages/backup-control-plane/backup-control-plane-test-support.ts
  • packages/backup-control-plane/backup-policy.ts
  • packages/backup-control-plane/backup-runtime.node.test.ts
  • packages/backup-control-plane/backup-runtime.ts
  • packages/backup-control-plane/backup-types.ts
  • packages/backup-control-plane/control-plane-fetch.node.test.ts
  • packages/backup-control-plane/control-plane-fetch.ts
  • packages/backup-control-plane/control-plane-ui.ts
  • packages/backup-control-plane/mailbox-pre-drop-approval.node.test.ts
  • packages/backup-control-plane/mailbox-pre-drop-approval.ts
  • packages/backup-control-plane/mailbox-pre-drop-persistence.ts
  • packages/backup-control-plane/mailbox-pre-drop-policy.ts
  • packages/backup-control-plane/mailbox-pre-drop-r2-policy.ts
  • packages/backup-control-plane/mailbox-pre-drop-runtime.ts
  • packages/backup-control-plane/mailbox-pre-drop-snapshot.ts
  • packages/backup-control-plane/mailbox-pre-drop-verification.ts
  • packages/backup-control-plane/mailbox-pre-drop-workflow.node.test.ts
  • packages/backup-control-plane/mailbox-pre-drop-workflow.ts
  • packages/backup-control-plane/readme.md
  • packages/backup-control-plane/worker.ts
  • packages/backup-control-plane/wrangler.jsonc
  • packages/shared/src/mailbox-pre-drop-approval.ts
  • packages/worker/migrations/0140-drop-email-postdrop-residue.sql
  • packages/worker/src/account/data-targets.ts
  • packages/worker/src/account/user-owned-surfaces.ts
  • packages/worker/src/email/inbound-mailbox-authority-mirror-migration.node.test.ts
  • packages/worker/src/email/legacy-email-graph-drop-migration.node.test.ts
  • packages/worker/src/email/mailbox-inbound-effect-ledger.ts
  • packages/worker/src/email/mailbox-message-deletion-tombstones.ts
  • packages/worker/src/email/mailbox-mutations.ts
  • packages/worker/src/email/mailbox-schema.ts
  • packages/worker/src/email/repo-search.workers.test.ts
  • packages/worker/src/email/test-schema.ts
  • packages/worker/src/email/user-graph-drop-approval-migration.node.test.ts
  • tools/apply-local-app-migrations.ts
  • tools/ci/backup-resources-reconcile-cli.ts
  • tools/ci/backup-resources.node.test.ts
  • tools/local-mailbox-pre-drop-approval-fixture.sql
  • tools/migration-ledger.json
💤 Files with no reviewable changes (22)
  • packages/backup-control-plane/mailbox-pre-drop-approval.ts
  • docs/contributing/mailbox-legacy-graph-drop.md
  • packages/backup-control-plane/mailbox-pre-drop-workflow.ts
  • packages/backup-control-plane/mailbox-pre-drop-r2-policy.ts
  • packages/backup-control-plane/backup-control-plane-test-support.ts
  • packages/backup-control-plane/mailbox-pre-drop-workflow.node.test.ts
  • packages/backup-control-plane/mailbox-pre-drop-verification.ts
  • packages/backup-control-plane/control-plane-fetch.node.test.ts
  • tools/local-mailbox-pre-drop-approval-fixture.sql
  • packages/backup-control-plane/mailbox-pre-drop-approval.node.test.ts
  • packages/backup-control-plane/mailbox-pre-drop-runtime.ts
  • packages/backup-control-plane/control-plane-ui.ts
  • packages/worker/src/email/test-schema.ts
  • packages/backup-control-plane/control-plane-fetch.ts
  • packages/backup-control-plane/worker.ts
  • packages/backup-control-plane/mailbox-pre-drop-snapshot.ts
  • packages/backup-control-plane/readme.md
  • packages/backup-control-plane/mailbox-pre-drop-persistence.ts
  • packages/worker/src/account/data-targets.ts
  • packages/worker/src/email/user-graph-drop-approval-migration.node.test.ts
  • packages/backup-control-plane/mailbox-pre-drop-policy.ts
  • packages/shared/src/mailbox-pre-drop-approval.ts

Comment on lines +220 to 227
'idx_email_delivery_events_user_dedupe_expires'
)
ORDER BY name`,
)
.all(),
).toEqual([
{ name: 'idx_email_delivery_events_user_dedupe_expires' },
{ name: 'idx_email_delivery_events_user_state_created' },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 8 \
  'authorityMirrorMigration|applyMigrationLikeD1|email_inbound_usage_effects|idx_email_inbound' \
  packages/worker/src/email/inbound-mailbox-authority-mirror-migration.node.test.ts \
  packages/worker/migrations/0129-email-inbound-mailbox-authority-mirror.sql \
  packages/worker/migrations/0140-drop-email-postdrop-residue.sql || true

rg -n -C 8 \
  '0140-drop-email-postdrop-residue|email_inbound_usage_effects' \
  packages/worker/src/email packages/worker/migrations || true

Repository: kentcdodds/kody

Length of output: 29983


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

wc -l packages/worker/src/email/inbound-mailbox-authority-mirror-migration.node.test.ts
sed -n '1,260p' packages/worker/src/email/inbound-mailbox-authority-mirror-migration.node.test.ts

Repository: kentcdodds/kody

Length of output: 7709


Preserve coverage for migration 0129.

applyMigrationsBefore(db, authorityMirrorMigration) only applies migrations before 0129-email-inbound-mailbox-authority-mirror.sql, so this test does not cover migration 0140. Keep the email_inbound_usage_effects schema check here, or add a separate migration 0140 test for the tear-down.

🤖 Prompt for 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.

In
`@packages/worker/src/email/inbound-mailbox-authority-mirror-migration.node.test.ts`
around lines 220 - 227, Update the migration test around applyMigrationsBefore
and authorityMirrorMigration to explicitly cover migration 0140’s
email_inbound_usage_effects schema or tear-down behavior. Preserve the existing
migration 0129 coverage, either by keeping that schema assertion in this test or
adding a separate targeted migration 0140 test.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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 `@packages/worker/src/email/email-postdrop-migration.node.test.ts`:
- Around line 19-22: Replace the dynamic extraction of droppedTables using the
regex pattern and matchAll on the sql variable with a hardcoded list of the two
expected retired table names as literals. Then add assertions that verify each
of these specific tables exists in the database before running the migration and
does not exist after the migration completes, ensuring the test fails if
unintended tables are dropped.
🪄 Autofix

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: 52319c9f-206c-40af-ac28-e06c75167cba

📥 Commits

Reviewing files that changed from the base of the PR and between 78537eb and 59b7a71.

📒 Files selected for processing (1)
  • packages/worker/src/email/email-postdrop-migration.node.test.ts

Comment thread packages/worker/src/email/email-postdrop-migration.node.test.ts Outdated
cursoragent and others added 4 commits August 4, 2026 14:41
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
…tdrop-80df

# Conflicts:
#	tools/migration-ledger.json

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>
@kody-bot
kody-bot merged commit e090800 into main Aug 4, 2026
10 checks passed
@kody-bot
kody-bot deleted the cursor/reap-email-postdrop-80df branch August 4, 2026 15:09
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.

3 participants