{"record":{"id":"269080c9f0926ee6","repo":"nautechsystems/nautilus_trader","slug":"python-on-degrade-failed-e-269080","errorCode":null,"errorMessage":"Python on_degrade failed: {e}","messagePattern":"Python on_degrade failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/python/algorithm.rs","lineNumber":575,"sourceCode":"        ExecutionAlgorithm::on_resume(self)?;\n        self.dispatch_no_args(\"on_resume\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_resume failed: {e}\"))\n    }\n\n    fn on_reset(&mut self) -> anyhow::Result<()> {\n        ExecutionAlgorithm::on_reset(self)?;\n        self.dispatch_no_args(\"on_reset\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_reset failed: {e}\"))\n    }\n\n    fn on_dispose(&mut self) -> anyhow::Result<()> {\n        self.dispatch_no_args(\"on_dispose\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_dispose failed: {e}\"))\n    }\n\n    fn on_degrade(&mut self) -> anyhow::Result<()> {\n        self.dispatch_no_args(\"on_degrade\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_degrade failed: {e}\"))\n    }\n\n    fn on_fault(&mut self) -> anyhow::Result<()> {\n        self.dispatch_no_args(\"on_fault\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_fault failed: {e}\"))\n    }\n\n    fn on_time_event(&mut self, event: &TimeEvent) -> anyhow::Result<()> {\n        ExecutionAlgorithm::on_time_event(self, event)?;\n        self.dispatch_time_event(event)\n            .map_err(|e| anyhow::anyhow!(\"Python on_time_event failed: {e}\"))\n    }\n\n    fn on_signal(&mut self, signal: &Signal) -> anyhow::Result<()> {\n        self.dispatch_on_signal(signal)\n            .map_err(|e| anyhow::anyhow!(\"Python on_signal failed: {e}\"))\n    }\n","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/python/algorithm.rs#L557-L593","documentation":"PyExecutionAlgorithm's DataActor on_degrade dispatches the Python `on_degrade` callback; any Python exception is re-wrapped with this anyhow message. Degrade is invoked when the system enters a degraded (reduced-capability) state, so a failure here means the Python degraded-mode handler raised.","triggerScenarios":"Calling on_degrade when the Python on_degrade raises — e.g. the callback assumes resources that are already unavailable, or wrong no-arg signature.","commonSituations":"Degrade triggered by connection loss where the handler then tries to use that same dead connection; typo'd or mis-signed degrade hook; degrade fired before on_start initialized state.","solutions":["Read the chained `{e}` traceback and fix the Python on_degrade implementation.","Make on_degrade not depend on the resources whose failure caused the degradation.","Guard state access so degrade works even if called before/after other lifecycle stages.","Verify the zero-arg `def on_degrade(self)` signature."],"exampleFix":"// before\ndef on_degrade(self):\n    self.conn.pause()  # conn already dead\n\n// after\ndef on_degrade(self):\n    self.degraded = True  # local flag only; reconnect on_resume","handlingStrategy":"try-catch","validationCode":"# Python: degrade must not depend on live connections\nassert hasattr(self, \"degraded\"), \"degrade flag not initialized in __init__\"","typeGuard":null,"tryCatchPattern":"if let Err(e) = actor.on_degrade() {\n    log::error!(\"python on_degrade failed: {e:#}\");\n    // treat as fault if the actor cannot even enter degraded mode\n}","preventionTips":["Make on_degrade only flip local state flags; do recovery work in on_resume.","Initialize the degraded flag in __init__ so degrade works at any lifecycle stage.","Chaos-test connection-loss paths so on_degrade runs with the failing resource already dead."],"tags":["rust","python","pyo3","lifecycle","on-degrade"],"backgroundTag":"api-error-response","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}