Hmbown/CodeWhale · error

cloud agent label apply failed

Error message

cloud agent label apply failed (HTTP {status}).

What it means

Daytona's labels endpoint (PUT sandbox/{id}/labels) returned a non-success HTTP status. The library treats label application as part of sandbox provisioning: without the job labels the sandbox is unaccounted for, so this failure aborts the dispatch (and triggers teardown by the caller).

Solutions

  1. Check the HTTP status in the wrapped error and verify the API key is valid and has sandbox write scope
  2. Retry the job — the code already tears the sandbox down and asks for a retry
  3. Check Daytona service status if 5xx
  4. Reduce dispatch concurrency if 429
Defensive patterns

Strategy: retry

Validate before calling

// verify credential before dispatch
let key = std::env::var("DAYTONA_API_KEY").expect("DAYTONA_API_KEY set");
assert!(!key.trim().is_empty());

Try / catch

match put_sandbox_labels(id, key, job) {
    Err(e) if is_retryable_status(&e) => schedule_retry(job),
    Err(e) => bail!("labels failed permanently: {e}"),
    Ok(()) => {}
}

Prevention

When it happens

Trigger: `send_json` PUT to the labels URL succeeds at the transport level but Daytona answers 4xx/5xx — e.g. 401/403 from a bad API key, 404 because the sandbox was destroyed concurrently, 429 rate limiting, or 5xx provider outage.

Common situations: Expired or wrong `CLOONEST_API_KEY`-style credential, sandbox reaped between create and label, Daytona incident/maintenance window, or rate limits under many parallel dispatches.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/160bcce29d66a5cf. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/cloud_dispatch.rs:1447

    /// Apply the dispatch labels via Daytona's dedicated labels endpoint.
    fn put_sandbox_labels(sandbox_id: &str, api_key: &str, job: &CloudJob) -> Result<()> {
        if !valid_sandbox_id(sandbox_id) {
            bail!("the sandbox id is not a usable path token");
        }
        let url = Self::control_plane_url(&format!("sandbox/{sandbox_id}/labels"))?;
        let body = serde_json::json!({
            "labels": {
                SANDBOX_JOB_LABEL: job.id,
                "codewhale.forge": job.forge.as_str(),
                SANDBOX_PRODUCT_LABEL: SANDBOX_PRODUCT_VALUE,
            }
        });
        let response = Self::send_json(reqwest::Method::PUT, &url, api_key, body)?;
        let status = response.status();
        if status.is_success() {
            Ok(())
        } else {
            bail!("cloud agent label apply failed (HTTP {status}).")
        }
    }

    fn send_json(
        method: reqwest::Method,
        url: &reqwest::Url,
        api_key: &str,
        body: serde_json::Value,
    ) -> Result<reqwest::blocking::Response> {
        Self::send_json_on(
            &Self::blocking_client()?,
            Self::CONTROL_PLANE_TIMEOUT_SECS,
            method,
            url,
            api_key,
            body,
        )
    }

View on GitHub (pinned to 73e0f67d83)