{"record":{"id":"ba50e125f3e099ed","repo":"nikivdev/code","slug":"codex-app-server-error","errorCode":null,"errorMessage":"codex app-server error: {}","messagePattern":"codex app-server error: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/skills.rs","lineNumber":1136,"sourceCode":"            bail!(\"codex app-server response timed out\");\n        }\n        let line = match lines.next() {\n            Some(Ok(line)) => line,\n            Some(Err(err)) => bail!(\"failed to read from codex app-server: {}\", err),\n            None => bail!(\"codex app-server closed stdout unexpectedly\"),\n        };\n        if line.trim().is_empty() {\n            continue;\n        }\n        let msg: serde_json::Value = serde_json::from_str(&line)\n            .with_context(|| format!(\"invalid JSON from codex app-server: {}\", line))?;\n        if msg.get(\"id\").and_then(|v| v.as_u64()) == Some(expected_id) {\n            if let Some(err) = msg.get(\"error\") {\n                let message = err\n                    .get(\"message\")\n                    .and_then(|v| v.as_str())\n                    .unwrap_or(\"unknown codex app-server error\");\n                bail!(\"codex app-server error: {}\", message);\n            }\n            return Ok(msg);\n        }\n    }\n}\n\npub(crate) fn reload_codex_skills_for_cwd(cwd: &Path) -> Result<usize> {\n    let codex_bin = configured_codex_bin_for_workdir(cwd);\n\n    let mut child = Command::new(&codex_bin)\n        .arg(\"app-server\")\n        .current_dir(cwd)\n        .stdin(std::process::Stdio::piped())\n        .stdout(std::process::Stdio::piped())\n        .stderr(std::process::Stdio::piped())\n        .spawn()\n        .context(\"failed to run codex app-server\")?;\n","sourceCodeStart":1118,"sourceCodeEnd":1154,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/skills.rs#L1118-L1154","documentation":"The codex app-server answered the request, but the JSON-RPC response contained an \"error\" object instead of a result. codex_read_response extracts the error's \"message\" field (defaulting to \"unknown codex app-server error\") and bails with this message. This is a server-side rejection of the request, not a transport problem.","triggerScenarios":"reload_codex_skills_for_cwd sends a request and the app-server replies with {\"id\": expected_id, \"error\": {\"message\": ...}} — e.g. the requested method is unknown, parameters are invalid, or the server is in a bad state.","commonSituations":"Protocol version mismatch so the method name is unsupported; invalid request payload (malformed cwd or params); app-server not initialized when the request arrives; permissions or workspace errors on the server side.","solutions":["Read the embedded server message after 'codex app-server error:' to identify the server-side cause","Verify the request method/params match the codex app-server protocol version in use","Ensure the app-server is fully initialized before sending requests","Upgrade or align the codex binary with the client expectations"],"exampleFix":"// before: opaque without context of the request\nbail!(\"codex app-server error: {}\", message);\n// after: include the request id for correlation\nbail!(\"codex app-server error (id {}): {}\", expected_id, message);","handlingStrategy":"try-catch","validationCode":"// pre-validate request params the server is known to reject\nassert!(cwd.is_dir(), \"cwd passed to app-server must exist: {}\", cwd.display());","typeGuard":null,"tryCatchPattern":"match codex_read_response(&mut lines, expected_id, deadline) {\n    Ok(msg) => Ok(msg),\n    Err(e) if e.to_string().starts_with(\"codex app-server error:\") => {\n        let server_msg = e.to_string().trim_start_matches(\"codex app-server error:\");\n        eprintln!(\"server rejected request: {server_msg}\");\n        // method/param mismatch => fix request, don't retry blindly\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Match request method names and params to the app-server protocol version","Initialize/handshake with the server before other requests","Log the full JSON-RPC error object, not just the message field","Keep the codex binary and client in version lockstep"],"tags":["json-rpc","codex","ipc","server-error"],"backgroundTag":"json-rpc-server-error","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}