{"record":{"id":"60a59fd50088ba52","repo":"facebook/flow","slug":"max-workers-should-be-positive","errorCode":null,"errorMessage":"max_workers should be positive","messagePattern":"max_workers should be positive","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_server/src/standalone.rs","lineNumber":70,"sourceCode":"use flow_utils_concurrency::thread_pool::ThreadPool;\nuse flow_utils_concurrency::worker_cancel;\n\nconst SERVER_THREAD_STACK_SIZE: usize = if cfg!(windows) {\n    64 * 1024 * 1024\n} else {\n    32 * 1024 * 1024\n};\nconst CONNECTION_THREAD_STACK_SIZE: usize = 2 * 1024 * 1024;\nconst MAX_CONNECTION_THREADS: usize = 128;\nconst INITIAL_CONNECTION_READ_TIMEOUT_SECS: u64 = 5;\n\npub fn start(options: Arc<Options>, flowconfig_name: String) {\n    crate::server::check_supported_operating_system(&options);\n    flow_server_env::monitor_rpc::disable();\n    let committed_heap = Arc::new(CommittedHeap::new());\n    let pool = ThreadPool::with_thread_count(ThreadCount::NumThreads(\n        std::num::NonZeroUsize::new(options.max_workers as usize)\n            .expect(\"max_workers should be positive\"),\n    ));\n    let tmp_dir = options.temp_dir.to_string();\n    let server = FlowServer::new(options, committed_heap, pool, flowconfig_name, tmp_dir);\n    server.run();\n}\n\nstruct ServerState {\n    env: Option<flow_server_env::server_env::EnvRef>,\n    init_done: bool,\n    pending_recheck: bool,\n    recheck_in_progress: bool,\n    should_shutdown: bool,\n}\n\nfn current_persistent_status(\n    server_state: &ServerState,\n) -> (server_status::Status, file_watcher_status::Status) {\n    let status = if !server_state.init_done {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_server/src/standalone.rs#L52-L88","documentation":"Standalone server startup converts options.max_workers (an i32 flowing from the CLI --max-workers flag or [server] max_workers in .flowconfig) to NonZeroUsize and expects success (rust_port/crates/flow_server/src/standalone.rs:67-71). A value of 0, or a negative value that wraps when cast to usize, makes NonZeroUsize::new return None and the server panics with 'max_workers should be positive' during startup. It is a configuration validation gate expressed as a panic.","triggerScenarios":"Passing --max-workers 0; setting server.max_workers = 0 (or a negative value, including the max_workers_full_check variant) in .flowconfig; programmatically building flow_common Options with max_workers left at a 0 default (several internal constructors default it to 0) and calling standalone::start.","commonSituations":"CI scripts computing worker counts arithmetically (cores - 1 on a 1-core runner yields 0); copy-pasted .flowconfig using max_workers = 0 intending 'auto'; embedding code that constructs Options without the CLI parser.","solutions":["Set a positive worker count: --max-workers N or server.max_workers = N (>= 1) in .flowconfig, or omit the setting to use the physical-core default","Fix scripts that derive the value arithmetically so they clamp to at least 1","If constructing Options programmatically, assert max_workers >= 1 before calling standalone::start","Upstream: replace the expect with a clear config error that includes the offending value"],"exampleFix":"# before (.flowconfig)\n[server]\nmax_workers = 0\n\n# after: positive value, or remove the key entirely\n[server]\nmax_workers = 4\n\n// programmatic guard before start()\nassert!(options.max_workers >= 1, \"max_workers must be positive, got {}\", options.max_workers);","handlingStrategy":"validation","validationCode":"// Validate before start()\nif options.max_workers < 1 {\n    return Err(format!(\"server.max_workers must be >= 1, got {}\", options.max_workers));\n}\nflow_server::standalone::start(options, flowconfig_name);","typeGuard":"fn valid_max_workers(n: i32) -> bool {\n    n >= 1\n}","tryCatchPattern":null,"preventionTips":["Clamp computed worker counts: max(1, cores - reserve)","Never use 0 to mean 'auto' — omit the setting instead","Validate .flowconfig server.max_workers values in CI linting"],"tags":["configuration","flowconfig","max-workers","server-startup","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}