{"record":{"id":"74ee3fbe4cf1d03c","repo":"BoundaryML/baml","slug":"the-browser-typescript-bridge-must-own-the-process-wide","errorCode":null,"errorMessage":"the browser TypeScript bridge must own the process-wide inbound policy","messagePattern":"the browser TypeScript bridge must own the process-wide inbound policy","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bridge_wasm/src/lib.rs","lineNumber":71,"sourceCode":"mod wasm_http;\nmod wasm_io;\nmod wasm_io_fs;\nmod wasm_io_glob;\nmod wasm_random;\nmod wasm_sys;\nmod wasm_time;\nmod wasm_vfs;\n\npub use lsp_wire::{LspNotification, LspRequest, LspResponse, LspResponseError};\n\nstatic LOGGER_INIT: Once = Once::new();\n\n#[wasm_bindgen(start)]\npub fn start() {\n    bex_project::register_inbound_union_ambiguity_policy(\n        bex_project::InboundUnionAmbiguityPolicy::SelectDefault,\n    )\n    .expect(\"the browser TypeScript bridge must own the process-wide inbound policy\");\n    #[cfg(feature = \"console_error_panic\")]\n    console_error_panic_hook::set_once();\n    LOGGER_INIT.call_once(|| {\n        let level = if cfg!(debug_assertions) {\n            log::Level::Debug\n        } else {\n            log::Level::Info\n        };\n        wasm_logger::init(wasm_logger::Config::new(level));\n    });\n}\n\n/// Get the version of the `bridge_wasm` crate.\n#[wasm_bindgen]\npub fn version() -> String {\n    baml_version::CANONICAL_VERSION.to_string()\n}\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bridge_wasm/src/lib.rs#L53-L89","documentation":"The WASM entrypoint start() registers the process-wide inbound union ambiguity policy (SelectDefault) and expects registration to succeed. bex_project::register_inbound_union_ambiguity_policy returns Err if the policy was already set, and start() .expect()s on it: 'the browser TypeScript bridge must own the process-wide inbound policy'. It means something else in the process initialized the policy first, so the browser bridge no longer owns it.","triggerScenarios":"Loading the WASM module twice into the same process/runtime, or another binding (Node bridge, tests) calling register_inbound_union_ambiguity_policy before wasm_bindgen start runs.","commonSituations":"Double-importing the wasm package (e.g. via two bundle chunks), SSR/test environments pre-initializing bex_project, or mixing the WASM bridge with a native bridge in the same process.","solutions":["Ensure the wasm module is imported/initialized only once per process","Check that no other bridge or test setup registers the inbound policy before WASM start","Deduplicate bundle chunks so a single wasm_bindgen start runs","Use a fresh WASM instance per isolated runtime instead of sharing one globally"],"exampleFix":"// before\nimport wasm1 from 'baml_wasm_bg';\nimport wasm2 from 'baml_wasm_bg'; // second start() -> panic\n// after\nexport const wasm = await import('baml_wasm_bg'); // single shared import","handlingStrategy":"validation","validationCode":"if (globalThis.__BAML_WASM_STARTED__) throw new Error('baml wasm already initialized in this process');\nawait import('baml_wasm_bg'); // single init point\nglobalThis.__BAML_WASM_STARTED__ = true;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Import the wasm package exactly once (single shared module instance)","Do not pre-register the inbound policy in tests or other bridges","Deduplicate bundler chunks referencing the wasm bg module","Use separate runtimes/instances rather than one shared process"],"tags":["wasm","initialization","policy"],"backgroundTag":"module-init-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}