{"record":{"id":"6fa55186b6a2ba7f","repo":"BoundaryML/baml","slug":"failed-to-recv-cred-response-across-wasm-bridge-0","errorCode":null,"errorMessage":"Failed to recv cred response across WASM bridge: {0}","messagePattern":"Failed to recv cred response across WASM bridge: (.+?)","errorType":"exception","errorClass":"RuntimeCallbackError","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/types/js_callback_provider.rs","lineNumber":29,"sourceCode":"    #[serde(rename = \"error\")]\n    Err(JsCallbackError),\n}\n\n#[derive(Debug, serde::Deserialize, Eq, PartialEq)]\n/// Deserialization helper for js_callback_bridge; declared here to enable deserialization unit testing.\npub struct JsCallbackError {\n    pub name: String,\n    pub message: String,\n}\n\n#[derive(Debug, Error, Clone)]\n/// For baml-src-reader and aws-cred-provider, provide a statically defined type which is Send + Sync\n/// anyhow::Error is not Send + Sync, so it's convoluted to use it in this callback context\npub enum RuntimeCallbackError {\n    #[error(\"Failed to send cred request across WASM bridge: {0}\")]\n    SendError(String),\n\n    #[error(\"Failed to recv cred response across WASM bridge: {0}\")]\n    RecvError(String),\n\n    #[error(\"Type error in JS callback: {0}\")]\n    JsCallbackTypeError(String),\n\n    #[error(\"JS callback error: {name}: {message}\")]\n    JsCallbackRuntimeError { name: String, message: String },\n\n    #[error(\"BAML internal error - credential provider bridges not initialized\")]\n    NoCredProviderBridge,\n}\n\nstatic_assertions::assert_impl_all!(RuntimeCallbackError: Send, Sync);\n\npub type RuntimeCallbackResult<T> = Result<T, RuntimeCallbackError>;\n\nstatic JS_CALLBACK_PROVIDER_SINGLETON: OnceLock<JsCallbackProvider> = OnceLock::new();\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/types/js_callback_provider.rs#L11-L47","documentation":"RuntimeCallbackError::RecvError is raised when the tokio broadcast `Receiver::recv` awaiting the credential response from the JS/WASM side fails at the transport level (not a credential error from JS itself, which comes back as Ok(Err(...))). This means the broadcast channel errored - typically closed or lagged - so no credential response was ever received.","triggerScenarios":"JsCallbackProvider::aws_req (js_callback_provider.rs:105-114) or gcp_req (js_callback_provider.rs:128-138) calls `resp_rx.recv().await` and gets `Err(e)` (e.g. `RecvError::Closed` after the sender was dropped, or `RecvError::Lagged` because the subscriber missed too many messages), which becomes `RuntimeCallbackError::RecvError(e.to_string())`.","commonSituations":"The JS side resolved/rejected the credential promise but the bridge sender was dropped before the response was published, the WASM runtime shut down mid-request, or many concurrent AWS cred requests caused a lagged broadcast receiver.","solutions":["Retry the credential request; the provider clones/resubscribes the broadcast receiver on each call, so a fresh call often succeeds.","Ensure the JS credential provider callback does not drop/replace the bridge channel while requests are in flight.","Check for runtime shutdown or worker termination racing with the LLM call and serialize initialization before calls.","If 'lagged' appears in the message, reduce concurrency of simultaneous cred requests or increase the broadcast channel capacity in the bridge setup."],"exampleFix":"// before: tearing down the runtime while a call is in flight\nruntime.dispose();\nawait b.GenerateSummary(input); // RecvError: channel closed\n\n// after: await in-flight work before disposing\nawait b.GenerateSummary(input);\nruntime.dispose();","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// JS side: bounded retry for transient bridge recv failures\nasync function callWithRetry(fn, retries = 2) {\n  for (let i = 0; i <= retries; i++) {\n    try { return await fn(); }\n    catch (e) {\n      if (String(e).includes('Failed to recv cred response') && i < retries) continue;\n      throw e;\n    }\n  }\n}","preventionTips":["Don't tear down the bridge channel while credential requests are in flight","Await all pending BAML calls before disposing the runtime","Limit concurrent AWS/GCP cred requests to avoid broadcast lag"],"tags":["wasm","aws-credentials","channel","async","rust"],"backgroundTag":"missing-credentials","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}