{"record":{"id":"f4e3b2c9bca96d6d","repo":"tracel-ai/burn","slug":"cannot-get-uninitialized-handle-id","errorCode":null,"errorMessage":"Cannot get uninitialized handle {id:?}.","messagePattern":"Cannot get uninitialized handle (.+?)\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/burn-ir/src/handle.rs","lineNumber":346,"sourceCode":"            panic!(\"Tensor {id:?} was never written: {error}\");\n        }\n\n        let (id, handle) = self\n            .take(id)\n            .unwrap_or_else(|| panic!(\"Should have handle for tensor {id:?}\"));\n\n        match handle {\n            Handle::Existing(handle) => match status {\n                TensorStatus::ReadOnly => {\n                    self.put(id, Handle::Existing(handle.clone()));\n                    handle\n                }\n                TensorStatus::ReadWrite => handle,\n                TensorStatus::NotInit => panic!(\n                    \"Cannot get uninitialized tensor {id:?}. Tensor exist but with wrong status\"\n                ),\n            },\n            Handle::NotInit => panic!(\"Cannot get uninitialized handle {id:?}.\"),\n            // The backstop for an `errored` count that has drifted below the\n            // map: the guard above is gated on it, so a drift would let an\n            // errored entry through to here. Not unreachable — reached only\n            // when the invariant `put`/`take` maintain has already broken.\n            Handle::Errored(error) => panic!(\"Tensor {id:?} was never written: {error}\"),\n        }\n    }\n\n    /// Get the tensor handle for the given [tensor intermediate representation](TensorIr).\n    pub fn get_tensor_handle(&mut self, tensor: &TensorIr) -> TensorHandle<H> {\n        TensorHandle {\n            handle: self.get_handle(&tensor.id, &tensor.status),\n            shape: tensor.shape.clone(),\n        }\n    }\n\n    /// Get the [float tensor](burn_backend::backend::BackendTypes::FloatTensorPrimitive) corresponding to the\n    /// given [tensor intermediate representation](TensorIr).","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ir/src/handle.rs#L328-L364","documentation":"`HandleStore::get_handle` in burn-ir panics when the stored handle for a tensor id is `Handle::NotInit` — the id is registered in the store but no backend resource was ever written into it. This is a burn-runtime bookkeeping invariant violation: by the time a consumer requests a handle, the producer operation should have replaced NotInit with an `Existing` (or `Errored`) handle.","triggerScenarios":"Reading a tensor whose handle is still uninitialized: an operation that should have produced the tensor never ran or never registered its output (e.g. a skipped/failed kernel launch that still left the id registered), or a `TensorStatus::NotInit` tensor that is consumed without first being initialized.","commonSituations":"Kernel/kernel-launch failure silently swallowed earlier in the graph so downstream reads hit NotInit; mismatched TensorStatus in hand-written BackendIr code (registering output as NotInit then reading it); runtime/graph-executor bugs in custom backend integrations.","solutions":["Look earlier in the execution log for the operation that was supposed to write this tensor id — the NotInit handle means that op never completed its handle registration; fix that root cause first.","Check `take_error`/`has_errors` flow in your custom backend: ensure failed ops register `Handle::Errored` so consumers get the real error instead of NotInit.","Verify you pass the correct `TensorStatus` to `get_handle`/`get_tensor_handle` (ReadOnly vs ReadWrite vs NotInit) in custom BackendIr implementations.","If you maintain the runtime integration, audit the put/take pairing so outputs of every executed op are stored with `Handle::Existing`."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before reading a tensor in a custom integration:\nif store.take_error(&tensor_ir).is_some() {\n    return Err(\"producing op failed; tensor never initialized\".into());\n}\n// or probe existence via has_errors()/store introspection before get_handle","typeGuard":null,"tryCatchPattern":"let handle = std::panic::catch_unwind(panic::AssertUnwindSafe(|| store.get_handle(&id, &status)))\n    .map_err(|_| anyhow!(\"tensor {id:?} has an uninitialized handle; producer op failed\"))?;","preventionTips":["Call take_error() before consuming tensors in fallible runtimes","Ensure every executed op registers its output handle before downstream reads","Use correct TensorStatus (ReadOnly/ReadWrite/NotInit) for each get_handle call","When integrating a custom backend, test failure injection so NotInit never leaks as a bare panic"],"tags":["panic","burn","runtime","handle-store","internal-invariant"],"backgroundTag":"uninitialized-tensor-handle","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}