{"record":{"id":"8b8a380c7883e67d","repo":"clockworklabs/SpacetimeDB","slug":"failed-to-bsatn-deserialize-err","errorCode":null,"errorMessage":"Failed to BSATN-deserialize `{}`: {err:#?}","messagePattern":"Failed to BSATN-deserialize `(.+?)`: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bindings/src/rt.rs","lineNumber":1429,"sourceCode":"    _reducer: R,\n    args: A,\n) {\n    let arg_bytes = bsatn::to_vec(&SerDeArgs(args)).unwrap();\n\n    // Schedule the reducer.\n    sys::volatile_nonatomic_schedule_immediate(R2::NAME, &arg_bytes)\n}\n\n/// Read `source` completely into a temporary buffer, then BSATN-deserialize it as a `T`.\n///\n/// Panics if the bytes from `source` fail to deserialize as `T`.\n/// The type name of `T` will be included in the panic message.\n#[cfg_attr(not(feature = \"unstable\"), allow(unused))]\npub(crate) fn read_bytes_source_as<T: DeserializeOwned + 'static>(source: BytesSource) -> T {\n    let mut buf = IterBuf::take();\n    read_bytes_source_into(source, &mut buf);\n    bsatn::from_slice::<T>(&buf)\n        .unwrap_or_else(|err| panic!(\"Failed to BSATN-deserialize `{}`: {err:#?}\", std::any::type_name::<T>()))\n}\n\npub trait ExplicitNames {\n    fn explicit_names() -> RawExplicitNames {\n        RawExplicitNames::default()\n    }\n}\n","sourceCodeStart":1411,"sourceCodeEnd":1437,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings/src/rt.rs#L1411-L1437","documentation":"read_bytes_source_as drains a BytesSource (scheduled-reducer arguments, HTTP body bytes, etc.) into a buffer and BSATN-decodes it as T, panicking with T's type name and the debug error when decoding fails. A decode failure means the bytes were not produced by the schema T expects - a producer/consumer schema mismatch, not corrupted memory.","triggerScenarios":"Reading a scheduled reducer's stored argument rows after the module schema changed (old rows encode the old row type); decoding an HTTP request body as a type that does not match what the client serialized; module crate version differing between the writer and reader of the bytes.","commonSituations":"Redeploying a module that changed a scheduled reducer's argument type while scheduled rows persisted in the database; client and module disagreeing on the request body type after a partial upgrade.","solutions":["Make the reader's type identical to the writer's type and rebuild/redeploy both together.","If a scheduled reducer's args type changed, clear or migrate outstanding scheduled rows before invoking the new code.","Regenerate client bindings so request/response types match the module's current schema."],"exampleFix":"// before: scheduled args type changed, old rows still decode as the old shape\n#[spacetimedb::scheduled(reducer = tick)]\npub struct Tick { pub retries: u32 }\n\n// after: keep scheduled row layouts compatible or clear stale rows before deploying\nspacetime call my-db delete_all_scheduled_tick  // or migrate in `init`/migration reducer","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Change scheduled reducer argument types only alongside a migration that clears or rewrites stored rows.","Deploy writers and readers of shared bytes in lockstep (module + client bindings).","Version your payloads or include a schema tag when types may evolve."],"tags":["rust","bsatn","deserialization","schema-mismatch"],"backgroundTag":"bsatn-deserialization-failed","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}