zed-industries/zed · error

Failed to create OpenAI client

Error message

Failed to create OpenAI client

What it means

Panics inside run_repair's Openai arm when the OpenAiClient constructor fails for the repair step (plain or batched against LLM_CACHE_DB). During batch reprocessing the shared cache database is under concurrent access, so a constructor error from a locked or busy cache DB is turned into a panic by expect rather than a per-example error the driver can record and continue past.

Source

Thrown at crates/edit_prediction_cli/src/repair.rs:375

            let Some(response) = client.generate(model, 16384, messages, None, false).await? else {
                return Ok(());
            };

            response
                .content
                .iter()
                .filter_map(|c| match c {
                    anthropic::ResponseContent::Text { text } => Some(text.as_str()),
                    _ => None,
                })
                .collect::<Vec<_>>()
                .concat()
        }
        BatchProvider::Openai => {
            let client = if args.no_batch {
                OPENAI_CLIENT_PLAIN
                    .get_or_init(|| OpenAiClient::plain().expect("Failed to create OpenAI client"))
            } else {
                OPENAI_CLIENT_BATCH.get_or_init(|| {
                    OpenAiClient::batch(&LLM_CACHE_DB).expect("Failed to create OpenAI client")
                })
            };

            let messages = vec![
                // Turn 1: Original teacher prompt
                open_ai::RequestMessage::User {
                    content: open_ai::MessageContent::Plain(teacher_prompt.input.clone()),
                },
                // Turn 2: Original teacher response
                open_ai::RequestMessage::Assistant {
                    content: Some(open_ai::MessageContent::Plain(teacher_response.clone())),
                    tool_calls: vec![],
                    reasoning_content: None,
                    reasoning_details: None,
                },

View on GitHub (pinned to f4178619ac)

Solutions

  1. Return the constructor error from run_repair via ? so reprocess_after_batch_wait can mark just this example failed
  2. Add retry-with-backoff around client construction to ride out transient cache DB contention
  3. Fail fast on client construction once at startup to avoid mid-run aborts
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/edit_prediction_cli/src/repair.rs:375 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/abced21d55089759. Report an issue: GitHub.