{"record":{"id":"3ef6f3956cba2832","repo":"BigPizzaV3/CodexPlusPlus","slug":"bridge-context-is-not-initialized","errorCode":null,"errorMessage":"bridge context is not initialized","messagePattern":"bridge context is not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/codex-plus-launcher/src/main.rs","lineNumber":45,"sourceCode":"            core: Arc::new(DefaultLaunchHooks::default()),\n            data: Arc::new(LauncherDataService::default()),\n            runtime: Arc::new(LauncherRuntimeService::new(\n                9229,\n                default_user_script_manager(),\n            )),\n            bridge_context: Arc::new(Mutex::new(None)),\n            browser_monitor: Arc::new(Mutex::new(None)),\n        }\n    }\n}\n\nimpl LauncherHooks {\n    fn watchdog_bridge_context(&self) -> anyhow::Result<BridgeContext> {\n        self.bridge_context\n            .lock()\n            .map_err(|_| anyhow::anyhow!(\"bridge context lock poisoned\"))?\n            .clone()\n            .ok_or_else(|| anyhow::anyhow!(\"bridge context is not initialized\"))\n    }\n}\n\n#[tokio::main]\nasync fn main() -> Result<()> {\n    let args = std::env::args().skip(1).collect::<Vec<_>>();\n    let helper_only = args.iter().any(|arg| arg == \"--helper-only\");\n    let options = parse_launch_options(args.iter());\n    if let Err(error) = launcher_main(args, helper_only, options.clone()).await {\n        let _ = codex_plus_core::diagnostic_log::append_diagnostic_log(\n            \"launcher.failed\",\n            json!({\n                \"message\": error.to_string()\n            }),\n        );\n        if !helper_only {\n            let _ = options.status_store.save_latest(&LaunchStatus {\n                status: \"failed\".to_string(),","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/apps/codex-plus-launcher/src/main.rs#L27-L63","documentation":"watchdog_bridge_context clones the Option<BridgeContext> under the mutex and, if it is None, returns this error: the watchdog is being asked to reuse a bridge context that has never been created (initialize_bridge_context has not run or has not stored a value yet).","triggerScenarios":"start_bridge_watchdog (or a watchdog test hook) invoking watchdog_bridge_context before the launcher's initialize path stored Some(ctx) into the shared mutex — e.g. watchdog started concurrently before bridge init finished, or bridge init failed earlier.","commonSituations":"Race between watchdog startup and bridge initialization; bridge initialization failed silently and the watchdog fires later; calling watchdog-driven restart logic in an environment (test/embedded) where no bridge was set up.","solutions":["Ensure start_bridge_watchdog runs only after initialize_bridge_context has successfully stored Some(ctx) (sequence it or await a ready signal).","Make watchdog_bridge_context lazily initialize the context instead of erroring.","Have the watchdog treat this as 'nothing to watch' and skip the tick rather than fail hard.","Check why bridge initialization failed earlier (ports, app dir, data service) and fix the root cause."],"exampleFix":"// before\nlet ctx = launcher.watchdog_bridge_context().await?;\n// after\nlet Ok(ctx) = launcher.watchdog_bridge_context().await else { tracing::warn!(\"bridge not initialized; skipping watchdog tick\"); return Ok(()); };\n","handlingStrategy":"fallback","validationCode":"if !launcher.bridge_context_initialized() { tracing::warn!(\"bridge not initialized yet; deferring watchdog\"); return Ok(()); }","typeGuard":"function isInitialized(ctx: BridgeContext | null): ctx is BridgeContext { return ctx !== null; }","tryCatchPattern":"match launcher.watchdog_bridge_context().await {\n    Ok(ctx) => watch(ctx).await?,\n    Err(e) if e.to_string().contains(\"not initialized\") => { /* skip tick, retry next interval */ }\n    Err(e) => return Err(e),\n}","preventionTips":["Initialize the bridge context before starting the watchdog (strict ordering or a ready signal).","Treat 'not initialized' as a benign skip in watchdog loops.","Make watchdog ticks idempotent so ordering races are harmless."],"tags":["initialization","race-condition","lifecycle","watchdog"],"backgroundTag":"invalid-state-transition","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}