Skip to content

fix!: Always consume latest registry in updateRegistry#3948

Merged
FrederikBolding merged 5 commits intomainfrom
fb/always-retry-ota-updates
Apr 9, 2026
Merged

fix!: Always consume latest registry in updateRegistry#3948
FrederikBolding merged 5 commits intomainfrom
fb/always-retry-ota-updates

Conversation

@FrederikBolding
Copy link
Copy Markdown
Member

@FrederikBolding FrederikBolding commented Apr 9, 2026

Always consume latest registry in updateRegistry in an effort to provide a way to retry failed OTA updates without requiring a registry update.


Note

Medium Risk
Changes the event contract between SnapRegistryController and SnapController, which affects when preinstalled Snap auto-updates and block/unblock checks run. Risk is moderate because it can alter update frequency/behavior even when the registry database is unchanged or fetch is skipped.

Overview
SnapController now reacts to a new SnapRegistryController:registryUpdated event instead of stateChange-filtering on database, ensuring #handleRegistryUpdate runs even when the registry fetch is skipped (recently fetched), the signature is unchanged, or an update fails.

SnapRegistryController publishes registryUpdated with a databaseUpdated boolean on all update paths, and tests/tooling are updated accordingly, including a new test that verifies preinstalled Snap OTA updates can be retried when the registry database itself did not update.

Reviewed by Cursor Bugbot for commit 621a01a. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.56%. Comparing base (79e8b90) to head (621a01a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ages/snaps-controllers/src/snaps/SnapController.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3948   +/-   ##
=======================================
  Coverage   98.56%   98.56%           
=======================================
  Files         427      427           
  Lines       12343    12345    +2     
  Branches     1939     1939           
=======================================
+ Hits        12166    12168    +2     
  Misses        177      177           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@FrederikBolding FrederikBolding requested a review from Mrtenz April 9, 2026 14:37
Copy link
Copy Markdown
Member

@Mrtenz Mrtenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, looks good to me otherwise

@FrederikBolding FrederikBolding marked this pull request as ready for review April 9, 2026 15:25
@FrederikBolding FrederikBolding requested a review from a team as a code owner April 9, 2026 15:25
@FrederikBolding FrederikBolding requested a review from Mrtenz April 9, 2026 15:25
@FrederikBolding FrederikBolding changed the title fix: Always consume latest registry in updateRegistry fix!: Always consume latest registry in updateRegistry Apr 9, 2026
@FrederikBolding FrederikBolding added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit d952951 Apr 9, 2026
130 of 131 checks passed
@FrederikBolding FrederikBolding deleted the fb/always-retry-ota-updates branch April 9, 2026 15:33
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 621a01a. Configure here.

this.update((state) => {
state.databaseUnavailable = true;
});
this.messenger.publish('SnapRegistryController:registryUpdated', false);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infinite loop when registry fetch fails with null database

High Severity

Publishing registryUpdated in the #update() error path creates an infinite loop when the database is null and fetches keep failing. #handleRegistryUpdate() fires, calls SnapRegistryController:get, which calls #getDatabase(), which calls requestUpdate() (because database is still null), which calls #update(), which fails again and publishes registryUpdated again — restarting the cycle. The old stateChange subscription with the ({ database }) => database selector prevented this because a failed fetch doesn't change database. The new unfiltered registryUpdated subscription removes that protection. Additionally, lastUpdated is never set in the error path, so #wasRecentlyFetched() never short-circuits the loop.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 621a01a. Configure here.

github-merge-queue bot pushed a commit that referenced this pull request Apr 10, 2026
BugBot indicated that my previous PR had a infinite loop in case of the
registry failure state:
#3948 (comment)

We do not need to emit `:registryUpdated` on failure, which should fix
this problem.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Low risk: a small behavioral change to event emission that only
affects failure paths, reducing the chance of update-trigger loops when
the registry is unavailable.
> 
> **Overview**
> Prevents `SnapRegistryController` from publishing the
`SnapRegistryController:registryUpdated` event when `#update()` fails
(e.g., fetch/verify errors), while still marking `databaseUnavailable`
in state.
> 
> Successful updates and no-op updates (recent fetch or unchanged
signature) continue to emit `:registryUpdated` as before.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
8af7c86. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants