Repository navigation
Conversation
FileCache pickles DeviceFeatures, and unpickling skips __init__ and DeviceFeatures.from_dict, so features cached by an older version lack any field added since. DeviceFeaturesTrait.refresh merged those as None, which makes discovery raise "Device feature ... is unknown" as soon as a trait gates on a new field. Treat an incomplete cached object as a cache miss, matching what from_dict already does for dict-based caches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
infy1995
left a comment
There was a problem hiding this comment.
Thanks for this, the ValueError is real and the new check fixes it. One thing should be fixed before this goes in, though: the rediscovered features cannot be written back with the stock FileCache, and the failed flush leaves the cache file empty (details inline).
This also makes me unsure how the stale pickle arises. On main (7.38.0), after a fresh V1 discovery FileCache.flush() already fails the same way, so I could not get a stock setup to produce a pickled DeviceFeatures at all. How was the file on your side written, with a custom serialize_fn perhaps?
The first commit of my #1092 (ef100c4d) fixes the same stale-cache case, and it has the same write-back problem. I think this cache fix should land first, on its own, with the write-back fixed. #1092 is still a draft, so I will drop that commit and rebase on top of this one.
| common.merge_trait_values(self, cached) | ||
| return | ||
| # Save cached device features | ||
| await super().refresh() |
There was a problem hiding this comment.
The next line, cache_data.device_features = self, stores the trait itself, including _rpc_channel. With a real V1Channel that channel holds a local closure, so FileCache.flush() raises AttributeError: Can't get local object 'V1Channel.rpc_channel.<locals>.rpc_strategies_cb'. store_value has already opened the file with "wb" by then, so it is left at 0 bytes and the next start fails with EOFError.
I reproduced this with create_device_manager, FileCache, FakeRoborockCloud and V1VacuumSimulator. It is pre-existing on main, but this change sends more caches down that path: a pickle that only lacks a field no trait gates on (for example is_curtain_supported) works and flushes fine on main, and with this change the flush destroys it.
Caching a plain copy fixes it:
# Save cached device features
await super().refresh()
# Cache a plain copy: the trait holds the RPC channel, which FileCache cannot pickle.
cache_data.device_features = DeviceFeatures(**{f.name: getattr(self, f.name) for f in fields(DeviceFeatures)})
await self._device_cache.set(cache_data)Separately (not needed here), store_value could serialize before opening the file, so a serialization error cannot truncate a good cache.
|
|
||
| rpc_channel.send_command.assert_awaited_once_with(RoborockCommand.APP_GET_INIT_STATUS) | ||
| assert trait.is_ai_recognition_obstacle_supported is True | ||
| assert (await device_cache.get()).device_features is trait |
There was a problem hiding this comment.
device_features is trait locks in storing the object that cannot be pickled, which is why the flush problem does not show up here. With the plain copy, something like this would cover it:
cached = (await device_cache.get()).device_features
assert pickle.loads(pickle.dumps(cached)).is_ai_recognition_obstacle_supportedThe same is trait assertion in test_from_dict_rejects_legacy_missing_capabilities above would need updating too.
What
FileCache(the default persistent cache) picklesDeviceFeatures. Unpickling skips__init__andDeviceFeatures.from_dict, so features cached by an older library version simply lack any field added since.DeviceFeaturesTrait.refresh()merged that object into the trait withgetattr(..., None), so every new field becameNone. As soon as an optional trait gates on a new field, discovery then raisesValueError: Device feature '<name>' on trait '<trait>' is unknownand the device fails to set up after an upgrade.DeviceFeatures.from_dictalready treats missing fields as a stale cache for dict-based caches. This applies the same rule to the cached object inDeviceFeaturesTrait.refresh(): if it is missing anyDeviceFeaturesfield, it's treated as a cache miss, re-read withAPP_GET_INIT_STATUS, and written back.Why now
#1030 (
is_obstacle_photo_supported) and #1086 (is_carpet_boost_supported) both gate a trait on a newDeviceFeaturesfield. Both hit this on upgrade from 7.38.0 with an existing file cache. The automated review of those updates found it. Any future capability field would hit it too, so it's a standalone fix.Testing
tests/test_supported_features.py::test_refresh_rejects_pickled_features_missing_capabilitiespickles aDeviceFeaturesmissing one field, loads it from the device cache, and checks that refresh re-reads init status and caches the complete trait. It fails onmain(no RPC is sent and the field merges asNone) and passes with the fix.ruff check,ruff format --check, andpytestpass (3295 passed, 45 xfailed).mypyreports only the existingtests/map/test_b01_q10_render.py:502error, also onmain.🤖 Generated with Claude Code