{"record":{"id":"0ded400c5544a3bb","repo":"pbakaus/impeccable","slug":"serve-question-stop-needs-key","errorCode":null,"errorMessage":"serve-question: --stop needs --key\n","messagePattern":"serve-question: --stop needs --key\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/context/src/serve_question.rs","lineNumber":274,"sourceCode":"            return 3;\n        }\n        let collected = safe_read(&answer_file(&qdir, &key)).unwrap_or_default();\n        let collected = crate::util::js_trim(&collected).to_string();\n        print_answer(io, &collected);\n        let mut keeps_open = false;\n        if let Ok(p) = serde_json::from_str::<Value>(&collected) {\n            keeps_open = p.get(\"optionId\").and_then(|v| v.as_str()) == Some(\"reroll\") || p.get(\"followup\") == Some(&Value::Bool(true));\n        }\n        let _ = std::fs::remove_file(answer_file(&qdir, &key));\n        if !keeps_open {\n            let _ = std::fs::remove_file(state_file(&qdir, &key));\n        }\n        return 0;\n    }\n\n    if a.has(\"stop\") {\n        let Some(key) = a.arg(\"key\") else {\n            io.err(\"serve-question: --stop needs --key\\n\");\n            return 1;\n        };\n        if let Some(state) = read_state(&qdir, &key) {\n            if let Some(pid) = state.get(\"pid\").and_then(|p| p.as_f64()) {\n                kill_pid(pid as i64);\n            }\n        }\n        let _ = std::fs::remove_file(answer_file(&qdir, &key));\n        let _ = std::fs::remove_file(state_file(&qdir, &key));\n        io.out(\"stopped\\n\");\n        return 0;\n    }\n\n    if a.has(\"update\") {\n        let key = a.arg(\"key\");\n        let (Some(key), Some(pp)) = (key, payload_path.clone()) else {\n            io.err(\"serve-question: --update needs --key and --payload\\n\");\n            return 1;","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/crates/context/src/serve_question.rs#L256-L292","documentation":"The --stop flag shuts down a running question server by killing the recorded PID, which requires --key to locate the state file holding that PID. Without --key, run() prints this message and exits 1 instead of stopping an arbitrary question server.","triggerScenarios":"Invoking `serve-question --stop` without the `--key <key>` argument identifying the question whose server should be terminated.","commonSituations":"Cleanup scripts that lost track of the key between sessions; trying to stop 'the' question server when several keys may be live; copy-pasting a stop command without editing the key placeholder.","solutions":["Re-run with the exact --key used at --start time.","If the key is lost, list the question directories under the qdir to recover candidate keys.","As a last resort, kill the server process manually and remove the stale state file."],"exampleFix":"// before\nserve-question --stop\n// after\nserve-question --stop --key <key-from-start>","handlingStrategy":"validation","validationCode":"if (args.includes('--stop') && !args.includes('--key')) {\n  throw new Error('serve-question --stop requires --key');\n}","typeGuard":"null","tryCatchPattern":"const res = spawnSync('serve-question', args);\nif (res.status === 1 && res.stderr.includes('--stop needs --key')) {\n  // recover the key from the qdir state files, then retry\n}","preventionTips":["Store the key alongside the PID when starting the question","Enumerate qdir state files to recover keys before stopping","Never issue a bare --stop in shared scripts"],"tags":["cli","argument-validation","process-management"],"backgroundTag":"missing-required-flag","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}