{"record":{"id":"f3b55d5655dde59a","repo":"nautechsystems/nautilus_trader","slug":"python-on-start-failed-e-f3b55d","errorCode":null,"errorMessage":"Python on_start failed: {e}","messagePattern":"Python on_start failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/python/algorithm.rs","lineNumber":547,"sourceCode":"        let _ = self\n            .dispatch_position_event(\"on_position_changed\", PositionEvent::PositionChanged(event));\n    }\n\n    fn on_position_closed(&mut self, event: PositionClosed) {\n        let _ = self\n            .dispatch_position_event(\"on_position_closed\", PositionEvent::PositionClosed(event));\n    }\n\n    fn on_position_event(&mut self, event: PositionEvent) {\n        let _ = self.dispatch_position_event(\"on_position_event\", event);\n    }\n}\n\nimpl DataActor for PyExecutionAlgorithm {\n    fn on_start(&mut self) -> anyhow::Result<()> {\n        ExecutionAlgorithm::on_start(self)?;\n        self.dispatch_no_args(\"on_start\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_start failed: {e}\"))\n    }\n\n    fn on_stop(&mut self) -> anyhow::Result<()> {\n        ExecutionAlgorithm::on_stop(self)?;\n        self.dispatch_no_args(\"on_stop\")\n            .map_err(|e| anyhow::anyhow!(\"Python on_stop failed: {e}\"))\n    }\n\n    fn on_resume(&mut self) -> anyhow::Result<()> {\n        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}\"))","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/python/algorithm.rs#L529-L565","documentation":"PyExecutionAlgorithm implements the DataActor lifecycle. Its on_start first runs the Rust-side ExecutionAlgorithm::on_start, then dispatches the Python `on_start` callback; a Python-side exception is re-wrapped with this message. It indicates the Python component failed to start.","triggerScenarios":"Calling on_start when the Python on_start raises — e.g. failed initialization inside the user callback, resources unavailable at start, or invalid no-arg dispatch.","commonSituations":"Python on_start connecting to external services that are down; referencing attributes initialized in an overridden __init__ that was not called; state carried over from a previous run without reset.","solutions":["Read the chained `{e}` traceback and fix the Python on_start callback.","Ensure any external resources the callback needs (connections, config) are available before start.","Call on_reset (or fresh construction) before restarting so stale state cannot break startup.","Confirm the Python class defines a zero-argument on_start method."],"exampleFix":"// before\ndef on_start(self, config): ...  # unexpected argument\n\n// after\ndef on_start(self): ...","handlingStrategy":"try-catch","validationCode":"# Python: preflight startup dependencies before the engine starts\nassert self.ready, \"state not initialized; call __init__/on_reset first\"","typeGuard":null,"tryCatchPattern":"match actor.on_start() {\n    Ok(()) => {},\n    Err(e) => {\n        log::error!(\"python on_start failed: {e:#}\");\n        // route the actor to faulted state instead of continuing\n    }\n}","preventionTips":["Validate external dependencies (connections, config) in on_start and fail fast with clear messages.","Always run on_reset (or fresh construction) before a restart.","Keep lifecycle hooks zero-argument as the DataActor contract requires."],"tags":["rust","python","pyo3","lifecycle","on-start"],"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"}