{"record":{"id":"5750367b74534415","repo":"Hmbown/CodeWhale","slug":"port-must-be-0","errorCode":null,"errorMessage":"Port must be > 0","messagePattern":"Port must be > 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_api.rs","lineNumber":832,"sourceCode":"    let workshop_activation = install_runtime_server_workshop_budgets(config);\n    let manager = Arc::new(RuntimeThreadManager::open_with_plugin_registry(\n        config.clone(),\n        workspace,\n        manager_config,\n        plugin_registry,\n    )?);\n    Ok((manager, workshop_activation))\n}\n\n/// Start the runtime API server.\npub async fn run_http_server(\n    config: Config,\n    workspace: PathBuf,\n    plugin_discovery: Arc<crate::plugins::PluginDiscoveryContext>,\n    options: RuntimeApiOptions,\n) -> Result<()> {\n    if options.port == 0 {\n        bail!(\"Port must be > 0\");\n    }\n    if options.web && options.host != \"127.0.0.1\" {\n        bail!(\"Codewhale web is loopback-only and must bind to 127.0.0.1\");\n    }\n    if options.web && options.insecure_no_auth {\n        bail!(\"Codewhale web requires Runtime authentication; remove --insecure\");\n    }\n\n    let task_cfg = TaskManagerConfig::from_runtime(\n        &config,\n        workspace.clone(),\n        config.default_text_model.clone(),\n        Some(options.workers),\n    );\n    let (runtime_threads, _workshop_activation) = open_runtime_threads_for_server(\n        &config,\n        workspace.clone(),\n        RuntimeThreadManagerConfig::from_task_data_dir(task_cfg.data_dir.clone()),","sourceCodeStart":814,"sourceCodeEnd":850,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/runtime_api.rs#L814-L850","documentation":"run_http_server validates RuntimeApiOptions before binding and rejects port == 0. Unlike some servers that treat 0 as 'assign me an ephemeral port', the runtime API requires an explicit positive port because clients (web UI, bridges) must know the port ahead of time. The field is a u16, so only the value 0 fails this check.","triggerScenarios":"Starting the runtime API server with RuntimeApiOptions { port: 0, .. }; typically from a CLI/server subcommand where the port flag was not provided and defaulted to 0, or a config that parsed an unset port.","commonSituations":"Assuming OS-assigned ephemeral ports work here; config files with port: 0 or a commented-out port that deserializes to 0; scripts copying an example that never set --port.","solutions":["Pass an explicit port greater than 0 (e.g. --port 8080 or RuntimeApiOptions { port: 8080, .. }).","If the port comes from config, check how unset values deserialize and give the key a real default instead of 0.","Pick a port outside the ephemeral range if you also want stable reboots (e.g. avoid 32768-60999 on Linux)."],"exampleFix":"// before\nlet options = RuntimeApiOptions { port: 0, ..Default::default() };\nrun_http_server(config, workspace, discovery, options).await?; // bails: Port must be > 0\n\n// after\nlet options = RuntimeApiOptions { port: 8080, ..Default::default() };\nrun_http_server(config, workspace, discovery, options).await?;","handlingStrategy":"validation","validationCode":"// Rust: validate options before starting the server\nfn valid_port(port: u16) -> bool { port > 0 }\n\nlet port = options.port;\nanyhow::ensure!(valid_port(port), \"refusing to start: port {port} must be > 0\");\nrun_http_server(config, workspace, discovery, options).await?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give the port a real non-zero default wherever RuntimeApiOptions is constructed.","Fail fast on unset config keys (Option<u16>) instead of coercing them to 0.","Log the resolved port at startup so misconfiguration is visible immediately."],"tags":["server","port","startup-validation","rust","runtime-api"],"backgroundTag":"invalid-port-configuration","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}