Skip to content

fix(plugin): answer /api/v1/appplugin with the requested products only - #288

Merged
Lash-L merged 4 commits into
Python-roborock:mainfrom
Hoeze:fix/appplugin-product-filter
Nov 22, 2026
Merged

Lash-L merged 4 commits into
Python-roborock:mainfrom
Hoeze:fix/appplugin-product-filter

Conversation

@Hoeze

@Hoeze Hoeze commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

/api/v1/appplugin now answers only the records whose productid the app asked for. Before, it always answered the whole catalog. When the Android app opens a device, it installs the first record of that answer. So on a server without a cloud import, every device got the plugin of the first fallback entry, the a87.

Problem

The Android app (4.60.06) posts this body as JSON:

{"apilevel": 10046, "productids": [263], "type": 2}

When the app opens a device, it installs the first record of the answer and does not check its productid. The app's background plugin updater does check it. The route ignored productids and answered the full list. Without a cloud import, that list is APPPLUGIN_LIST, and its first entry is the a87 plugin (productid 110). A device of another model then gets the a87 zip, and the app crashes when it opens the device:

JSBigFileString::fromPath - Could not open file: .../files/plugin_v3/roborock.vacuum.a307/index.android.bundle

A cloud snapshot with several products has the same problem, because every device gets the first record.

Change

  • The route reads productids from the JSON body (__json) and from form fields, including repeated fields and comma-joined ids.
  • It picks the snapshot catalog as fix(plugin): resolve string product ids and serve the iOS app plugin #224 does: the iOS catalog for type: 1, else the Android one.
  • For each requested id, it takes the snapshot's records. For an id that the snapshot lacks, it takes the records of APPPLUGIN_LIST. So a device added after the cloud import still gets its plugin.
  • When ids are sent and none matches, it answers []. This includes ids that are not valid product ids. Without ids, it answers the full list as before.

This alone does not help a model that the catalog lacks. Such a model now gets [] instead of another model's plugin. My a307 (Saros 20 Flow, product id 263) also needed its entry in MODEL_PRODUCT_ID_OVERRIDES and APPPLUGIN_LIST. I'll send that as a separate PR, on top of the product id handling of #224.

Related

This PR is rebased onto #224. APPPLUGIN_LIST is the same for both platforms, so an iOS request for an id that no snapshot catalog has gets an Android zip. #224's fallback to the Android catalog has the same limit when the snapshot has no iOS catalog.

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: the device test ran on e839839 of my fork's a307-plugin branch. That build is upstream main 32608dd plus the first commit of this PR, the a307 catalog entry, feat(api): enable scene tiles via productTags and category cardSpec #208 and my other fixes for the a307. The tests ran on this branch, on upstream main 2069fc7.
  • Install method (Docker / Home Assistant add-on / other): built from source

What I did and what happened:

Before: opening the a307 in the app crashed with the error above, because the app had installed the a87 plugin.

After: the app installs the a307 plugin and opens the device. The review commits came later and are not deployed. They change only the answers for a snapshot without the requested id, for ids without any match and for iOS. My server has no snapshot, its a307 has a match, and I use Android.

Tests:

  • New tests in tests/test_plugin_routes.py failed before the change and pass after it. They cover the JSON and form bodies, the per-id snapshot and built-in lookup, the full list without ids, and [] for ids without a match, with and without a snapshot, and iOS requests with ids.
  • Full suite: uv run --extra dev pytest -q passes (515 tests).

Screenshots (required for any UI change)

No UI changes.

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

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.

🟢 Approval recommended

No active review issues remain for the requested-product filtering change.

No open issues 🎉

What changed in this PR

This PR updates /api/v1/appplugin to return requested products when matches exist, preventing the Android app from installing an unrelated catalog entry.

Changes:

  • Parses product IDs from JSON bodies and repeated or comma-separated form fields.
  • Filters both snapshot and fallback catalogs, preserving full-list responses when IDs are absent or unmatched.
  • Adds tests for request parsing, filtering, fallback behavior, and proxied plugin URLs.
File Description
tests/​test_plugin_routes.py Adds coverage for product filtering and full-list fallback behavior.
src/​roborock_local_server/​bundled_backend/​https_server/​routes/​api/​v1/​appplugin.py Parses requested product IDs and filters catalog records before proxying URLs.

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.

