Repository navigation
Proxy voice pack lists and packages for clients that pass our URL to the robot unchanged - #261
Conversation
There was a problem hiding this comment.
Automated review: changes requested
The proxy itself is safe and the tests pass. It works for a client that calls /voice-pkg/info and passes our URL to the robot unchanged, as in the a245 test via LocalRock, but not end to end for the official app's Language page.
Confirmed:
- Info path:
soundPackageFilePathbuilds/app/<bucket>/voice-pkg/or/<bucket>/app/voice-pkg/, addsdebug/for v2–v5, and has theppscouple/rubysc1special cases (tanos411.js:209-225). - Install RPC:
dnld_install_sound {sid, url, md5, sver}, plusget_sound_progress. - Security is fine:
- The hosts are fixed or allowlisted, and the path must contain
/voice-pkg/, end in.pkgand contain no... - Redirects aren't followed.
- The size caps (2 MB / 64 MB) and timeouts are enforced while streaming.
- No account data is sent.
- The hosts are fixed or allowlisted, and the path must contain
Blocking:
-
The official plugin undoes the URL rewrite. It builds the robot URL as
'https://' + getResHost(true) + url.split('.com')[1](tanos2512.js:537, hermesmodule_3672.js), so our host is discarded.- With no
.cominapi_url, the robot goes to Roborock's res host with the original path. - With
.comin it, the URL comes out garbled. us-app.roborock.comalso isn't inmitm_redirect.py's list, so the official app reads the real cloud anyway.
- With no
-
The legacy layout set is incomplete (
voice_pkg.py:102).tanosandtanosealso use/<bucket>/app/voice-pkg/(411.js:217-218), so t6, s6, t7 and a11 get the wrong path. -
Buckets are wrong for inherited configs. Where
forceRealResourceis false or unset, the parent's bucket applies:Model Correct bucket Line pearleh pearle44 vivianf vivian50 pandora vivian57 pearlfpro viviansc63 talcsc tanosslite86
Should fix:
4. Concurrent requests clash. Two requests for the same package write the same .tmp (lines 256-258), and info cache misses race too.
5. Minor:
rulackseu-app.roborock.comas its cosHost (line 29).- The package cache has no eviction.
- Tests: add cases for the tanos/tanose layout, the inherited buckets, and what the plugin's
split('.com')does to the rewritten URL.
Unverifiable: whether the firmware checks the local TLS cert or the md5 for a server-hosted URL.
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.
…page GET /voice-pkg/info?model=<model> (and the plugin's own /app/<bucket>/voice-pkg/info path) fetches the official plugin's voice pack info file from the region's cosHost, falling back to its FDS host, and serves the last good copy when both fail. Each voice_pkg_url is rewritten to /voice-pkg/files/<host>/<path>.pkg on this server, which downloads the pack once, caches it, and serves it to the robot, so the robot never needs to reach the cloud host itself. Model to bucket follows the plugin's device configs. Upstream requests carry X-RR-Voice-Proxy so a DNS loop back to this server answers 508 instead of recursing. Only allowlisted Roborock and Xiaomi FDS hosts are fetched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plugin's soundPackageFilePath uses /<bucket>/app/voice-pkg/ for Tanos, TanosE, TanosV, RubyPlus, RubySE and RubySC (p223 L281411-281523). The set was missing tanos and tanose, so t6, s6, t7 and a11 asked for the wrong path. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
createDeviceModelConfig takes bucket = product only when forceRealResource is truthy, otherwise the inherited config's bucket (p223 L281131-281183). PearlEH, VivianF, Pandora and PearlFPro pass false and TalcSC passes nothing, so they use pearle, vivian, vivian, viviansc and tanosslite. Every other inheriting entry passes true and keeps its own product name. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Two requests for the same package wrote the same .tmp file and both downloaded it, and concurrent info misses raced on the cache file. Callers with the same key now share one in-flight fetch, cache writes go through a unique temp file plus replace, and the package cache keeps the newest 64 files (hits refresh the mtime) and drops stale temp files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The plugin builds the robot URL as 'https://' + getResHost() + voice_pkg_url.split('.com')[1] (p223 L1318756-1318805), so our host never reaches the robot. Without a .com in our URL it falls back to the original path on Roborock's res host. With one it cuts at the first .com and sends a garbled path. Redirecting us-app.roborock.com through mitm_redirect.py is not a safe fix: the robot resolves that host itself and whether it accepts our TLS certificate or md5 is unverified. Only clients that pass the URL unchanged, such as LocalRock, install from this server. The module docstring and a test now state this.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Eviction can delete a package between the exists() check and read_bytes(). The hit path now reads once and falls through to a download if the file is gone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
64 files of up to 64 MB each could fill 4 GB, and any client can request packages. Eviction now also drops the oldest packages once the cache passes 512 MB. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The plugin's model list holds <short>v2 to <short>v5 (p223 L280750-280830, concat of prefix, '.', short, 'vN'), but the bucket lookup used the whole suffix, so those models returned unknown and the debug/ path was unreachable. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
e61e578 to
808e282
Compare
|
Thanks for the careful review. The branch is rebased on current main and the pushed head is Blocking
Should fix
Three small fixes I found while rechecking: a cache hit that disappears between the existence check and the read is now served as a miss instead of raising ( Still unverified: whether the firmware checks the TLS cert or the md5 for a server-hosted URL. I have updated the title and description. I will mark it ready for review again. |
Lash-L
left a comment
There was a problem hiding this comment.
Automated review: passed (re-review at 808e2826)
Now that this has passed the automated review, I'll do a human review and then either request changes or merge it. It's still a draft, so mark it ready when you're done.
Earlier findings:
| Finding | Status |
|---|---|
The official plugin's split('.com') discards our host |
Scoped out, and accurately documented in the title, body, module docstring and a test. The official app's Language page still won't use it. |
tanos/tanose legacy layout |
Fixed, and matches 411.js:213-221. |
| Inherited buckets (pearleh, vivianf, pandora, pearlfpro, talcsc) | Fixed, with a test. |
Concurrent .tmp clash |
Fixed. Same-key requests share one fetch, and writes use a unique temp file plus replace. |
ru cosHost |
You were right. The refreshed Hermes bundle has ksyru0-eco.fds.api.xiaomi.com for ru. Our earlier review used the old nonhermes value. |
| No cache eviction; missing tests | Fixed: capped at 64 files and 512 MB, and stale temp files are swept. |
Security re-check: still fine.
- Hosts are fixed or allowlisted.
- The path must contain
/voice-pkg/, end in.pkg, and contain no... - Redirects aren't followed, the size caps are enforced, and there's a loop guard.
Nits:
- The info cache file is keyed by path only, while the in-flight key includes the region. Add the region to the filename.
- Corrupt cached JSON makes the stale fallback raise an unhandled error.
- Files up to 64 MB are read and written with blocking calls on the event loop. Use
asyncio.to_threadandFileResponse.
Unverifiable: whether the firmware checks the TLS cert or the md5 for a server-hosted URL.
Checks: all 521 tests pass.
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.
The in-flight key already included the region, but the cache file name did not, so a stale answer cached for one region could be served for another whose upstream hosts differ. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The stale fallback parsed the cache file without any guard, so a truncated or hand-edited file raised an unhandled error instead of the usual 502. It now reads through a helper that returns nothing for a missing, corrupt or wrongly shaped file, and the original upstream error is raised. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Packages up to 64 MB were read, written and evicted with blocking calls inside the request handler. The writes, the eviction scan and the info cache read and write now run through asyncio.to_thread, and a cache hit is served with FileResponse so the file is streamed rather than loaded into memory. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Lash-L
left a comment
There was a problem hiding this comment.
Automated review: passed (nits) (re-review at 3d18c5f)
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 (808e282 → 3d18c5f)
| Earlier nit | Status |
|---|---|
| The info cache file was keyed by path only, while the in-flight key included the region | Fixed (79bb7b1). The file is now info-<sha256("region:path")>.json, and the in-flight key uses the same normalised region (voice_pkg.py:317-325). There is a test for it. |
| Corrupt cached JSON made the stale fallback raise | Fixed (1068169). _read_cached_info returns None for missing, unreadable or wrongly shaped JSON, so the request gets the normal 502 (voice_pkg.py:302-311). There is a test for it. |
| File IO on the event loop | Fixed (3d18c5f). The info cache write, the stale read, the package write and eviction now run in asyncio.to_thread. Cache hits are streamed with FileResponse instead of being read whole into memory (voice_pkg.py:291, 328, 348-359). |
Security re-check of the delta. Still fine.
- SSRF / open proxy: none. Info lists come only from the fixed
_REGION_HOSTS, and the path is built from the model table or matched by_INFO_PATH. Packages need an allowlisted host, a path containing/voice-pkg/and ending in.pkg, and no... Redirects are not followed (voice_pkg.py:108-113, 122-126, 159, 423-435). - Path traversal: none. Every cache filename is a sha256 hex digest, so nothing from the client ends up in a filesystem path.
- Atomic writes: each write goes to a unique temp file and is then renamed into place, and replacing a file that
FileResponseis still serving is safe on POSIX. - Memory: a cache hit is now streamed. A miss still buffers up to 64 MB before replying, which is the same as before and acceptable.
- Auth: the routes are unauthenticated, as for the plugin zip proxy, and no account data goes upstream.
Checked against the app: the info path builder (/app/<bucket>/voice-pkg/ or /<bucket>/app/voice-pkg/) is in hermes tanos module_1568.js:893-896. The voice_pkg_url.split('.com') rebuild onto the plugin's own host, followed by dnld_install_sound {sid, url, md5, sver, ota_url}, is in module_3672.js:1595-1611. Both match what the PR says, including the documented limitation that the official app's Language page does not use the rewritten URL.
Nits (non-blocking):
voice_pkg.py:348-353: the hit path checks the file withos.utimeand then returns aFileResponse. Starlette only stats the file when the response is sent. If the file is evicted or deleted in between, the request fails with a 500 (RuntimeError: File at path ... does not exist) instead of being treated as a miss. This window is much smaller than the one6af0ca9closed, because a just-touched file is the newest one and is unlikely to be evicted. The new test fakes the failure inutime, so it does not cover this window. Optional fix: have_touchreturn theos.statresult and pass it asstat_result=, or open the file in the worker thread and stream from that handle.voice_pkg.py:175-178:_cache_dir()still callsmkdiron the event loop on every request. This is trivial, but it could be done once or moved into the thread helpers.
Tests: the full suite passes on 3d18c5f (523 passed), and it merges cleanly with main. CI is green.
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 hit path touched the file and then returned a FileResponse, which stats and opens the file only when the response is sent. A file evicted in that gap raised instead of falling back to a download. The touch and read now happen together in one thread call and a vanished file is a cache miss. Packages are capped at 64 MB and the miss path already holds them in memory. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
_cache_dir ran mkdir on the event loop for every request. Only the atomic writer needs the directory, and it already runs in a worker thread, so the mkdir moves there and lookups just build the path. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Lash-L
left a comment
There was a problem hiding this comment.
Automated review: passed (nits) (re-review at 35f79fa)
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 (3d18c5f → 35f79fa)
Two commits went in after the 01:38Z review. Both only touch routes/plugin/voice_pkg.py and its tests.
| Commit | What changed | Status |
|---|---|---|
1bbf691 |
A cache hit is now read into memory (_read_cached_package, voice_pkg.py:210-216) and returned as a plain Response (voice_pkg.py:347-353) instead of a FileResponse. This closes the race where eviction could delete the file after the utime check but before FileResponse opened it, which gave a 500. |
Confirmed. The OSError from a missing file now falls through to a miss and a re-download. test_cache_hit_removed_after_the_touch_still_answers covers it. |
35f79fa |
_cache_dir no longer runs mkdir on every lookup (voice_pkg.py:175-176). _write_atomic creates the parent directory instead (voice_pkg.py:203-207). |
Confirmed. Both writers (the info cache at :291 and the package write at :219-221) go through _write_atomic. Eviction only runs after a write, so iterdir() never sees a missing directory (:224-228). The info stale read already treats a missing file as no cache (:301-311). There's a test for this too. |
Security re-check of the delta. Still fine.
- SSRF / open proxy: unchanged. The host allowlist, the path checks (
/voice-pkg/,.pkg, no..) and the no-redirect policy are untouched. The cache filename is stillsha256(source_url), so there's no path traversal. - Auth: unchanged. The route is unauthenticated, like the existing plugin zip proxy, and no account data goes upstream.
- Secrets in logs: nothing new is logged.
- Atomic writes: still a unique temp file plus
replace. Creating the directory inside the worker thread doesn't change that. - Cloud unreachable: unchanged. You still get the stale info, or the 502
voice_pkg_proxy_failed.
Nits (non-blocking)
- Memory on cache hits. Hits now load the whole package into memory, up to the 64 MB
VOICE_PKG_MAX_BYTES(voice_pkg.py:26, 214), and the hit path is not single-flighted. N concurrent hits mean N copies in memory. Real packs are about 6 MB, so this is fine in practice. Two options:- Wrap the hit read in
_single_flight(f"pkg:{cache_file}", ...). - Open the file handle inside the thread, then stream from that already-open fd. An unlinked file stays readable through an open fd on POSIX, so eviction can't cause a 500 and memory stays flat.
- Wrap the hit read in
- No Range support. Starlette's
FileResponsehonouredRange; a plainResponsedoes not. If the firmware resumes an interrupted download withRange, it will now get the full body with a 200. Whether the robot sendsRangeis unverifiable: nothing invac_firmware/Q7mentionsdnld_install_soundor a resume. The same is already true on the miss path, so this isn't a regression for first downloads.
Re-confirmed claims
- Scope is still stated accurately. The plugin rebuilds the URL from
host+split('.com')[1](RR_API/nonhermes/com.roborock.tanos/index.android.bundle:2518-2519), so the official app's Language page is still out of scope. Confirmed as documented. - Robot-side download behaviour: unverifiable. This covers the TLS cert check, the md5 check and Range. It rests on the author's live a245 test only.
Tests and merge
uv run --extra dev pytest -q: 525 passed, including the 2 new tests.git merge-treemerges cleanly against currentmain(which is 5 commits ahead), #255 and #252.
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 full suite passes (525 passed), and |
What and why
The official plugin's voice Language page lists the robot's voice packs and installs one by sending the robot a package URL. With the robot on the local server, the list request and the robot's download both go to cloud hosts that the local setup either answers with nothing or does not resolve. This PR lets the server fetch the list from Roborock, point every package URL at itself, and serve the packages to the robot.
This works for clients that hand the rewritten URL to the robot unchanged, such as LocalRock (installed end to end on an a245, see Testing). It does not make the official app's Language page work: the plugin rebuilds the robot URL as
'https://' + host + voice_pkg_url.split('.com')[1]on Roborock's own res host, which discards our host. Whether the firmware checks the TLS cert or the md5 for a server-hosted URL is unverified.How it works
GET /voice-pkg/info?model=<model>maps the model to the plugin's product bucket (for exampleroborock.vacuum.a245toberyllite) and builds the same info path the official plugin uses (/app/<bucket>/voice-pkg/info, the older/<bucket>/app/voice-pkg/infolayout fortanos,tanoseand the other legacy buckets, anddebug/forv2tov5models, which are looked up by their base model id). The model to bucket table comes from the plugin's device configs and follows inherited configs: where a config does not force its own resource bucket, the parent's bucket applies (for example pearleh usespearle). An unknown model gets a 404./app/<bucket>/voice-pkg/info, with or withoutdebug/) is answered the same way, so a request that reaches the server under the cloud path also works.us-app.roborock.com,eu-app.roborock.com,cn-app.roborock.com), then the region's FDS host, in the order of the plugin'sareaServerMap. For the a245 the list is only on the app host; the FDS host does not have it.voice_pkg_urlinvoice_list,special_voice_listandfactory_test_listis rewritten to<api_url>/voice-pkg/files/<host>/<path>.pkg, using the host the list came from. The original is kept invoice_pkg_source_url, andvoice_pkg_md5is left as is.GET /voice-pkg/files/<host>/<path>.pkgdownloads the package from that host once, stores it under<runtime_dir>/voice_pkg_cache/, and serves it to the robot from there afterwards.dispatch_plugin_zip_request: a path that is not a plugin zip is offered to the voice handler. Upstream failures become the existing 502 response with routevoice_pkg_proxy.Safety
*.fds.api.xiaomi.com/*.fds.api.mi-img.com, and the path must contain/voice-pkg/, end in.pkgand not contain... Anything else gets a 403 without a request upstream. Redirects are not followed, so an allowed host cannot send the server somewhere else.Content-Lengthover the cap is refused before reading, and the body is read in chunks that stop at the cap.X-RR-Voice-Proxy: 1. If DNS sends the cloud host back to this server, the request with that header gets a 508 instead of being fetched again.X-RR-Voice-Cache: stale) when every upstream host fails. Responses carryX-RR-Voice-Cache: hit,missorstale.voice_pkg_proxy_failed(the plugin proxy keepsplugin_proxy_failed).Testing
tests/test_voice_pkg_routes.pyhas 19 tests: model to path mapping (including theppscouple,rubysc1andrubysespecial cases, the tanos/tanose legacy layout, the inherited buckets,v2tov5model strings and an unknown model), list fetched from the region host with URLs rewritten to this server, fallback to the FDS host and then to the cached copy, 502 with no upstream, 404 for an unknown model, a package proxied once and then served from the cache, a package from an unknown host refused, the loop guard, a redirect not followed, the size cap enforced while streaming and fromContent-Length, concurrent requests sharing one upstream call, cache eviction, and what the plugin'ssplit('.com')does to a rewritten URL. Full suite on this branch: 521 passed.roborock.vacuum.a245):https://us-app.roborock.com/app/beryllite/voice-pkg/info. Through this route the server returned more than 20 packs with the URLs rewritten to<api_url>/voice-pkg/files/....dnld_install_soundwith the server URL, reported progress 100, state 3 andsid_in_use103 within about 4 seconds, and then switched back to English (sid 3) the same way.Related
LocalRock PR: DonSidro/LocalRock#119 (the app side of the Language page).