Skip to content

fix: serialize cached widget restores#63

Merged
homanp merged 1 commit intohomanp:mainfrom
mehdiraized:fix/widget-cache-restore-race
Mar 30, 2026
Merged

fix: serialize cached widget restores#63
homanp merged 1 commit intohomanp:mainfrom
mehdiraized:fix/widget-cache-restore-race

Conversation

@mehdiraized
Copy link
Copy Markdown
Contributor

@mehdiraized mehdiraized commented Mar 29, 2026

What

Fix two follow-up issues in the widget build cache flow:

  • serialize cached widget restores so concurrent requests cannot restore the same widget at the same time
  • keep the widget runtime working directory consistent between fresh-build and cache-restore paths

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 ready status while another had already terminated the runtime it depended on.

Also, the runtime cwd differed depending on whether the widget was served from a fresh build or from cached output. The current file server uses absolute paths, but keeping cwd consistent avoids subtle behavior differences and makes the runtime setup more predictable.

Test plan

  • Tests pass locally
  • Tested manually

Manual verification:

  • reviewed the restore path and confirmed concurrent restores are now guarded by a per-widget restore lock
  • confirmed the status is set to an in-progress state before awaiting cache restore, so later callers do not start competing restores
  • confirmed the upstream runtime now uses the same working directory convention in both fresh-build and cache-restore paths
  • verified the modified files are free of editor/type errors after the change

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 restoreLocks gate and setting an in-progress building status before awaiting the restore, so concurrent ensureWidget calls share the same restore attempt.

Aligns runtime behavior between build paths by creating the widget runtime with the cache root directory (not the dist directory) after a fresh build, matching the cache-restore cwd convention, and preserves existing error status without triggering competing restores/rebuilds.

Written by Cursor Bugbot for commit b2f9558. Configure here.

@github-actions github-actions bot added the contributor:verified Contributor passed trust analysis. label Mar 29, 2026
@homanp homanp self-assigned this Mar 30, 2026
@homanp homanp merged commit 4db3624 into homanp:main Mar 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:verified Contributor passed trust analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants