{"record":{"id":"4cb6d858874ac809","repo":"Hmbown/CodeWhale","slug":"codewhale-runtime-thread-panicked-message","errorCode":null,"errorMessage":"Codewhale runtime thread panicked: {message}","messagePattern":"Codewhale runtime thread panicked: (.+?)","errorType":"panic","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/tui/src/lib.rs","lineNumber":1681,"sourceCode":"    // events all share one async owner. Debug builds retain enough stack\n    // temporaries that nesting a modal event over the TUI loop can exceed the\n    // platform main-thread default (8 MiB on macOS). Give that owner an\n    // explicit stack while keeping process hardening and the global panic hook\n    // above this boundary, before Tokio or any worker thread exists.\n    let runtime_thread = std::thread::Builder::new()\n        .name(\"codewhale-main\".to_string())\n        .stack_size(CODEWHALE_MAIN_STACK_BYTES)\n        .spawn(move || run_async_main(cli, command, plugin_discovery, plugin_registry))\n        .context(\"Failed to start the Codewhale runtime thread\")?;\n    match runtime_thread.join() {\n        Ok(result) => result,\n        Err(payload) => {\n            let message = payload\n                .downcast_ref::<&str>()\n                .map(|value| (*value).to_string())\n                .or_else(|| payload.downcast_ref::<String>().cloned())\n                .unwrap_or_else(|| \"unknown panic payload\".to_string());\n            Err(anyhow!(\"Codewhale runtime thread panicked: {message}\"))\n        }\n    }\n}\n\nfn run_async_main(\n    cli: Cli,\n    command: Option<Commands>,\n    plugin_discovery: Arc<crate::plugins::PluginDiscoveryContext>,\n    plugin_registry: Arc<crate::plugins::PluginRegistry>,\n) -> Result<()> {\n    build_runtime()?.block_on(run_async_main_inner(\n        cli,\n        command,\n        plugin_discovery,\n        plugin_registry,\n    ))\n}\n","sourceCodeStart":1663,"sourceCodeEnd":1699,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/lib.rs#L1663-L1699","documentation":"crates/tui/src/lib.rs runs the entire async runtime on a dedicated 'codewhale-main' thread with a fixed stack size (CODEWHALE_MAIN_STACK_BYTES). If code inside run_async_main panics, thread::join() returns the panic payload; this site downcasts it to &str or String and rewraps it as 'Codewhale runtime thread panicked: {message}'. The message names the panic value, not the file:line where it happened.","triggerScenarios":"Any panic inside run_async_main: an unwrap/expect on None or Err, an out-of-bounds index, an assertion, a panic inside a dependency, or 'unknown panic payload' when the payload is not a string type.","commonSituations":"A startup regression panics on an unexpected config shape or empty model registry; a dependency panics on malformed input; deep recursion exceeds the configured stack size and the runtime aborts into the panic path.","solutions":["Re-run with RUST_BACKTRACE=1 (or full) — the panic hook prints the real file:line to stderr before this join error is returned","Reproduce with the same subcommand and inputs, then fix the unwrap/expect at the reported location","If depth/recursion related, raise CODEWHALE_MAIN_STACK_BYTES or move the deep work off the fixed-stack thread","Report the panic location and backtrace if it comes from released code"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match runtime_thread.join() {\n    Ok(result) => result,\n    Err(payload) => {\n        let message = payload\n            .downcast_ref::<&str>()\n            .map(|value| (*value).to_string())\n            .or_else(|| payload.downcast_ref::<String>().cloned())\n            .unwrap_or_else(|| \"unknown panic payload\".to_string());\n        Err(anyhow!(\"Codewhale runtime thread panicked: {message}\"))\n    }\n}","preventionTips":["Run with RUST_BACKTRACE=1 so the panic hook prints the real file:line before join returns","Replace unwrap/expect on fallible startup data with error propagation","Keep the default panic hook installed — it carries the location this error omits","Wrap third-party code that may panic in std::panic::catch_unwind where feasible"],"tags":["rust","panic","threading","runtime"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}