warpdotdev/warp · error · anyhow::Error

{OZ_RUN_ID_ENV_VAR} is set but is not valid Unicode

Error message

{OZ_RUN_ID_ENV_VAR} is set but is not valid Unicode

What it means

`load_env_run_id` reads OZ_RUN_ID to associate uploaded artifacts with the ambient agent task. `env::VarError::NotUnicode` means the variable's bytes are not valid UTF-8, so it can never parse as a task id and upload association fails.

Source

Thrown at app/src/ai/agent_sdk/artifact_upload.rs:303

fn ambient_task_id_from_conversation_metadata(
    conversation_id: &str,
    metadata: ServerAIConversationMetadata,
) -> Result<AmbientAgentTaskId> {
    metadata.ambient_agent_task_id.ok_or_else(|| {
        anyhow!("Conversation '{conversation_id}' is not backed by a cloud agent task")
    })
}

fn parse_run_id(run_id: &str, error_prefix: &str) -> Result<AmbientAgentTaskId> {
    parse_ambient_task_id(run_id, error_prefix)
}

fn load_env_run_id() -> Result<Option<String>> {
    match env::var(OZ_RUN_ID_ENV_VAR) {
        Ok(run_id) => Ok(Some(run_id)),
        Err(env::VarError::NotPresent) => Ok(None),
        Err(env::VarError::NotUnicode(_)) => Err(anyhow!(
            "{OZ_RUN_ID_ENV_VAR} is set but is not valid Unicode"
        )),
    }
}

fn resolve_env_run_id(env_run_id: Option<String>) -> Result<AmbientAgentTaskId> {
    let Some(run_id) = env_run_id else {
        bail!("{OZ_RUN_ID_ENV_VAR} is not set");
    };

    parse_run_id(&run_id, "Invalid OZ_RUN_ID")
}

fn resolve_upload_association_from_sources(
    explicit_run_id: Option<AmbientAgentTaskId>,
    explicit_conversation_id: Option<ServerConversationToken>,
    conversation_task_id: Option<Result<AmbientAgentTaskId>>,
    env_run_id: Option<String>,

View on GitHub (pinned to e72fd7aacb)

Solutions

  1. Pass `--run-id <ambient task id>` explicitly and stop depending on the env var
  2. Re-export OZ_RUN_ID with the valid task id string, or unset it
  3. Fix the runner/harness that injects OZ_RUN_ID so it writes valid UTF-8

Example fix

# before
OZ_RUN_ID=$'\xff\xfe' warp artifacts upload out.log
# after
warp artifacts upload --run-id <ambient-task-id> out.log
Defensive patterns

Strategy: validation

Validate before calling

fn env_run_id_usable() -> Option<String> {
    std::env::var_os(OZ_RUN_ID_ENV_VAR)?.to_str().map(str::to_owned)
}
// Require Some(valid id) or an explicit --run-id before starting the upload.

Type guard

fn env_run_id_is_utf8() -> bool {
    std::env::var_os(OZ_RUN_ID_ENV_VAR)
        .map(|v| v.to_str().is_some())
        .unwrap_or(true)
}

Prevention

When it happens

Trigger: Running artifact upload where OZ_RUN_ID contains invalid UTF-8 bytes (set by a corrupted orchestration layer, CI env forwarding, or manual export from binary data) and no explicit --run-id was supplied.

Common situations: Corrupted runner env; CI env forwarding bugs; container images with broken encoding; hand-set env vars from non-text sources.

Related errors


AI-assisted analysis of warpdotdev/warp@e72fd7aacb (2026-08-16). Data as JSON: /api/errors/b6d42014aea955e1. Report an issue: GitHub.