fix(runtime): seed registry with existing entries before watching#65
Merged
Conversation
The watcher-based registry initialized its SubscriptionRef with an empty map and relied on future filesystem events to populate it, so entries written before the subscriber started were invisible until the provider's next 30-second heartbeat. The polling fallback did not have this problem because it reads the directory immediately. Read the directory once during layer construction to seed the ref, and trigger one extra read after the watcher is subscribed so a change made between the initial snapshot and the watcher subscription is not lost. Reads are run sequentially so an older snapshot cannot overwrite a newer watcher-triggered one. Fixes #63 Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
|
Install the packages built from this commit: @distilled.cloud/cloudflare-rolldown-plugin bun add https://pkg.distilled.cloud/cloudflare-rolldown-plugin/8902f84@distilled.cloud/cloudflare-runtime bun add https://pkg.distilled.cloud/cloudflare-runtime/8902f84@distilled.cloud/cloudflare-vite-plugin bun add https://pkg.distilled.cloud/cloudflare-vite-plugin/8902f84 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #63.
Problem
On platforms where
CLOUDFLARE_RUNTIME_FILE_SYSTEM_SUPPORTS_WATCHERdefaults totrue,RegistryLiveinitialized itsSubscriptionRefwith an empty map and relied onfs.watchevents to populate it. Native watchers only report future changes, so a subscriber could not resolve workers whose registry entries existed before it started — resolution only began after a later filesystem event, typically the provider's 30-second heartbeat. This broke cross-process service bindings whenever the provider started before the consumer.Fix
SubscriptionRefwith the result, so entries written before the process started are resolvable on the first read in both watcher and polling modes.Stream.mapEffect, so an older snapshot cannot overwrite a newer watcher-triggered read.Tests
Added the regression test suggested in the issue: a provider registry writes its entry, then a second registry sharing the same
CLOUDFLARE_RUNTIME_HOMEis constructed and its first read must resolve the provider. The test runs in both watcher and polling modes and fails onmainin both (the polling fallback's first read was also racy, since its initial directory read ran in a forked fiber).Verified with
bun run checkand the registry, durable object, queue, and workflow test suites.Made with Cursor