Skip to content

feat(plugin): serve the device plugin of every cloud model without a cloud import - #295

Open
Hoeze wants to merge 12 commits into
Python-roborock:mainfrom
Hoeze:feat/plugin-fallback-catalog
Open

Hoeze wants to merge 12 commits into
Python-roborock:mainfrom
Hoeze:feat/plugin-fallback-catalog

Conversation

@Hoeze

@Hoeze Hoeze commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Without a cloud import, the server now answers the right Android device plugin for every model in the Roborock cloud's product list, not only for the a87, a15 and sc05. The data is a generated JSON file with the cloud's numeric product ids and plugin records. A script rebuilds it with any cloud login.

Problem

The app requests its device plugin with the numeric product id from /api/v5/product. With a cloud import, #224 takes that id from the import. Without one, the server knew the id for three models only, through MODEL_PRODUCT_ID_OVERRIDES. Every other model got a hashed id, for example 659231 for the a307, and the hardcoded APPPLUGIN_LIST had no record for it. So a scratch-onboarded server could not serve the plugin of most models.

Change

  • bundled_backend/shared/device_plugin_catalog_eu.json holds the numeric product id of 81 models and the Android plugin record of 79 products, from the EU cloud. The file records the cloud base URL, the region and the fetch time.
  • bundled_backend/shared/device_plugin_catalog.py loads every device_plugin_catalog_<region>.json and merges them per model. It replaces MODEL_PRODUCT_ID_OVERRIDES, and APPPLUGIN_LIST now holds the EU catalog records. The merged catalog is built once per region.
  • One helper, resolve_product_ids, gives each product its numeric id, for /api/v5/product and /api/v1/appplugin alike. The order: the id from the account's cloud import (fix(plugin): resolve string product ids and serve the iOS app plugin #224), a numeric id from the inventory, the catalog id of the model, and the hashed id as before. A model gets its catalog id only if no other model on the server holds that id. A snapshot plugin record also holds its id, for the model that the snapshot's home data names. So each id belongs to one model, and the record of a device that has left the inventory never reaches another model.
  • /api/v1/appplugin keeps the rules of fix(plugin): answer /api/v1/appplugin with the requested products only #288. For each requested id, it takes the snapshot's records. Otherwise, it finds the model that has the id, and answers that model's catalog record, with productid set to the requested id. An id without a model, or with two models, gets [].
  • The importer fetches the device plugins by the product list id of each model, the same id that /api/v5/product sends. Before, it used the numeric home-data id, so a different id left the imported plugin unused.
  • scripts/refresh_device_plugin_catalog.py rebuilds a regional file. With --source-json and raw user data, it takes --email as the username. It stops with an error if /api/v1/appplugin answers no record. It writes a .tmp file first, so a crash keeps the old catalog, and a failed write removes the .tmp file.
  • endpoint_rules.py loses _build_product_response. Nothing called it, because /api/v4/product and /api/v5/product use product_service.build_product_response.

Ids, models and regions

The app takes the numeric product id from the server's /api/v5/product and sends it back to the server's /api/v1/appplugin. The cloud never sees it. So the ids only have to agree inside the server: each id belongs to one model, and the answer for an id is that model's plugin. The ids differ by region: the a199 is 199 in the US and 185 in the EU, and 199 is the a226 in the EU. That is why this PR looks up catalog records by model and not by id. A US import and the EU catalog can then never hand a device another model's plugin.

