{"record":{"id":"a38381535bd88823","repo":"sinelaw/fresh","slug":"typescript-plugin-thread-creation-failed","errorCode":null,"errorMessage":"TypeScript plugin thread creation failed: {}","messagePattern":"TypeScript plugin thread creation failed: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/fresh-editor/src/services/plugins/manager.rs","lineNumber":86,"sourceCode":"                let services = Arc::new(EditorServiceBridge {\n                    command_registry: command_registry.clone(),\n                    dir_context,\n                    theme_cache,\n                    local_plugin_fs,\n                    window_registry: Arc::clone(&window_registry),\n                });\n                match PluginThreadHandle::spawn(services) {\n                    Ok(handle) => {\n                        return Self {\n                            inner: Some(handle),\n                            window_registry: Some(window_registry),\n                            pending_injected_commands: Vec::new(),\n                        }\n                    }\n                    Err(e) => {\n                        tracing::error!(\"Failed to spawn TypeScript plugin thread: {}\", e);\n                        #[cfg(debug_assertions)]\n                        panic!(\"TypeScript plugin thread creation failed: {}\", e);\n                    }\n                }\n            } else {\n                tracing::info!(\"Plugins disabled via --no-plugins flag\");\n            }\n            Self {\n                inner: None,\n                window_registry: None,\n                pending_injected_commands: Vec::new(),\n            }\n        }\n\n        #[cfg(not(feature = \"plugins\"))]\n        {\n            let _ = command_registry; // Suppress unused warning\n            let _ = dir_context; // Suppress unused warning\n            let _ = theme_cache; // Suppress unused warning\n            let _ = authority_filesystem; // Suppress unused warning","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/src/services/plugins/manager.rs#L68-L104","documentation":"The plugin manager's `new` constructor spawns a dedicated thread for the TypeScript plugin runtime. If thread creation fails it logs the error via tracing, and — only in debug builds (`#[cfg(debug_assertions)]`) — panics with \"TypeScript plugin thread creation failed\". In release builds the panic is compiled out and the editor continues with plugins unavailable; in debug builds it aborts editor startup.","triggerScenarios":"Constructing PluginManager::new with plugins enabled (no --no-plugins flag) when std::thread::Builder::spawn returns Err — practically only when the OS refuses to create a thread (thread/resource limits hit, e.g. RLIMIT_NPROC/ulimit -u exhausted, out-of-memory in debug builds, cgroup thread caps).","commonSituations":"Development/debug builds running under low ulimit -u, containers with low pids.max cgroup limits, or a heavily loaded system that already exhausted the process/thread budget. Never occurs in release builds from this code path.","solutions":["Check the underlying error `e` in the log line for the OS reason (e.g. 'Os { code: 11, ... }' = EAGAIN).","Raise the thread/process limit: ulimit -u, container pids cgroup limit, or systemd TasksMax.","Free threads by reducing concurrently spawned plugin threads, or restart the environment if the limit was leaked.","As a workaround for development sessions, launch with --no-plugins to skip spawning the TypeScript plugin thread."],"exampleFix":"// before (debug build, thread limit exhausted)\npanic!(\"TypeScript plugin thread creation failed: {}\", e);\n\n// after: raise the limit instead of patching code\n# ulimit -u 4096   # or raise container pids.max / systemd TasksMax","handlingStrategy":"fallback","validationCode":"// Rust: check the process/thread budget before spawning (Linux)\nlet limits = std::fs::read_to_string(\"/proc/sys/kernel/threads-max\")?;\nlet used: i32 = std::fs::read_to_string(\"/proc/self/status\")?\n    .lines().find(|l| l.starts_with(\"Threads:\"))\n    .and_then(|l| l.split_whitespace().nth(1))\n    .unwrap_or(\"0\").parse()?;\nlet max: i32 = limits.trim().parse()?;\nlet can_spawn = used < max - 16;","typeGuard":null,"tryCatchPattern":"// the spawn returns Result; handle it without panicking even in debug\nif let Err(e) = thread::Builder::new().name(\"ts-plugins\".into()).spawn(...) {\n    tracing::error!(\"TypeScript plugin thread creation failed: {}\", e);\n    // continue with plugins disabled\n}","preventionTips":["Raise ulimit -u / container pids.max in dev environments.","Run release builds in constrained environments; the panic only exists in debug_assertions.","Use --no-plugins when plugin support is not needed for the session."],"tags":["rust","thread-creation","plugins","debug-build","resource-limit"],"backgroundTag":"internal-invariant-violation","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}