[wrangler] fix: prevent remote binding sessions expiring during long dev sessions#13016
[wrangler] fix: prevent remote binding sessions expiring during long dev sessions#13016
Conversation
🦋 Changeset detectedLatest commit: 4852073 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
✅ All changesets look good |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
|
I've completed my thorough review of the PR. Let me summarize my findings: The PR is well-structured and addresses the stated issues clearly. The code changes are logical, the test coverage for the new proactive refresh behavior is solid, and the error recovery pattern (re-emitting After careful review, I don't find any actionable logic bugs, security issues, backward compatibility violations, or incorrect API behavior. The key areas I verified:
LGTM |
6ab5cab to
35d0aae
Compare
35d0aae to
cb76ef9
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
petebacondarwin
left a comment
There was a problem hiding this comment.
Looking good so far. I wonder if we could achieve a similar result by emitting the previewTokenExpired event after 50 mins and let the rest of the machinery do the refresh?
packages/miniflare/src/workers/shared/remote-proxy-client.worker.ts
Outdated
Show resolved
Hide resolved
packages/wrangler/src/api/startDevWorker/RemoteRuntimeController.ts
Outdated
Show resolved
Hide resolved
packages/wrangler/src/api/startDevWorker/RemoteRuntimeController.ts
Outdated
Show resolved
Hide resolved
packages/wrangler/src/api/startDevWorker/RemoteRuntimeController.ts
Outdated
Show resolved
Hide resolved
…rt, unwrapHook in tests
|
Codeowners approval required for this PR:
Show detailed file reviewers |
…preempted refresh
|
/bonk fix the lint issues on this PR |
|
Fixed the lint issue. The problem was a single unused import:
Lint and format checks now pass clean. |
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
|
Codeowners approval required for this PR:
Show detailed file reviewers |
Fixes #12901
Fixes an issue where remote bindings (e.g. Workers AI) would stop working after ~1 hour in
wrangler dev, requiring a manual restart.Root causes fixed:
Preview tokens expired silently — tokens have a 1-hour TTL set by the Workers control plane. The ProxyWorker would detect expiry reactively (only after a request failed), meaning one request would always fail before a refresh was triggered. This PR adds a proactive refresh at 50 minutes so no request ever sees an expired token.
error code: 1031not recognised as expiry — bindings like Workers AI returntext/plainerror code: 1031when their session times out, but the existing check only matched the HTMLInvalid Workers Preview configurationresponse. The check is now content-type-agnostic.Failed refresh left ProxyWorker permanently paused — if
#refreshPreviewTokenthrew afteremitReloadStartEventhad already paused the ProxyWorker, noreloadCompletewas ever emitted to unpause it. The catch block now re-emits the last knownproxyDatato recover.Auth resolved too early —
unwrapHook(dev.auth)was called at bundle-complete time and the resolved value stored. This means OAuth tokens captured at startup could go stale. Auth is now resolved lazily each time a session starts.Handler reserved keys proxied to remote stub — workerd probes service binding entrypoints for lifecycle handler methods (
tail,trace,scheduled, etc.) by accessing those properties. Without a guard these fell through to the capnweb stub, returning truthyRpcPromiseobjects and making workerd think the binding handled those events. Added aHANDLER_RESERVED_KEYSguard matching the existing pattern inexternal-service.ts.