The plugin files differ by region too, because each region hosts its own. For the a87 and the a15, the old built-in records (US hosts) and the EU records have the same versions (6058 and 5208), but different files. The sc05 differs (90 against 108). So the server merges the catalogs of all regions per model. A model takes its record and its id from the first catalog that has a record for it: the catalog of the server's region, then the EU catalog, then the other catalogs by region name. The server's region is the region of the cloud import (meta.base_url, else the account's region), else network.region. An earlier catalog may give the same id to another model. Then the model gets a hashed id, and it still gets its record. Only the EU catalog exists so far. So a server in another region gets the EU record of the same model, which is unverified. Without the catalog, that device would get []. A catalog for another region needs only a run of the refresh script with an account there.

Category Products Android plugin records
robot.vacuum.cleaner 56 56
roborock.wetdryvac 13 13
roborock.mower 6 6
roborock.wm 4 4
roborock.mowbs 2 0

The two models without a record are roborock.mowbs.a355 and roborock.mowbs.a384 (WiFi Amplifier Charging Station). A second request with only their ids also answered no record.

The data comes from the EU cloud (https://euiot.roborock.com), with an account that owns no devices. The product list came from GET /api/v5/product. The records came from one POST /api/v1/appplugin request with {"type": 2, "apilevel": 10046, "productids": [all 81 ids]}, which is the body of the Android app 4.60.06.

Changed behavior

  • a87: the product id moves from 110 to 103. In the EU cloud, 103 is the a87 (Qrevo MaxV), and 110 is the Zeo Lite washer (roborock.wm.a91). With both ids in one list, two models would share 110. The a87 record keeps version 6058.
  • a15: still 23, still version 5208. The URL now points to the EU mirror.
  • sc05: still 10001. The record moves from version 90 to the cloud's current version 108.
  • With a cloud import, the import's id now wins over these ids. On main, the overrides win, so after an EU import the a87 gets 110, the washer's id there.
  • A catalog record now goes only to an id that a paired device holds. On main, any id in the built-in list gets its record. The app asks only for ids from /api/v5/product, which lists the paired devices.
  • Without ids, the route answers the full list as before. On a server without a snapshot, that list now starts with the lowest product id (4, roborock.vacuum.s6) instead of the a87 record.
  • The catalog has Android records only, like the old APPPLUGIN_LIST. The iOS records of fix(plugin): resolve string product ids and serve the iOS app plugin #224 still come from the snapshot. fix(plugin): answer /api/v1/appplugin with the requested products only #288's comment on Android zips for iOS requests still applies.
  • Imports made since fix(plugin): resolve string product ids and serve the iOS app plugin #224 store the product list, but they fetched the plugin records by the numeric home-data id. A model whose two ids differ finds no snapshot record and gets its catalog record. Run the import again after the update, so it fetches the records by the product list id.

How to refresh the data

Any Roborock account works, also one without devices:

uv run python scripts/refresh_device_plugin_catalog.py --email you@example.com

The script asks Roborock for a login code and reads it from the terminal. --source-json reuses a stored login in the formats that import_web_inventory_from_cloud.py --source-json accepts. --base-url selects another region. The script takes the region from the cloud host, or from --region, and writes device_plugin_catalog_<region>.json. It makes two cloud requests, writes only the catalog, and prints the models without a plugin record.

Open question: rriotids differ from product_catalog.json

The EU cloud gives every model a different rriotid than product_catalog.json. All 51 models that both lists have differ, and none match. So the rriotid seems to depend on the cloud region, and product_catalog.json likely comes from another region. The numeric ids partly agree: the a15 (23) and the sc05 (10001) match the old overrides, and the a87 does not (110 against 103).

This PR leaves product_catalog.json as it is. Onboarding stores the catalog rriotid, and /api/v5/product answers the same value, so the app still joins device and product. The server uses the numeric id only between its own /api/v5/product and /api/v1/appplugin. Without an import, these ids only need to agree with each other. With an import, the import's ids win, and the guard keeps the two id spaces apart.

Models in only one of the two lists:

  • Only in product_catalog.json: roborock.vacuum.a140, roborock.vacuum.a246, roborock.vacuum.a34.
  • Vacuums only in the EU cloud: roborock.vacuum.a226, roborock.vacuum.a232, roborock.vacuum.a328, roborock.vacuum.a389, roborock.vacuum.a62.
All 51 rriotid mismatches
Model product_catalog.json EU cloud EU numeric id
roborock.vacuum.a08 5PHxDTl0lbtWBEi22ov6hj 6t5OGALwYyq9vFnl62BYuW 11
roborock.vacuum.a10 4StIrRPopvz0ZzPN2o1sWy 7ggJhlYqQs58zKFAOgBPc1 21
roborock.vacuum.a101 3rMctAN2h7gewWfZgLNOdz 2MFSO1n8JFiRfv62xlADmh 109
roborock.vacuum.a104 7AQWqICyaBLKFcOiDtu8ky ZfkRY1ldQav0ZV7HwEng3 111
roborock.vacuum.a117 3hVxBJoGbDP2kv93Pcc1pb 2hQn0JzHiNQ35vO5ivl8b3 126
roborock.vacuum.a123 15zrEeDGib2Rn15gviBrvv 7S6884nZ0mDrq7kp19RZ3p 135
roborock.vacuum.a125 2BNKSSVJ0bsXHxTH3KLi6H 4Xf12di720F6qesRKfycCA 133
roborock.vacuum.a135 3D9rSKoTaOfI0gcf6zcbdu fbns45APpnI0M72jVDwd9 139
roborock.vacuum.a144 5OY3uePAU3xCcBKUfFxcED 2p7GFUkE4SOOSIO5HfDQpS 146
roborock.vacuum.a147 585rv0Obq0bq7yzrcmEdVf 1KtYm84Say3qrqaqNAWebE 148
roborock.vacuum.a15 1YYW18rpgyAJTISwb1NM91 4oT3mL3dB7GpIS77ZADOLs 23
roborock.vacuum.a156 g0hm04CP4C1iT8sS0Bnpn 6IApKn1vVzqlFpLYe0LFaQ 154
roborock.vacuum.a159 2j5VnNUMBJLRelsHF7Njmg 6GyGRYzZqDFUCSYVPRgzcH 156
roborock.vacuum.a168 4ERRv6L8uw8POy0ueLjFxj pbz98A77my6QRtHQskKdz 163
roborock.vacuum.a170 7M4dAzHEgGusWLXkvgbLbL 4oVepXHU3bW0MB4kRHnOWm 165
roborock.vacuum.a179 h53cll17CJO53LaiWx3vd 4Ov5HOF4DSflrFPHptk0w7 179
roborock.vacuum.a185 6O6vtRc0hqwOUrgCla43LY 6GGPVYxOuz6vbimp0SVp5w 175
roborock.vacuum.a187 2CjvhDFL7Q9NdJQmhE86zn 7gkjgsDwbTIwhqpDKoETBi 177
roborock.vacuum.a19 5fLhydOIblbngogVGdU8Jw 497pdG4KW89b2fXwXXbAp9 26
roborock.vacuum.a197 5BvMJHXT8IKv4x4l0LU0er 5ha5sFvFvdITRP5QUAJXta 183
roborock.vacuum.a199 3PWf17rt73QjM3F1DaZelu 52SDKUl9N1mAqUTUlVlBnk 185
roborock.vacuum.a205 3oaoyfO05M0tZoOXvtH2v6 5AyfS82NRjCTWyqaZ33iOF 189
roborock.vacuum.a21 1Gc3InagdnSm1JPhQ7TPiU 7XJg0gp4iNM0FDtdcLl48d 35
roborock.vacuum.a245 64Pgg7cwjxHqT2qQrEh7Ib 35UTzLf1vJNv8ZUV67TcNC 209
roborock.vacuum.a27 3FvTMilsXUPmxlqAeOsIrB 42yfoQm5eOY3gARZw6xgU 41
roborock.vacuum.a279 1yhOql5rqTWqyFtU4dg8O9 2TbfeYcHq0FOyKskAVGTHv 244
roborock.vacuum.a288 1KuWrSJHhHe7lOvyuefM7x 3eizObJLFvPAxXvdW96ftd 251
roborock.vacuum.a294 72bzD7888QqxdmRHNA74E7 aZagb9tLAoAq2UbmGnFx0 255
roborock.vacuum.a296 RzNz70g002C6hAyIppc9Q 3PlD6TMLNY5LwI8kwxntCL 257
roborock.vacuum.a298 6Thza6zTK1AHOYGiNPugak 3KsqEpbY6FTrU4mKH46SmB 259
roborock.vacuum.a30 1v5nXqpWY8FiCfmsoIApP7 tvrfviO3uXoYL72vcXYOs 80
roborock.vacuum.a307 4J89YHjAc2uUG9W0HLxKPP 2Rr24hQJmvHyJzqB7ljK2y 263
roborock.vacuum.a326 4Snq4xVLaWSyq2PjbSGV1j 6HlbEc7sRDfEaxFEwBeHJG 273
roborock.vacuum.a38 63dnvWbeJYQ09VhrqvUJ4g 7kamVau2Xpgoj0dCdS7230 56
roborock.vacuum.a40 uqdBrJSn1yke0E5AayqmE 40NMBhdhC1ML9ptLiMIC2T 60
roborock.vacuum.a51 2LwHTkAMUb3RKxUBFvQzgM 1YHt9M9RESPHmiQFrrPw1S 88
roborock.vacuum.a65 1jWVq0qkthUqXggImMutvr sFW9mQ4M0YyE8OptxSbmG 92
roborock.vacuum.a70 5sYzP4uUXS6dTMZPoTakvU 2rqIfLiubPlddpYoWfBTl7 91
roborock.vacuum.a72 1yyDvxjxA23iHkUtnq6k5D 5ZuoVsCgt96KKxvDKCGEHe 84
roborock.vacuum.a73 1y5FvZEz6L6rtsFcFwWuGH 6cwszeXau9M2YrquXiSjJd 82
roborock.vacuum.a75 1JaaBKwzW2RFF9XZmH04TJ ldHlB6hwVPMvdm6AdkxJv 81
roborock.vacuum.a87 5gUei3OIJIXVD3eD85Balg 7HYigCZR9rr0vBtYPvch90 103
roborock.vacuum.a95 4CO3m8q3uF1h9s7n1FQ3dm 2YRm17wk0BaK6uu8bI1aKN 121
roborock.vacuum.a97 FI9ykCmTQOgMLP1i1Xyww 1vbAfJdO7IlyJyRGRfMQv 105
roborock.vacuum.s4 NYgv2MvTxT7UjaAS0ujPh 6kmXQYR5B2Canw2AuscVNO 5
roborock.vacuum.s5e 73EnOOM2NhDujvnvb7hvvv 42qYXusGAhtBh5L2Sa4SMV 13
roborock.vacuum.s6 7G2eVYbclOehHcpTf7P2mF 2ttN5avau73W2bjOwzn71a 4
roborock.vacuum.sc01 6yaImeCA2aoQAJQ5aAvwKD 1Wl34RgS6nWzI4LewgdLWK 10000
roborock.vacuum.sc05 5ayEx3aKgStqZZ0v5IpMBP 4qmLTqSG6Tb0WbnVhU0dfX 10001
roborock.vacuum.ss07 1O9BlCxWe4loekRE624qPv 3gKDz7BnDrjXOVBAEXj4uw 10002
roborock.vacuum.ss09 5SmbDEjAG5fpNlETF3jGK0 37p53dchJVjuUzqRopp3gb 10003

Related

Before you open this PR (optional, but very helpful)

  • I checked for duplicates. I searched open PRs and issues and nobody else is already working on this.
  • I reviewed 1-2 other open PRs and tested whether they work on my vacuum.

PRs I reviewed:

Proof that it works

Tested on:

  • Vacuum model: Roborock Saros 20 Flow (roborock.vacuum.a307)
  • Firmware version: 02.17.50
  • App: Android 4.60.06, patched for the local server
  • Server version / commit: aecdb11 of my fork's a307-plugin branch. That build is upstream main 2069fc7 plus this PR, my other open PRs, feat(api): enable scene tiles via productTags and category cardSpec #208 and one more a307 fix. The tests ran on this branch, rebased on upstream main f1e49fd.
  • Install method (Docker / Home Assistant add-on / other): built from source

What I did and what happened:

On main, the a307 gets the hashed id 659231. No plugin record has that id, so the a307 gets no plugin. Before #288, the app installed the a87 plugin instead and crashed.

After the deploy, the app requested its plugin with id 263. The server answered exactly the a307 record of the catalog (version 7046). The a307 opened, and its map loaded.

The fixes for the review came after this device test. My server has no cloud import and an EU config, so they leave its path unchanged: the a307 still gets 263 and the same record.

Tests:

  • New tests in tests/test_plugin_routes.py:
    • Without a snapshot, the a307 (263), the a226 (199), a wet and dry vacuum (180) and a mower (224) each get their own record.
    • A snapshot record wins over the catalog record.
    • Each catalog product id belongs to one model, each has at most one record, and every record URL passes the plugin proxy's host check, for every regional file.
  • New tests in tests/test_product_response.py:
    • The a307, a87, a15, sc05 and a wet and dry vacuum get their catalog id in /api/v5/product. An unknown model keeps the hashed id. A numeric inventory id wins over the catalog id. The import's id wins over both.
    • End to end without an import: the a307 gets 263 in /api/v5/product, and /api/v1/appplugin with that id answers exactly the a307 record.
    • An EU import that lacks a model: the model gets its catalog id and record.
    • A US import with the a199 at 199 and a later a226: the a226 gets a hashed id and its own record. A request for 199 gets the a199 record, or the snapshot's record if there is one.
    • A US import with the a87 at 110: the a87 record, with productid 110. An a87 that keeps a numeric 110 without a snapshot also gets the a87 record, and never the washer's.
    • An id that two models hold, or that no device has: [].
    • The region comes from meta.base_url, the account's region or the config. A US server takes a model from a US catalog first, then from the EU catalog, then from the other catalogs by region name. A record wins over an id without a record. An id that an earlier catalog gives another model becomes a hashed id, and the model still gets its record.
    • Two a307 on one server get one product and the a307 record. With two different home-data ids, they get two products, and each id answers the a307 record.
    • A shared a307, in receivedDevices or received_devices, gets 263 and its record.
    • A snapshot whose product list or plugin catalog is an error entry still gives the a307 263 and its catalog record.
    • A snapshot record whose device has left the inventory keeps its id. A later a226 gets a hashed id and its own record, for an Android or iOS record, whether the snapshot's home data names the a199 or not. A paired a15 that the snapshot's home data names for 23 keeps 23 and its snapshot record.
    • The merged catalog is built once per region.
  • tests/test_refresh_device_plugin_catalog.py: the script asks for all ids in one request and writes a sorted catalog with its region. Raw user data with --email gets that username. An answer without a record stops the script. The catalog file is replaced, and a failed write keeps the old file and leaves no .tmp file.
  • Import tests in tests/test_cloud_plugin_catalogs.py: the a307 at 4242 in home data and 263 in the product list fetches the plugin for 263. If the product list fails, a string id stores an error and requests no plugin, and a numeric home-data id is still fetched.
  • Full suite: uv run --extra dev pytest -q passes (797 tests).
  • uvx ruff check reports no new findings on the changed files.

Screenshots (required for any UI change)

No UI changes.

Copilot AI balanced review requested due to automatic review settings November 21, 2026 21:42

Copilot AI 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.

🟡 Changes recommended

Unresolved product-ID collisions and model-ID mismatches can serve the wrong or Android-only plugin, while the documented raw user-data import fails because it omits the username override.

4 open issues
What changed in this PR

Expands the local server’s Android device-plugin fallback beyond three models, building on #288’s requested-product filtering and #224’s cloud-import support.

Changes:

  • Adds a generated EU catalog containing numeric IDs for 81 models and 79 Android plugin records, plus a refresh script.
  • Prioritizes imported product IDs and plugin records, with catalog fallback and a cross-region model guard.
  • Adds tests for ID precedence, plugin selection, catalog consistency, and refresh generation.
File Description
tests/​test_refresh_device_plugin_catalog.py Tests bulk fetching and sorted catalog generation.
tests/​test_product_response.py Tests product-ID precedence and end-to-end plugin lookup.
tests/​test_plugin_routes.py Tests filtering, snapshot precedence, and fallback guards.
src/​roborock_local_server/​bundled_backend/​shared/​device_plugin_catalog.py Loads built-in model IDs and Android plugin records.
src/​roborock_local_server/​bundled_backend/​shared/​device_plugin_catalog.json Supplies generated EU product and plugin data.
src/​roborock_local_server/​bundled_backend/​shared/​constants.py Removes the three-model ID overrides.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​plugin/​common.py Replaces hardcoded plugin records with catalog data.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​api/​v1/​appplugin.py Filters requested IDs and guards catalog fallback.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​api/​product_service.py Resolves IDs using import, inventory, catalog, then hash.
src/​roborock_local_server/​bundled_backend/​https_server/​endpoint_rules.py Updates the legacy product builder to use catalog IDs.
scripts/​refresh_device_plugin_catalog.py Rebuilds the bundled catalog using a cloud login.

Review effort: Balanced

@Hoeze
Hoeze force-pushed the feat/plugin-fallback-catalog branch from 9ba0071 to dee8f75 Compare November 21, 2026 23:55
@Hoeze

Hoeze commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

I pushed fixes for the four review findings. Beyond them, 85740de and dee8f75 make the catalog regional. The plugin files differ by region, so the server merges the catalogs of all regions per model. A model takes its record from the catalog of the server's region first, then from the EU catalog, then from the other catalogs. The server's region is the region of the cloud import, else network.region. Only the EU catalog exists so far, and a catalog for another region needs one run of the refresh script with an account there. The section "Ids, models and regions" in the description explains the rules. 11f0c02 adds tests for two vacuums of one model, shared devices and catalog error entries.

…cloud import

Without a cloud import, the server knew the numeric product id and the
Android plugin record of three models only (a87, a15, sc05). Every other
model got a hashed product id in /api/v5/product, and /api/v1/appplugin
had no record for it.

The new shared/device_plugin_catalog.json holds the EU cloud's numeric
product id of 81 models in five categories, and the Android plugin
record of the 79 products that have one. It replaces
MODEL_PRODUCT_ID_OVERRIDES and the hardcoded APPPLUGIN_LIST.
scripts/refresh_device_plugin_catalog.py rebuilds it with any cloud
login, in two requests.

/api/v5/product takes the product id from the account's cloud import
first, then a numeric id in home data, then the catalog id of the model,
then the hashed id. Product ids differ by cloud region, so the import's
id now also wins over the old hardcoded ids. Before, the a87 got 110
even with an EU import, and in the EU cloud 110 is the Zeo Lite washer
(roborock.wm.a91). Without an import, the a87 now gets the EU id 103.

/api/v1/appplugin answers the catalog records for the product ids that
the cloud snapshot has no record for, like the built-in list before. It
skips an id that the cloud import gives to another model than the
catalog does, because that record would be the plugin of another model.
…ogin

A raw user data file has no username, and the import helper needs one.
The refresh script did not pass --email on, so --source-json with raw
user data failed with "Username is missing". It now passes the email as
the username override, and the help text says so.
…model

The local /api/v5/product gives a model the id of the cloud's product
list, but the import fetched the plugins by the numeric home data id. If
the two ids differed, the snapshot had no record for the id that the app
requests, and the app got the Android-only built-in record, also on iOS.
The import now takes the product list id of each model first, then the
numeric home data id, like /api/v5/product.
Product ids differ by cloud region, so a built-in record looked up by
its EU id could be the plugin of another model, like the washer record
of 110 for an a87 with a US import.

/api/v5/product now resolves the ids of all home data products in one
helper: the import's id, then a numeric home data id, then the built-in
id if no other model holds it, then the hashed id. For an id that the
snapshot has no record for, /api/v1/appplugin answers the built-in
record of the model that gets the id, with the requested id. An id that
no device has, or that two models get, gets no record.
The built-in catalog is now one file per cloud region,
shared/device_plugin_catalog_<region>.json, and the current one is the
EU catalog. The server takes the region of its cloud import: the region
of meta.base_url, else the region in the user data. Without an import,
or if the import's region is unknown, it takes network.region from the
config.

The id resolution and the plugin lookup by model use the catalog of
that region. A region without its own catalog uses the EU catalog, so a
device gets the EU record of its model. The refresh script writes the
file of the region. It takes the region from the cloud host, or from
--region for an unknown host.
…errors

Two devices of one model get one product id, and the id still gets the
plugin record of the model. A shared device gets its built-in id and
record from both inventory spellings of the shared device list. A failed
product or appplugin request in the snapshot falls back to the built-in
id and record. The import stores the error of a failed product list and
fetches the plugins by the numeric home data id, if there is one.
…odel

A model that the catalog of the server's region lacks now takes its record
from the EU catalog, then from the other catalogs by region name. Before,
the server used one catalog only, so such a model got no plugin.

The id comes from the same catalog as the record. If an earlier catalog
gives that id to another model, the model gets a hashed id, and
/api/v1/appplugin still finds its record by model.

Only the EU catalog exists so far, so nothing changes yet.
@Hoeze
Hoeze force-pushed the feat/plugin-fallback-catalog branch from dee8f75 to 046a0ed Compare November 22, 2026 21:50
@Hoeze
Hoeze marked this pull request as ready for review November 22, 2026 21:51
@Hoeze
Hoeze requested a balanced review from Copilot November 24, 2026 13:30

Copilot AI 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.

🟡 Changes recommended

Unresolved plugin ID collisions can cause /api/v1/appplugin to serve the wrong model’s plugin when product catalog retrieval fails or an inventory ID conflicts with a snapshot mapping.

2 open issues
4 resolved since last review

Review effort: Balanced

/api/v1/appplugin matches a snapshot plugin record by its product id alone. If the record's device has left the inventory or has not paired, no model holds that id. Another model then got the id as its built-in id, and the app installed the record's plugin for it. For example, a US import stored the a199 plugin at 199. The EU catalog gives 199 to the a226, so an a226 got 199 and the a199 plugin.

This happens if the import has no product list. Imports before Python-roborock#224 stored none, and neither does an import whose product list request failed. Such an import fetched the records by the numeric home data ids.

The record now holds its id for the model that the snapshot's home data names, else for an unknown model. A paired device of the named model keeps the id and the record. The iOS test fixture gets the product list of a current import, because a real import never writes records without home data.

Copilot AI 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.

🔵 Needs a closer look

Replacing non-EU plugin binaries with EU fallbacks leaves cross-region runtime compatibility unverified, requiring human review or representative non-EU on-device validation.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@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 (nits)

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

What was checked

  • The data in device_plugin_catalog_eu.json matches RR_API/hermes/update_manifest.json (the EU product list): all 81 models have the same numeric ids, with no differences. The manifest also backs up the PR's claims. In the EU list, 103 is the a87 and 110 is roborock.wm.a91. In the US list, the a87 is 110, and 199 is the a199 (185 in the EU, where 199 is the a226). 53 models have different ids in the two regions, so looking records up by model and not by id is the right design.
  • The app gets its product list from GET /api/v5/product (the ProductService in the bundled feature plugins of the 4.64.06 APK). The part of the app that calls /api/v1/appplugin is not in the decompiled sources, so the claim that the app sends back the id from /api/v5/product can't be checked here.
  • SSRF / open proxy: this PR adds no new outbound fetches at runtime. Every catalog URL still goes through proxied_plugin_records, then through the existing host allowlist in is_allowed_plugin_source (https only). The catalog's hosts are app-files.roborock.com (51 records), files.roborock.com (9) and cdn.awsde0.fds.api.mi-img.com (19). The last one is allowed by the .fds.api.mi-img.com suffix rule, so the EU mirror URLs (for example the a15) still go through the proxy. The proxy, its cache file name (a sha256 digest, so no path traversal) and its write through a temp file are unchanged.
  • Auth: this PR adds no new route. /api/v1/appplugin and /api/v5/product keep their current access rules. The data they answer is the public plugin catalog.
  • Stacking: this PR is not stacked on #292. They share no commits. Both PRs edit shared/constants.py in hunks next to each other (this one removes MODEL_PRODUCT_ID_OVERRIDES, and #292 adds REGION_COUNTRY right after it), so git merge-tree reports a conflict. Whichever PR is merged second needs a small rebase.

Nits

  1. https_server/endpoint_rules.py:508: nothing calls _build_product_response. /api/v4/product and /api/v5/product both use product_service.build_product_response. This PR updates both copies. Delete the unused one, so a later id change can't update only one of them.
  2. Each /api/v1/appplugin request with ids now reads and parses the cloud snapshot JSON several times on the request path: in server_cloud_region (routes/plugin/common.py:124), in snapshot_plugin_records, in snapshot_plugin_catalog_data, in snapshot_plugin_record_owners and inside home_payload. It also rebuilds the merged catalog in catalog_for_region (shared/device_plugin_catalog.py:71). /api/v5/product does most of this too. With a large snapshot, this blocking IO slows the event loop. Suggestions: cache catalog_for_region per region (the catalog files are fixed at import time), and load the snapshot once per request and pass it down.
  3. scripts/refresh_device_plugin_catalog.py:106: if /api/v1/appplugin answers something other than a list (an error dict, for example), records or [] keeps no records. The script then writes a catalog with no plugin records, without an error. It writes the file in place (line 156), so a crash in the middle leaves a truncated JSON file. The server reads every device_plugin_catalog_*.json at import time, so it would then fail to start. Fix: raise an error when the answer is not a non-empty list, and write to a .tmp file first, then replace() it.
  4. shared/device_plugin_catalog.py:147 and :163: a numeric home-data id (fixed_id) is used without checking holders. If an inventory from an older version still has a numeric id that the import's product list gives to another model, two models share that id. The built-in fallback then refuses the id (correctly), but the snapshot records still match the id alone. Real imports probably can't produce this (see the earlier Copilot thread). A one-line comment, or the same holders check for numeric home-data ids, would make it safe.
  5. Release note: imports made before this PR fetched the plugin records by the numeric home-data id. A model whose product list id is different now falls back to the EU built-in record until the user runs the import again. It is worth telling users who imported before this PR to run the import again.

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 passed auto review Automated review found no blocking issues label Nov 25, 2026
Nothing called _build_product_response in endpoint_rules.py. /api/v4/product and /api/v5/product both use product_service.build_product_response. The two helpers of the copy have their used versions in routes/user/homes/service.py. So a later change of the product ids has one place to go.
…talog atomically

If /api/v1/appplugin answered something other than a list of records, refresh_device_plugin_catalog.py wrote a catalog without plugin records and reported no error. It also wrote the file in place, so a crash left a truncated file, and the server failed to start on it. The script now raises an error if the answer has no record. It writes a .tmp file first and replaces the catalog with it. A failed write removes the .tmp file, so a package build can't ship it.
catalog_for_region merged the catalogs of all regions on each call, and /api/v1/appplugin and /api/v5/product call it on every request. The catalog files load at import time and do not change at runtime. So the merged catalog is now cached per region. Tests that swap a region catalog also swap the cache.
A numeric home data id can only be the import id of another model if the inventory and the import come from different regions. The comment says so, as the review asked.
@Hoeze

Hoeze commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I addressed the nits in four commits:

  1. 4d1d8b8 deletes _build_product_response and its two helpers from endpoint_rules.py, together with the test variants that called it.
  2. a7b07e8 builds the merged catalog once per region. The snapshot is still read several times per request. The routes on main read it the same way, so I'd leave one load per request to a follow-up PR.
  3. ba13a53 stops the refresh script if /api/v1/appplugin answers no record. The script writes a .tmp file first and then replaces the catalog. A failed write removes the .tmp file.
  4. ca3df62 adds the comment.
  5. The PR body now asks users to run the import again after the update. This concerns imports made since fix(plugin): resolve string product ids and serve the iOS app plugin #224, because older snapshots have no product list.

@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 (nits)

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

Since the last review (57c3634 → ca3df62)

  1. Unused _build_product_response in endpoint_rules.py: fixed (4d1d8b8). It is gone with its two helpers and the test variants that called it. /api/v4/product and /api/v5/product now have one builder, product_service.build_product_response.
  2. Repeated work on the request path: partly fixed (a7b07e8). catalog_for_region now caches the merged catalog per region in _MERGED_CATALOGS. That is safe, because CATALOGS is fixed at import time and every caller copies a record before changing it (dict(record, productid=...) in appplugin.py, dict(record) in proxied_plugin_records). The snapshot is still read and parsed several times per /api/v1/appplugin and /api/v5/product request. Deferring that to a follow-up is fine.
  3. Refresh script writing an empty or truncated catalog: fixed (ba13a53). fetch_cloud_answers raises when /api/v1/appplugin returns no dict record. write_catalog writes device_plugin_catalog_<region>.json.tmp, then calls replace(), and removes the .tmp file if that fails. The server's glob device_plugin_catalog_*.json does not match the .tmp name. The tests cover both.
  4. Numeric home-data id skipping the holders check: addressed with a comment (ca3df62). The comment is accurate. The id of an import's product list is used first for every model in that list, so the two ids can only clash when the inventory and the import come from different regions.
  5. Release note about running the import again: done in the PR body.

Conflicts: rebase needed

GitHub shows this PR as conflicting with main. git merge-tree finds two conflicts:

  • shared/constants.py: main added REGION_COUNTRY / region_country() right after MODEL_PRODUCT_ID_OVERRIDES. Keep main's additions and drop MODEL_PRODUCT_ID_OVERRIDES.
  • https_server/endpoint_rules.py imports: main moved to default_timezone from shared.data_helpers (#294), and DEFAULT_TIMEZONE is no longer imported there. Once _build_product_response is gone, the imports should be from shared.constants import DEFAULT_HOME_NAME, DEFAULT_PRODUCT_SCHEMA and from shared.data_helpers import as_bool, as_int, default_home_id, default_product_name, default_timezone, get_value. stable_int and MODEL_PRODUCT_ID_OVERRIDES are no longer needed.

product_service.py, data_helpers.py, the importer and tests/test_product_response.py merge cleanly. The merged build_product_response keeps main's "agreements": product_agreements() (#292) next to resolve_product_ids. With the two conflicts resolved as above, the full suite passes on the merge result (917 passed). On the PR head alone, 797 pass.

The two PRs fit together. #253 (now on main) refreshes the plugin catalogs through _fetch_plugin_catalogs, which calls _plugin_product_ids. With this PR, that refresh fetches the records by the product-list id too. So an admin Refresh plugins (POST /admin/api/cloud/refresh-plugins) should be enough for users who imported before this PR, and they don't need a full re-import. Consider mentioning that in the release note.

Overlap with #208

#208 (scene tiles) conflicts with this PR in routes/api/product_service.py and tests/test_product_response.py. #208 reads snapshot_plugin_catalog_data(ctx, "product") inline in build_product_response, and this PR moves that read into _served_products. Whichever is merged second has to read the cloud product payload once in build_product_response. It then passes the payload to _cloud_product_details (#208) and gets the ids from _served_products / resolve_product_ids (this PR). The two don't clash in behaviour: #208 also looks up productTags by model, not by id. #208 is also behind main's product_agreements() change.

Nits

  1. shared/device_plugin_catalog.py:71: _MERGED_CATALOGS is a module-level cache keyed by region. A test that changes CATALOGS has to reset the cache too. Two tests already do this (tests/test_product_response.py:482, :531). A small _reset_merged_catalogs() helper, or a fixture, would keep a future test from picking up a stale merged catalog.
  2. The snapshot is read several times per request (item 2 above). Still open, and fine as a follow-up.

Device compatibility remains unverified for serving an EU-hosted plugin record to a server in another region. The PR already says so.


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 commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Can you Fix conflicts? @Hoeze

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

passed auto review Automated review found no blocking issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants