Skip to content

Refresh the plugin catalogs on demand with the stored cloud login - #253

Merged
Lash-L merged 6 commits into
Python-roborock:mainfrom
virtitnerd:pr/plugin-catalog-refresh
Nov 22, 2026
Merged

Lash-L merged 6 commits into
Python-roborock:mainfrom
virtitnerd:pr/plugin-catalog-refresh

Conversation

@virtitnerd

@virtitnerd virtitnerd commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #224. This branch is built on #224's head, so until that merges the diff also shows its one commit
(fix(plugin): resolve string product ids and serve the iOS app plugin). The commits that are new here are:

  • Refresh the plugin catalogs from the cloud with the stored login
  • Add admin endpoints to refresh and list the plugin catalogs
  • Keep stored plugin catalogs on partial failure and write the snapshot safely
  • Give each plugin refresh failure its own message

#255 (firmware updates) contains this branch, so merge this first.

Why

The plugin catalog is read once, during the cloud import, so it goes stale. In my setup the stock Android app (talking
to the real cloud) ran plugin 7006 for a Qrevo Curv 2 Flow while the iOS app, pointed at the local server, was served
5736. Re-running the whole import to refresh one list is heavy, and it needs a fresh email code.

What

  • POST /admin/api/cloud/refresh-plugins re-reads the plugin catalogs with the login the server stored at sign-in.
  • GET /admin/api/cloud/plugins shows what is stored without a cloud request, with each plugin's version, API level
    and download URL.
  • The import's own plugin fetch (from fix(plugin): resolve string product ids and serve the iOS app plugin #224) decides which platforms to fetch, so the refresh does not take a platform.
  • The refresh merges catalog by catalog: where a catalog errors, the stored entry is kept and its name is listed under
    kept_previous in the response (the only API addition). A refresh that fails completely changes nothing.
  • The snapshot is written atomically, by both the refresh and submit_code, and writes are serialised with a lock. If
    a sign-in finishes while a refresh is running, the refresh stops instead of overwriting the new login. The file is
    now created through a temporary file, so on POSIX it has mode 0600.
  • Failures get their own message: rejected login, rate limit, timeout, unreachable cloud, or other (stored catalogs
    kept). Only a rejected login tells the user to sign in again.

Testing

Tests for the refresh with a fake cloud, for the stored catalog and for the two endpoints, including that both need
the admin login, partial failure, the sign-in race, atomic writes and each error message. tests/test_cloud.py has 25
cases (was 12). Full suite: 520 passed, plus one failure in tests/test_log_retention.py that is intermittent on main too.

Related

#224 (the same stale-catalog problem for the iOS app).

@virtitnerd
virtitnerd force-pushed the pr/plugin-catalog-refresh branch from 2194577 to a5f4c29 Compare November 14, 2026 15:00
@virtitnerd
virtitnerd marked this pull request as ready for review November 15, 2026 15:20
@Lash-L Lash-L added area: official-app Official Roborock Android/iOS apps, login and plugins. blocked Waiting on an explicit dependency or maintainer hold; record the blocker. feature PR adding capability; under this two-type scheme also covers additive documentation. labels Nov 15, 2026
@virtitnerd
virtitnerd force-pushed the pr/plugin-catalog-refresh branch from a5f4c29 to 402702a Compare November 15, 2026 21:43

@Lash-L Lash-L left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review: changes requested

The design is sound. The new work beyond #224 is 44ed228d and 402702a9, and tests/test_cloud.py / tests/test_admin_api.py pass.

Confirmed:

  • Calls: the refresh reuses _fetch_plugin_catalogs. appfeatureplugin with type/apiLevel matches the APK's IPluginApi, and meta.base_url is used for the region.
  • Client id: device_identifier is now saved at sign-in, so header_clientid stays stable.
  • Failure handling: a total failure leaves the snapshot untouched, and a test covers it.
  • Access: both routes call _require_admin, and the cookie is samesite=lax, so a cross-site POST won't carry it.