Checked:

  • Request body: confirmed. python-roborock sends {"apilevel", "productids": [id], "type": 2} as JSON and reads data[0]["url"] (roborock/web_api.py:794-801). The server stores JSON bodies under __json, so your JSON branch is the one the app hits.
  • Cloud filters by product id: confirmed indirectly. python-roborock asks for one id and takes the first record, which only works if the cloud returns just that product.
  • "App installs the first record without checking": partly contradicted.
    • The background plugin updater in the APK does check Product.getIntId() == PluginVersion.getProductid() and apilevel >= 10028.
    • The device-open install path isn't in the decompiled sources, so your crash log is the only evidence for that path.
    • Filtering is correct either way.
  • a307 needs an override entry: confirmed by the code. Its product id is a string, so without an override it hashes to an id that can never match, unless a cloud import exists (#224).

Conflict with #224: both PRs rewrite appplugin.build(). Resolving it as "pick the iOS catalog first, then filter by productids" passes all 494 tests, so please rebase onto #224 once it lands.

Nits:

  1. When ids are sent but none match, the route returns the full catalog, which is exactly the case that crashed the a307 (it gets the a87 zip first). Returning [] for "ids sent, none matched" is more faithful and fails cleanly. Keep the full list only for "no ids sent", and update the unknown_id case in test_app_plugin_answers_full_list_without_matching_product_ids.
  2. With a cloud snapshot present, only snapshot records are searched, so a device added after the import never reaches its APPPLUGIN_LIST entry.
  3. Please add a test for iOS (type: 1) combined with productids in the rebase.

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 21, 2026

@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.

TY!

@Lash-L

Lash-L commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Hey @Hoeze this has some conflicts, can you fix it?

@Lash-L
Lash-L marked this pull request as draft November 21, 2026 19:36
The Android app (4.60.06) posts {"apilevel": 10046, "productids": [id],
"type": 2} as JSON. It installs the first record of the answer and does
not check its productid. The route ignored the requested ids and always
answered the whole catalog. Without a cloud snapshot, every model then
got the a87 plugin, and other models failed to load it.

The route now keeps only the records whose productid is in the request's
productids. It reads the ids from the JSON body and from form fields.
Without ids, or when no record matches, it answers the full list as
before. The filter also applies to a cloud snapshot catalog.
With a cloud snapshot present, the route only searched the snapshot
records. A device added after the snapshot import then never got its
built-in APPPLUGIN_LIST record. Each requested id now uses the snapshot
records if the snapshot has that id, and the built-in records otherwise.
If the request sent product ids and neither the snapshot nor the built-in
list had them, the route answered the full list. The app then installed
its first record, which is the plugin of another model (the a87 plugin for
an a307), and crashed when it opened the device. The route now answers an
empty list in that case and keeps the full list for requests without ids.
The route picks the iOS catalog for type 1 requests and then keeps only
the requested product ids. The new tests check that an iOS request gets
the iOS record of the requested id, and the full iOS list without ids.
An id that only the Android catalog has gets the built-in record or
nothing, and an unmatched id gets an empty list.
@Hoeze
Hoeze force-pushed the fix/appplugin-product-filter branch from 78a20db to 0775e38 Compare November 21, 2026 20:50
@Hoeze

Hoeze commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the approval. I rebased onto main, which fixes the conflicts, and pushed these review changes:

  1. 069e215: when the app sends product ids and none matches, the route now answers []. Ids that are not valid product ids count as sent, so they get [] too. Without ids, it answers the full list as before. The unknown_id case is now its own test, for the built-in list and for a snapshot. I have not tested how the app handles [].
  2. b46aff1: a requested id that the snapshot lacks now gets its record from APPPLUGIN_LIST. A snapshot record wins over a built-in record with the same id.
  3. 0775e38: tests for iOS (type: 1) with productids. I resolved the conflict as you suggested: the route picks the catalog as fix(plugin): resolve string product ids and serve the iOS app plugin #224 does, iOS first, and then filters by productids.

One limit of the built-in fallback: APPPLUGIN_LIST is the same for both platforms, so an iOS request for an id that no snapshot catalog has gets an Android zip. #224's fallback to the Android catalog has the same limit when the snapshot has no iOS catalog. A comment in the code says so.

On the first record: yes, my crash came from opening the device. I changed the description and the code comment to say that opening a device installs the first record without the check, while the background updater does check the product id.

@Hoeze
Hoeze marked this pull request as ready for review November 21, 2026 20:51

@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 0775e38c, rebased onto #224)

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

Earlier nits:

Nit Status
Ids that matched nothing returned the full catalog Fixed: they now get []. A missing, null or empty productids still gets the full list. How the app treats [] is unverifiable, since its caller isn't in the decompiled sources.
With a snapshot present, a device added later never reached APPPLUGIN_LIST Fixed. Built-in records fill in missing ids, and a snapshot record wins over a built-in one with the same id.
No iOS + productids test Fixed: four iOS tests added.

How it combines with #224:

  • The catalog order is right: iOS snapshot → Android snapshot → built-in, then the productids filter.
  • Requests without ids behave as on main, on both platforms.

Minor, not blocking:

  • On iOS, an id missing from the iOS catalog falls back to an Android zip (the code comment says so).
  • A form-encoded iOS request is treated as Android. That comes from #224, and the app sends JSON.

Checks: 515 tests passed, and it merges cleanly. #295 is stacked on this PR, so this one should merge first.


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

Thanks @Hoeze

@Lash-L
Lash-L merged commit f1e49fd into Python-roborock:main Nov 22, 2026
3 checks passed
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