{"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":1104,"sourceCode":"    }\n    let serve_result = axum::serve(\n        listener,\n        app.into_make_service_with_connect_info::<SocketAddr>(),\n    )\n    .await\n    .map_err(|e| anyhow!(\"Runtime API server error: {e}\"));\n    scheduler_cancel.cancel();\n    scheduler_handle.abort();\n    task_manager.shutdown_and_wait().await?;\n    serve_result\n}\n\n/// Mobile control uses plain HTTP only on loopback. It has no TLS or verified\n/// overlay transport, so a non-loopback listener would expose the Runtime API\n/// to peers that can observe or replay browser traffic.\nfn validate_runtime_listener_security(options: &RuntimeApiOptions) -> 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    if options.mobile && !is_loopback_bind_host(&options.host) {\n        bail!(\n            \"Codewhale mobile is loopback-only without TLS or a verified overlay; bind to 127.0.0.1 or ::1\"\n        );\n    }\n    if options.insecure_no_auth && !is_loopback_bind_host(&options.host) {\n        bail!(\n            \"Unauthenticated Runtime access is loopback-only; remove --insecure or bind to 127.0.0.1 or ::1\"\n        );\n    }\n    Ok(())","sourceCodeStart":1086,"sourceCodeEnd":1122,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_api.rs#L1086-L1122","documentation":"`validate_runtime_listener_security` rejects a Runtime API port of 0 because the mobile/control HTTP listener needs an actual deterministic port; port 0 (OS-assigned ephemeral) is not accepted for this secured surface.","triggerScenarios":"Starting the Runtime API with `RuntimeApiOptions.port == 0`, typically from a CLI flag like `--port 0` or a config value defaulting to 0.","commonSituations":"Copy-pasting a dev config where the port was never set; assuming port 0 means 'pick any free port' as with ordinary TCP servers.","solutions":["Pass an explicit port > 0, e.g. --port 8080","Fix the config value that sets port to 0","Check for a shell variable expanding empty/0 into the flag"],"exampleFix":"// before\ncodewhale runtime --port 0\n// after\ncodewhale runtime --port 8080","handlingStrategy":"validation","validationCode":"if port <= 0 { return Err(\"Runtime API port must be an explicit positive integer\".into()); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass --port 0 to the runtime API","Read ports from config with a positive-integer default","Validate numeric flags before constructing RuntimeApiOptions"],"tags":["runtime-api","port","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}