{"record":{"id":"5d027148db36192d","repo":"BigPizzaV3/CodexPlusPlus","slug":"codex-app-server-method-error","errorCode":null,"errorMessage":"Codex app-server {method} 失败：{error}","messagePattern":"Codex app-server (.+?) 失败：(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/connect/app_server.rs","lineNumber":363,"sourceCode":"            \"params\": params\n        }))\n        .await?;\n        let deadline = tokio::time::Instant::now() + timeout;\n        loop {\n            let remaining = deadline.saturating_duration_since(tokio::time::Instant::now());\n            if remaining.is_zero() {\n                bail!(\"Codex app-server {method} 请求超时\");\n            }\n            let message = self.read_message(remaining).await?;\n            if is_server_request(&message) {\n                self.reject_server_request(&message).await?;\n                continue;\n            }\n            if response_id(&message) != Some(id) {\n                continue;\n            }\n            if let Some(error) = rpc_error(&message) {\n                bail!(\"Codex app-server {method} 失败：{error}\");\n            }\n            return Ok(message.get(\"result\").cloned().unwrap_or(Value::Null));\n        }\n    }\n\n    async fn read_message(&mut self, timeout: Duration) -> anyhow::Result<Value> {\n        loop {\n            let line = tokio::time::timeout(timeout, self.stdout.next_line())\n                .await\n                .context(\"等待 Codex app-server 响应超时\")??;\n            let Some(line) = line else {\n                self.running = false;\n                let exit = self.child.try_wait().ok().flatten();\n                bail!(\n                    \"Codex app-server 已关闭{}\",\n                    exit.map(|status| format!(\"：{status}\")).unwrap_or_default()\n                );\n            };","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/connect/app_server.rs#L345-L381","documentation":"When the JSON-RPC response matching the request id carries an error payload, request() throws this error embedding the method name and the server's error text. It means the Codex app-server explicitly failed the RPC (initialize, thread/new, etc.) rather than timing out.","triggerScenarios":"request() gets a response with response_id == id and a non-null rpc_error — e.g. initialize rejected due to protocol version mismatch, thread/new rejected because work_dir does not exist or auth is missing/expired.","commonSituations":"Expired Codex authentication credentials, work_dir path removed or not accessible, CLI/app-server protocol version incompatibility after an upgrade, invalid sandbox or model options passed in the request params.","solutions":["Read the embedded {error} text from Codex for the exact cause","Re-authenticate Codex if the error mentions auth/credentials","Verify work_dir exists and is readable/writable","Update the Codex CLI to match the protocol the library speaks"],"exampleFix":"// before\nAppServerConfig { work_dir: PathBuf::from(\"/tmp/gone\"), .. }\n// after\nlet work_dir = PathBuf::from(\"/tmp/project\");\nassert!(work_dir.is_dir());\nAppServerConfig { work_dir, .. }","handlingStrategy":"validation","validationCode":"// pre-flight before start()\nassert!(config.work_dir.is_dir(), \"work_dir missing\");\n// verify codex auth out-of-band before opening the app-server","typeGuard":null,"tryCatchPattern":"match CodexAppServer::start(config).await {\n    Err(e) if e.to_string().contains(\"失败：\") => {\n        eprintln!(\"app-server RPC failed: {e}\");\n        // re-auth / recreate work_dir / align versions\n    }\n    r => r?,\n}","preventionTips":["Refresh credentials before sessions","Guarantee work_dir exists and is writable","Keep CLI/library versions matched","Validate model and sandbox options against the installed CLI"],"tags":["json-rpc","ipc","api-error","configuration"],"backgroundTag":"api-error-response","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}