BigPizzaV3/CodexPlusPlus · error

Codex app-server 失败:

Error message

Codex app-server {method} 失败:{error}

What it means

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.

Solutions

  1. Read the embedded {error} text from Codex for the exact cause
  2. Re-authenticate Codex if the error mentions auth/credentials
  3. Verify work_dir exists and is readable/writable
  4. Update the Codex CLI to match the protocol the library speaks

Example fix

// before
AppServerConfig { work_dir: PathBuf::from("/tmp/gone"), .. }
// after
let work_dir = PathBuf::from("/tmp/project");
assert!(work_dir.is_dir());
AppServerConfig { work_dir, .. }
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight before start()
assert!(config.work_dir.is_dir(), "work_dir missing");
// verify codex auth out-of-band before opening the app-server

Try / catch

match CodexAppServer::start(config).await {
    Err(e) if e.to_string().contains("失败:") => {
        eprintln!("app-server RPC failed: {e}");
        // re-auth / recreate work_dir / align versions
    }
    r => r?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/5d027148db36192d. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/connect/app_server.rs:363

            "params": params
        }))
        .await?;
        let deadline = tokio::time::Instant::now() + timeout;
        loop {
            let remaining = deadline.saturating_duration_since(tokio::time::Instant::now());
            if remaining.is_zero() {
                bail!("Codex app-server {method} 请求超时");
            }
            let message = self.read_message(remaining).await?;
            if is_server_request(&message) {
                self.reject_server_request(&message).await?;
                continue;
            }
            if response_id(&message) != Some(id) {
                continue;
            }
            if let Some(error) = rpc_error(&message) {
                bail!("Codex app-server {method} 失败:{error}");
            }
            return Ok(message.get("result").cloned().unwrap_or(Value::Null));
        }
    }

    async fn read_message(&mut self, timeout: Duration) -> anyhow::Result<Value> {
        loop {
            let line = tokio::time::timeout(timeout, self.stdout.next_line())
                .await
                .context("等待 Codex app-server 响应超时")??;
            let Some(line) = line else {
                self.running = false;
                let exit = self.child.try_wait().ok().flatten();
                bail!(
                    "Codex app-server 已关闭{}",
                    exit.map(|status| format!(":{status}")).unwrap_or_default()
                );
            };

View on GitHub (pinned to b1ed92e5e4)