jlcodes99/cockpit-tools · error

网关 prepareStartContext 请求失败[{}]: {} (url={})

Error message

网关 prepareStartContext 请求失败[{}]: {} (url={})

What it means

trigger_wakeup_via_client_gateway_once first calls a prepareStartContext gateway endpoint before the main wakeup; a transport failure there is wrapped as '网关 prepareStartContext 请求失败[{kind}]: {err} (url={prepare_url})'. Like error 255, this is a pre-response transport failure, but specific to the prepareStartContext bootstrap step, so the whole wakeup cascade cannot begin.

Source

Thrown at src-tauri/src/modules/wakeup.rs:1460

            cancel_rx,
            client
                .post(&prepare_url)
                .header(reqwest::header::CONTENT_TYPE, "application/json")
                .json(&json!({
                    "accountId": account_id,
                    "model": model,
                    "maxOutputTokens": max_output_tokens,
                }))
                .send(),
        )
        .await?
        .map_err(|e| {
            let kind = classify_gateway_transport_error(&e);
            let message = format!(
                "网关 prepareStartContext 请求失败[{}]: {} (url={})",
                kind, e, prepare_url
            );
            crate::modules::logger::log_error(&format!("[Wakeup] {}", message));
            message
        })?
        .error_for_status()
        .map_err(|e| {
            format!(
                "网关 prepareStartContext 返回错误: {} (url={})",
                e, prepare_url
            )
        })?;

        start_resp = post_gateway_json(
            &client,
            &format!("{}/StartCascade", service_base),
            &json!({}),
            "StartCascade",
            cancel_rx,
        )
        .await?;

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Check the classified [kind] to pinpoint dns/connect/tls/timeout
  2. Verify the prepareStartContext URL and gateway config for the active environment
  3. Test connectivity to the gateway host directly (curl/ping)
  4. Retry with backoff; the caller may fall back to alternate base URLs
  5. If TLS-related, refresh CA certs or fix the server certificate

Example fix

// before
.map_err(|e| {
    let kind = classify_gateway_transport_error(&e);
    let message = format!("网关 prepareStartContext 请求失败[{}]: {} (url={})", kind, e, prepare_url);
    crate::modules::logger::log_error(&format!("[Wakeup] {}", message));
    message
})?;
// after
.map_err(|e| {
    let kind = classify_gateway_transport_error(&e);
    let message = format!("网关 prepareStartContext 请求失败[{}]: {} (url={})", kind, e, prepare_url);
    crate::modules::logger::log_error(&format!("[Wakeup] {}", message));
    retry_with_backoff_if_transient(kind); // e.g. connect/timeout only
    message
})?;
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight reachability of the prepare endpoint before the wakeup cascade
fn prepare_endpoint_ok(prepare_url: &str) -> bool {
    reqwest::blocking::get(prepare_url).map(|r| !r.status().is_server_error()).unwrap_or(false)
}

Type guard

fn is_prepare_transport_error(err: &str) -> bool { err.contains("prepareStartContext 请求失败") }

Try / catch

match trigger_wakeup_via_client_gateway(req).await {
    Err(e) if e.contains("prepareStartContext 请求失败") => {
        // bootstrap failed: back off, then retry with fallback base URL
        sleep_backoff();
        try_wakeup_with_next_base().await;
    }
    other => handle(other),
}

Prevention

When it happens

Trigger: trigger_wakeup_via_client_gateway → trigger_wakeup_via_client_gateway_once sends the prepareStartContext POST and reqwest fails at DNS/connect/TLS/timeout before any HTTP status is received.

Common situations: Gateway host down or misconfigured; network offline/VPN drop at session start; TLS certificate problems on the prepare endpoint; client timeout set too low for a slow gateway; wrong environment base URL.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/d98fe70893644168. Report an issue: GitHub.