{"record":{"id":"65254b342dc37743","repo":"nautechsystems/nautilus_trader","slug":"cannot-start-bar-aggregation-for-bar-type","errorCode":null,"errorMessage":"Cannot start bar aggregation for {bar_type}","messagePattern":"Cannot start bar aggregation for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/data/src/engine/mod.rs","lineNumber":4917,"sourceCode":"        );\n\n        Ok(())\n    }\n\n    fn start_bar_aggregator(\n        &mut self,\n        bar_type: BarType,\n        request_id: Option<UUID4>,\n        skip_first_non_full_bar: Option<bool>,\n    ) -> anyhow::Result<()> {\n        let key = bar_aggregator_key(bar_type, request_id);\n        let bar_type_std = bar_type.standard();\n\n        self.create_bar_aggregator_for_key(bar_type, request_id, skip_first_non_full_bar)?;\n        let aggregator = self\n            .bar_aggregators\n            .get(&key)\n            .ok_or_else(|| anyhow::anyhow!(\"Cannot start bar aggregation for {bar_type}\"))?\n            .clone();\n        let defer_subscription_activation = request_id.is_none()\n            && aggregator.borrow().is_running()\n            && !self.bar_aggregator_handlers.contains_key(&key);\n\n        if !self.bar_aggregator_handlers.contains_key(&key) {\n            // Subscribe to underlying data topics\n            let mut subscriptions = Vec::new();\n\n            if bar_type.is_composite() {\n                let topic = switchboard::get_bars_topic(bar_type.composite());\n                let handler = TypedHandler::new(BarBarHandler::new(&aggregator, bar_type_std));\n                msgbus::subscribe_bars(topic.into(), handler.clone(), None);\n                subscriptions.push(BarAggregatorSubscription::Bar { topic, handler });\n            } else if bar_type.spec().price_type == PriceType::Last {\n                let topic = switchboard::get_trades_topic(bar_type.instrument_id());\n                let handler = TypedHandler::new(BarTradeHandler::new(&aggregator, bar_type_std));\n                msgbus::subscribe_trades(","sourceCodeStart":4899,"sourceCodeEnd":4935,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/engine/mod.rs#L4899-L4935","documentation":"After creating a bar aggregator for the given bar type and request ID, the engine looks it up in the bar_aggregators map and fails if it is absent. This is an internal invariant check immediately following create_bar_aggregator_for_key, so hitting it means aggregator creation silently failed or the entry was evicted concurrently.","triggerScenarios":"Calling start_bar_aggregation / subscribe_bars where create_bar_aggregator_for_key succeeded but self.bar_aggregators.get(&key) returns None — effectively an internal invariant violation in the aggregator registry.","commonSituations":"Race conditions between concurrent subscribe/stop calls on the same bar type; forked engine state where the creation path was patched; custom request_id handling causing key mismatch.","solutions":["Retry the subscription once — if transient concurrency caused the miss, a fresh call recreates the aggregator.","Check for concurrent subscribe/stop calls on the same BarType (e.g. an unsubscribe racing the subscribe) and serialize them.","Verify the aggregator key derivation (bar_aggregator_key) is consistent between creation and lookup; update to a version where creation and lookup share one key.","File an issue with the bar_type and call stack — this indicates an engine bug rather than user error."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if engine.is_subscribed_bars(&bar_type) {\n    // already active, skip create/start path\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Cannot start bar aggregation\") => {\n        // retry once after a short delay; else surface as engine bug\n    }\n    other => other?,\n}","preventionTips":["Avoid concurrent subscribe/stop calls for the same BarType.","Serialize data engine subscription lifecycle calls.","Keep engine versions in sync across the deployment (creation/lookup invariant)."],"tags":["rust","data-engine","bar-aggregation","internal-invariant"],"backgroundTag":"internal-invariant-violation","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"}