Blocking:

  1. A partial failure overwrites good data (cloud.py:195-205).
    • The guard only rejects the refresh when every catalog failed. If appplugin_ios or appplugin errors while plugins succeeds, the error entry replaces the good stored catalog. One way this happens is "No product ids available" (import_web_inventory_from_cloud.py:461).
    • The fallback then serves iOS the Android zips, which #224 says the iOS app can't load.
    • Fix: merge catalog by catalog and keep the previous entry wherever the new one has error.
  2. The snapshot write isn't atomic (cloud.py:205). This file holds the only stored login and is read on every request (routes/auth/service.py:57), so a crash or a concurrent read can see truncated JSON. Reuse atomic_write_inventory. submit_code (line 278) has the same pre-existing issue.
  3. Lost-update race (cloud.py:172 → 205). The refresh reads the snapshot, waits up to 120s on the cloud, then writes the whole file back. A sign-in that finishes in between is reverted to the old login. Take a lock, or re-read before writing.

Should fix:
4. Misleading error (cloud.py:190-193). Every exception is reported as "the cloud rejected the stored login… sign in again", including timeouts, an unreachable cloud and RoborockRateLimit. Telling users to re-run the rate-limited code login is the wrong advice in those cases.
5. Tests: add one for a partial failure (bug 1).

#255 depends on this PR.

I've converted this PR to draft while these are addressed. Mark it ready for review again once they're fixed and it will go through another review.


This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.

@Lash-L Lash-L added the failing auto review Automated review requested changes before merge label Nov 21, 2026
@Lash-L
Lash-L marked this pull request as draft November 21, 2026 16:07
virtitnerd and others added 4 commits November 21, 2026 19:13
The snapshot keeps the cloud login and the plugin catalogs fetched at sign-in, and the
plugin routes serve those. Newer robots can need newer plugins than the snapshot holds, so
CloudImportManager.refresh_plugin_catalogs asks the cloud again with the stored login and
replaces only the catalogs. The sign-in now also stores the device identifier the cloud
ties the login to. A rejected login or an empty answer leaves the snapshot as it was.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /admin/api/cloud/refresh-plugins re-reads them with the stored login, taking an
optional platform type. GET /admin/api/cloud/plugins shows what is stored without a cloud
request. Both return each plugin's version, API level and download URL.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… safely

A refresh where one catalog errored replaced the good stored entry with the
error, and the fallback then served iOS the Android zips. Merge catalog by
catalog and keep the previous entry wherever the new one has an error.

The snapshot holds the only stored login and is read on every request, so
write it with atomic_write_inventory (also in submit_code). The refresh now
re-reads the snapshot under a lock after the cloud wait, so a sign-in that
finished meanwhile is not reverted; if the login changed, the refresh stops
and asks to run again. The result gains kept_previous when entries were kept.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every exception was reported as a rejected login with advice to sign in
again, including timeouts, an unreachable cloud and RoborockRateLimit, which
made users re-run the rate-limited code login. Only RoborockInvalidCredentials
and RoborockAccountDoesNotExist now say to sign in again; rate limit, timeout
and connection errors get their own text, and anything else says the stored
catalogs were kept. The home-data helper now chains its RuntimeError to the
last error so the original type is visible to the classifier.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@virtitnerd
virtitnerd force-pushed the pr/plugin-catalog-refresh branch from 402702a to 6b97054 Compare November 22, 2026 02:39
@virtitnerd

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All five items are addressed in 447c106 and 6b97054, on top of current main. Hashes are from the pushed head (6b97054).

  1. Partial failure overwrote good data. Fixed in 447c106. The refresh merges catalog by catalog and keeps the stored entry wherever the new one has an error. The response lists those names under kept_previous. If nothing good was stored for a catalog, the error entry is stored as before. A full failure still leaves the snapshot untouched.
  2. Non-atomic write. Fixed in 447c106. The refresh and submit_code both write the snapshot with atomic_write_inventory. One side effect: the file is now created through a temporary file, so on POSIX its mode becomes 0600. That should be fine for a file holding a login token, but it matters if something reads it as another user.
  3. Lost-update race. Fixed in 447c106. The cloud wait runs without the lock. Afterwards the refresh re-reads the snapshot under a lock and replaces only the plugin catalogs on that fresh copy, so other changes made meanwhile survive. If the stored login token changed during the wait, it stops with "A new sign-in finished while the refresh ran. Run the refresh again." and writes nothing, because the catalogs were fetched with the old login. submit_code takes the same lock for its write.
  4. Misleading error. Fixed in 6b97054. Only RoborockInvalidCredentials and RoborockAccountDoesNotExist say to sign in again. RoborockRateLimit, timeouts and connection errors each get their own message, and anything else says the stored catalogs were kept. The cloud helper wrapped every error in a plain RuntimeError, so I chained the original with from last_error to keep its type visible. Errors other than a rate limit are still retried across the three endpoints first. I also removed the "sign in again" advice from the "no plugin catalogs" message, since that case cannot tell a rejected login from other failures.
  5. Tests. Added in 447c106 and 6b97054: partial failure (stored entry kept, and error stored when nothing was stored), the sign-in race, an unrelated snapshot change during the wait, the atomic writer at both write sites, a failed write leaving the file intact, and each error message including the cause chain.

