Skip to content

fix(cloudflare): destroy actually tears everything down#43

Merged
aynaash merged 1 commit into
mainfrom
fix/cloudflare-destroy-teardown
Jul 3, 2026
Merged

fix(cloudflare): destroy actually tears everything down#43
aynaash merged 1 commit into
mainfrom
fix/cloudflare-destroy-teardown

Conversation

@aynaash

@aynaash aynaash commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Destroy previously deleted only the Worker and attempted the R2 bucket delete
(which fails on a non-empty bucket) — while logging success. Every provisioned
resource (D1, KV, Hyperdrive, Queues, Vectorize, AI Gateway), the bucket + all
its objects, and provisioned DNS records survived and kept billing, with the
operator told "successfully destroyed."

Now Destroy:

  • Sweeps R2 objects (S3 client, batched DeleteObjects) then deletes the bucket.
  • Deletes every resource in the encrypted cfstate manifest (incl. orphans) via the right CF API per kind, and clears/rewrites the state file.
  • Deletes the DNS records nextdeploy added, matched by value so unrelated sibling records in the zone are never touched.
  • Treats 404 as already-gone (idempotent), and returns an error listing anything that couldn't be removed — so success is never reported while resources still exist.

Extracts the R2 credential setup into ensureR2Client (shared by deploy + teardown). Tests cover per-kind delete routing and 404-vs-500 handling.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ru3K1fyNRnyTXQ95Gmv6Su

Destroy previously deleted only the Worker and *attempted* the R2 bucket
delete — which fails on a non-empty bucket — while reporting success. Every
provisioned resource (D1, KV, Hyperdrive, Queues, Vectorize, AI Gateway), the
bucket + all its objects, and provisioned DNS records survived, still billing.

Now Destroy:
- sweeps R2 objects (S3 client, batched DeleteObjects) then deletes the bucket;
- deletes every resource recorded in the encrypted cfstate manifest (incl.
  orphans) via the right CF API per kind, and clears/rewrites the state file;
- deletes the DNS records nextdeploy added, matched by value so unrelated
  sibling records in the zone are never touched;
- treats 404s as already-gone (idempotent), and RETURNS AN ERROR listing
  anything that couldn't be removed — so the operator is never told "done"
  while resources still exist.

Extracts the R2 credential setup into ensureR2Client (shared by deploy + the
teardown sweep). Adds tests covering per-kind delete routing and 404-vs-500
handling.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ru3K1fyNRnyTXQ95Gmv6Su
@aynaash
aynaash merged commit 84e0a73 into main Jul 3, 2026
14 checks passed
@aynaash
aynaash deleted the fix/cloudflare-destroy-teardown branch July 3, 2026 19:19
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