{"record":{"id":"809d0a561d7f6c7c","repo":"BigPizzaV3/CodexPlusPlus","slug":"codex-turn-start-error","errorCode":null,"errorMessage":"Codex turn/start 失败：{error}","messagePattern":"Codex turn/start 失败：(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/connect/app_server.rs","lineNumber":231,"sourceCode":"        let mut response_received = false;\n        let mut turn_completed = false;\n        let mut reply_parts = Vec::new();\n        let mut model = self.config.model.trim().to_string();\n        let mut usage = TurnUsage::default();\n        let deadline = tokio::time::Instant::now() + TURN_TIMEOUT;\n        while !response_received || !turn_completed {\n            let remaining = deadline.saturating_duration_since(tokio::time::Instant::now());\n            if remaining.is_zero() {\n                bail!(\"等待 Codex 回复超时\");\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                if let Some(error) = rpc_error(&message) {\n                    bail!(\"Codex turn/start 失败：{error}\");\n                }\n                let result = message.get(\"result\").cloned().unwrap_or(Value::Null);\n                if extract_turn_id(&result).is_none() {\n                    bail!(\"Codex turn/start 未返回 turn id\");\n                }\n                if model.is_empty() {\n                    model = extract_model(&result).unwrap_or_default();\n                }\n                if let Some(reported_usage) = extract_turn_usage(&result) {\n                    usage = reported_usage;\n                }\n                response_received = true;\n                continue;\n            }\n\n            if model.is_empty() {\n                model = extract_model(&message).unwrap_or_default();\n            }","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/connect/app_server.rs#L213-L249","documentation":"When the JSON-RPC response to the turn/start request carries an error payload, run_turn surfaces it with this message, embedding the server-provided error text. It means Codex explicitly rejected the turn/start RPC rather than timing out or crashing silently.","triggerScenarios":"run_turn sends turn/start; the matching response (by id) contains rpc_error — e.g. invalid model name, rejected session/thread, sandbox or work_dir problems, Codex-side auth failure, malformed turn parameters.","commonSituations":"Configured model string no longer exists after a CLI update, expired ChatGPT/Codex authentication, work_dir deleted or inaccessible, sandbox mode value not accepted by the installed CLI version.","solutions":["Read the embedded {error} text — it comes from Codex itself and usually names the cause","Verify the model name in config matches a model the installed CLI supports (`codex` / app-server model list)","Re-authenticate with Codex (check auth status) and confirm work_dir/sandbox settings are valid","Update the Codex CLI and the library so protocol expectations match"],"exampleFix":"// before\nAppServerConfig { model: \"gpt-5-turbo-preview\".into(), .. } // removed model\n// after\nAppServerConfig { model: \"gpt-5\".into(), .. } // model supported by installed CLI","handlingStrategy":"validation","validationCode":"// before start: confirm the model is one the CLI accepts\nif !supported_models().contains(&config.model) {\n    eprintln!(\"model {} not supported by installed CLI\", config.model);\n}","typeGuard":null,"tryCatchPattern":"match server.run_turn(prompt).await {\n    Err(e) if e.to_string().contains(\"turn/start 失败\") => {\n        eprintln!(\"server rejected turn: {e}\");\n        // switch model / re-auth / adjust sandbox based on embedded cause\n    }\n    r => r,\n}","preventionTips":["Sync model names with the installed CLI version","Refresh authentication proactively","Validate work_dir/sandbox before each session","Upgrade CLI and library together"],"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"}