fix: serialize cached widget restores#63
Merged
homanp merged 1 commit intohomanp:mainfrom Mar 30, 2026
Merged
Conversation
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.
What
Fix two follow-up issues in the widget build cache flow:
Why
The first cache persistence PR fixed rebuilds on every restart, but it introduced a race during cache restore.
If multiple requests hit the same widget before the first restore completes, they could all enter the restore path concurrently. Each restore attempt disposes the previous runtime, so one request could return a
readystatus while another had already terminated the runtime it depended on.Also, the runtime
cwddiffered depending on whether the widget was served from a fresh build or from cached output. The current file server uses absolute paths, but keepingcwdconsistent avoids subtle behavior differences and makes the runtime setup more predictable.Test plan
Manual verification:
Note
Medium Risk
Touches widget lifecycle/concurrency and runtime working-directory setup; mistakes could still cause transient bad statuses or serving failures under load, but the change is localized and guarded by per-widget locking.
Overview
Prevents races during widget cache restoration by adding a per-widget
restoreLocksgate and setting an in-progressbuildingstatus before awaiting the restore, so concurrentensureWidgetcalls share the same restore attempt.Aligns runtime behavior between build paths by creating the widget runtime with the cache root directory (not the
distdirectory) after a fresh build, matching the cache-restorecwdconvention, and preserves existing error status without triggering competing restores/rebuilds.Written by Cursor Bugbot for commit b2f9558. Configure here.