Repository navigation
Refresh the plugin catalogs on demand with the stored cloud login - #253
Conversation
2194577 to
a5f4c29
Compare
a5f4c29 to
402702a
Compare
There was a problem hiding this comment.
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.appfeaturepluginwithtype/apiLevelmatches the APK'sIPluginApi, andmeta.base_urlis used for the region. - Client id:
device_identifieris now saved at sign-in, soheader_clientidstays stable. - Failure handling: a total failure leaves the snapshot untouched, and a test covers it.
- Access: both routes call
_require_admin, and the cookie issamesite=lax, so a cross-site POST won't carry it.
Blocking:
- A partial failure overwrites good data (
cloud.py:195-205).- The guard only rejects the refresh when every catalog failed. If
appplugin_iosorapppluginerrors whilepluginssucceeds, 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.
- The guard only rejects the refresh when every catalog failed. If
- 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. Reuseatomic_write_inventory.submit_code(line 278) has the same pre-existing issue. - 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.
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>
402702a to
6b97054
Compare
|
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).
|
Lash-L
left a comment
There was a problem hiding this comment.
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_utcis updated even for catalogs kept from before, so those look fresh.kept_previousdoes 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.
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>
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>
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 loginAdd admin endpoints to refresh and list the plugin catalogsKeep stored plugin catalogs on partial failure and write the snapshot safelyGive 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-pluginsre-reads the plugin catalogs with the login the server stored at sign-in.GET /admin/api/cloud/pluginsshows what is stored without a cloud request, with each plugin's version, API leveland download URL.
kept_previousin the response (the only API addition). A refresh that fails completely changes nothing.submit_code, and writes are serialised with a lock. Ifa 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.
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.pyhas 25cases (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).