tests/test_cloud.py went from 12 to 25 cases. Full suite on this head: 520 passed, plus one failure in tests/test_log_retention.py that is intermittent on main too. #255 contains this PR until it merges. It stays in draft as you set it; it is ready for another review whenever you want to run one.

@virtitnerd
virtitnerd marked this pull request as ready for review November 22, 2026 02:52

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review: passed (re-review at 6b97054e)

Now that this has passed the automated review, I'll do a human review and then either request changes or merge it.

Earlier findings:

Finding Status
A partial failure overwrote good catalogs Fixed. _merge_plugin_catalogs keeps the stored entry when the new one has error and reports it under kept_previous. A total failure still writes nothing.
Snapshot write wasn't atomic Fixed. The refresh and submit_code both use atomic_write_inventory.
Lost-update race with a sign-in Fixed. The cloud calls run without the lock. The snapshot is then re-read under _snapshot_lock, the refresh stops if the token changed, and only plugin_catalogs is replaced. There's no await inside the lock.
Every failure reported as "sign in again" Fixed. _describe_refresh_error follows the cause chain. Checked against python-roborock: an expired token is code 2010 (RoborockInvalidCredentials), network errors are wrapped from err, and RoborockRateLimit is re-raised.
No partial-failure test Fixed: tests for partial failure, the sign-in race, atomic writes and error messages.

Minor:

  • If the re-read snapshot is missing or corrupt, the user is told "a new sign-in finished while the refresh ran". That case should get its own message.
  • fetched_at_utc is updated even for catalogs kept from before, so those look fresh. kept_previous does flag them.

Checks: both admin routes call _require_admin, all 521 tests pass, and it merges cleanly.


This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles, refreshed 2026-11-21), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.

@Lash-L Lash-L added passed auto review Automated review found no blocking issues and removed failing auto review Automated review requested changes before merge labels Nov 22, 2026
virtitnerd and others added 2 commits November 22, 2026 11:09
When the snapshot vanished or was corrupted during the cloud wait, the refresh said a new sign-in had finished, which was wrong. It now says the stored login is missing or unreadable.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A kept catalog sat under a fresh top-level fetched_at_utc, so it looked as new as the ones just fetched. Kept entries now carry their own stamp, and the summary reports it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Lash-L
Lash-L merged commit d63f926 into Python-roborock:main Nov 22, 2026
3 checks passed
Lash-L added a commit to virtitnerd/local_roborock_server that referenced this pull request Nov 22, 2026
Resolves the conflicts left by the squash merges of Python-roborock#251 and Python-roborock#253:
keeps the firmware routes, store and admin endpoints from this branch,
keeps main's schedule create/update/delete routes, and checks the OTA
routes before the schedule update in the HTTP handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@virtitnerd
virtitnerd deleted the pr/plugin-catalog-refresh branch November 22, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: official-app Official Roborock Android/iOS apps, login and plugins. blocked Waiting on an explicit dependency or maintainer hold; record the blocker. feature PR adding capability; under this two-type scheme also covers additive documentation. passed auto review Automated review found no blocking issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants