{"record":{"id":"a6db039cdcb5cb29","repo":"tracel-ai/burn","slug":"autobatcher-should-be-able-to-send-resulting-proba","errorCode":null,"errorMessage":"Autobatcher should be able to send resulting probabilities.","messagePattern":"Autobatcher should be able to send resulting probabilities\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-rl/src/policy/async_policy.rs","lineNumber":115,"sourceCode":"        }\n        self.batch_action.clear();\n    }\n\n    pub fn flush_logits(&mut self) {\n        if self.len_logits() == 0 {\n            return;\n        }\n        let input: Vec<_> = self\n            .batch_logits\n            .iter()\n            .map(|m| m.inference_state.clone())\n            .collect();\n        let output = self.inner_policy.forward(P::Observation::batch(input));\n        let logits: Vec<_> = output.unbatch();\n        for (i, item) in self.batch_logits.iter().enumerate() {\n            item.sender\n                .send(logits[i].clone())\n                .expect(\"Autobatcher should be able to send resulting probabilities.\");\n        }\n        self.batch_logits.clear();\n    }\n\n    pub fn update_policy(&mut self, policy_update: P::PolicyState) {\n        if self.len_actions() > 0 {\n            self.flush_actions();\n        }\n        if self.len_logits() > 0 {\n            self.flush_logits();\n        }\n        self.inner_policy.update(policy_update);\n    }\n\n    pub fn policy_to_device(&mut self, device: &Device) {\n        self.inner_policy = self.inner_policy.clone().to_device(device);\n    }\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-rl/src/policy/async_policy.rs#L97-L133","documentation":"Channel-invariant guard in `Autobatcher::flush_logits` (burn-rl): after computing batched logits from the queued inference states, the code sends each result back to its requester via an mpsc sender; the `.expect` fires only if the receiving end (the per-agent handle awaiting its probabilities) has been dropped — i.e., an agent was closed/removed while its request was still queued, so the batcher cannot deliver the result.","triggerScenarios":"An agent dropped its receiver (task aborted, thread panicked, decrement_agents called) after push_logits queued the sender but before update_policy triggered flush_logits.","commonSituations":"Cancelling rollout workers mid-step; agent panics while the policy forward is in flight; shutdown ordering that tears down agents before flushing pending logits.","solutions":["Keep agent receivers alive until flush_logits completes for the pending batch","Flush pending logits before decrementing agents or shutting down the policy","Use cooperative cancellation so agents consume their pending logits first","Handle send errors gracefully (skip dead receivers) instead of expecting","sys"],"exampleFix":"// before\nitem.sender.send(logits[i].clone())\n    .expect(\"Autobatcher should be able to send resulting probabilities.\");\n// after\nif item.sender.send(logits[i].clone()).is_err() {\n    // receiver dropped; skip this agent\n}","handlingStrategy":"try-catch","validationCode":"// Before update_policy, confirm no pending logits belong to dead agents\nlet dead = self.batch_logits.iter().filter(|i| i.sender.is_closed()).count();\nassert_eq!(dead, 0, \"{dead} agents dropped before flush_logits\");","typeGuard":null,"tryCatchPattern":"if let Err(e) = item.sender.send(logits[i].clone()) {\n    log::warn!(\"agent receiver dropped, skipping: {e}\");\n    continue;\n}","preventionTips":["Flush pending logits before decrementing agents","Keep rollout workers alive until the policy returns their logits","Handle oneshot send errors gracefully instead of expecting","sys"],"tags":["rust","channels","concurrency","reinforcement-learning"],"backgroundTag":"channel-send-failed","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"}