The new account-deletion monitor (#42285) paged in prod: 4 Clerk deletions failed on every sweep. Cloudflare refuses to delete a tunnel with live connectors (400 This tunnel has active connections). These users deleted their accounts while their T3 Code host was running, and a host whose link is revoked keeps its connector up until it restarts (CloudLink.markLinkRevoked deliberately keeps going, because a 401 can be clock skew). So the retries could never succeed on their own.
Fix#
Account deletion now force-disconnects:
- When the tunnel delete fails with active connections, the relay rotates the tunnel secret, which kills the host's connector token so it can't reconnect, then clears the tunnel's connections and deletes it. This is Cloudflare's documented token-rotation procedure for remotely managed tunnels.
deprovision and unlinkEnvironmentRecord take a forceDisconnect option, and only AccountDeletion sets it. Unlink, release and the reaper keep their current behaviour of waiting for hosts to stop.
- Alchemy's tunnel binding doesn't expose connection cleanup. The relay now has its own binding (
ManagedTunnelBinding) built with Alchemy's exported makeTunnelClient, using the same token policy id and permissions (Cloudflare Tunnel Read and Write). The Worker's scoped token doesn't change.
- The delete is now wrapped in
Effect.suspend, so the retry after disconnecting is always a fresh request.
Evidence#
- Prod trace for the failing passes: DNS deleted, then
DeleteTunnelCloudflared → 400 "has active connections". Passes for users whose host was offline succeed.
- A new provider test: an unforced deprovision of a tunnel with a live connector still fails at
delete-tunnel without disconnecting. A forced one disconnects, deletes and removes the allocation. Disabling the forced branch makes the test fail.
- The relay suite passes (324 tests) and
check:changed passes.
After deploy, the 4 stuck deletions should finish on the next sweep and the monitor should resolve.
🤖 Generated with Claude Code (Claude Opus 5.5)
No actionable comments were generated in the recent review.
Walkthrough
Managed endpoint deprovisioning now supports an optional forced disconnect when active connections prevent tunnel deletion. The account deletion flow enables this option during environment unlinking. The worker uses a managed tunnel binding that provides the disconnect operation.
Changes: Managed endpoint disconnect flow
infra/relay/src/environments/ManagedTunnelBinding.ts,infra/relay/src/worker.tsdisconnect, which updates the tunnel secret and deletes its connection. The worker uses this binding for managed endpoint tunnel access.infra/relay/src/environments/ManagedEndpointProvider.ts,infra/relay/src/environments/ManagedEndpointProvider.test.ts,infra/relay/src/environments/ManagedEndpointReaper.test.tsforceDisconnectistrueand tunnel deletion fails because connections are active, the provider disconnects the tunnel and retries deletion. Tests cover forced and ordinary deprovisioning.infra/relay/src/http/Api.ts,infra/relay/src/accounts/AccountDeletion.tsforceDisconnect. Account deletion sets the option when unlinking environments.Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
Merge Risk:
Minimal · up to
6a3b2Account deletion now force-disconnects a host's tunnel connectors when Cloudflare refuses to delete a tunnel with active connections, then retries the deletion. No merge-blocking risk was found. The fix should be confirmed after deployment by checking that the four stuck deletions complete.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: account deletion now force-disconnects a live host's tunnel connectors, which the raw summary and objectives both confirm. It also follows the conventional commit form with a fix(relay) scope. It describes the bug fix in plain language and does not mention files or vague terms.
Full details: Description check
Explanation
The description covers the template sections. Problem: Clerk deletions fail with 'This tunnel has active connections' while a revoked host keeps its connector running. Change: forceDisconnect is added for AccountDeletion, with token rotation and a new ManagedTunnelBinding. Scope: it describes a bug fix tied to the account-deletion monitor (
#42285), but it does not link a bug issue or explain why no issue exists. Verification: it lists a new provider test, a mutation check, 324 passing relay tests, and a passing check:changed, and it notes that the production outcome is expected but not yet observed. The description also says the relay suite passes, but the template asks for focused checks, which the author gives. The main gap is the missing issue link for the Scope section.Resolution
Optionally link the issue or monitor alert that shows the bug, or state why no issue is needed. The template asks for this in the Scope section. Also consider noting the production result once it is verified.
Finishing Touches
Generate unit tests (beta)
5fc990e3-5715-4928-8d7a-1d66679bb973Reviewing files that changed from the base of the PR and between 55085df2a6c384f34b37901d5dcbc5925ada1600 and 6a3b2810508e9852e1d877290259f5aa8eb3ba49.
infra/relay/src/accounts/AccountDeletion.tsinfra/relay/src/environments/ManagedEndpointProvider.test.tsinfra/relay/src/environments/ManagedEndpointProvider.tsinfra/relay/src/environments/ManagedEndpointReaper.test.tsinfra/relay/src/environments/ManagedTunnelBinding.tsinfra/relay/src/http/Api.tsinfra/relay/src/worker.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.