You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current file persistence uses a Python-dict-backed StableBTreeMap (memory_id=255). During pre_upgrade, the entire file store is serialized as JSON+base64 and written to stable memory in one shot. This has two failure modes:
4GB stable memory limit — base64 overhead means ~3GB max raw file storage
Instruction limit — JSON serialization of many files can exceed the ~5B instruction budget for pre_upgrade, causing the upgrade to trap and leaving the canister in an inconsistent state
Both failures result in data loss with no warning as you approach the limits.
Solution
Replace the Python-dict file store with a Rust-backed StableBTreeMap<String, Vec<u8>> from ic-stable-structures. This stores file data directly in stable memory on every close(), making pre_upgrade a no-op for files.
Implementation plan
Add a Rust StableBTreeMap<String, Vec<u8>> in the canister template for file storage
Expose native Python APIs via _basilisk_ic: file_store_get, file_store_set, file_store_delete, file_store_keys
Modify _PersistentFile / _persistent_open to use the native API instead of the Python dict
Remove file store serialization from _basilisk_save_stable_maps / _basilisk_load_stable_maps
Backward compatibility: migrate existing Python-dict file store data to Rust-backed store on first upgrade
Benefits
No serialization during upgrades — eliminates both the 4GB and instruction-limit risks
Writes are immediately durable — no data loss if upgrade fails
Scales to full stable memory capacity (currently 8GB on IC, growing)
Problem
The current file persistence uses a Python-dict-backed
StableBTreeMap(memory_id=255). Duringpre_upgrade, the entire file store is serialized as JSON+base64 and written to stable memory in one shot. This has two failure modes:pre_upgrade, causing the upgrade to trap and leaving the canister in an inconsistent stateBoth failures result in data loss with no warning as you approach the limits.
Solution
Replace the Python-dict file store with a Rust-backed
StableBTreeMap<String, Vec<u8>>fromic-stable-structures. This stores file data directly in stable memory on everyclose(), makingpre_upgradea no-op for files.Implementation plan
StableBTreeMap<String, Vec<u8>>in the canister template for file storage_basilisk_ic:file_store_get,file_store_set,file_store_delete,file_store_keys_PersistentFile/_persistent_opento use the native API instead of the Python dict_basilisk_save_stable_maps/_basilisk_load_stable_mapsBenefits
Related