xai-org/grok-build · error

invalid {GROK_CHAT_LOCAL_WORKSPACE_MODE_ENV}={other:?}; expe

Error message

invalid {GROK_CHAT_LOCAL_WORKSPACE_MODE_ENV}={other:?}; expected own|attach

What it means

The env var `GROK_CHAT_LOCAL_WORKSPACE_MODE` must be exactly `own` or `attach`. Any other non-empty value causes `resolve_local_workspace_config` to bail with `invalid GROK_CHAT_LOCAL_WORKSPACE_MODE=<value>; expected own|attach` (session_startup.rs:441).

Source

Thrown at crates/codegen/xai-grok-pager/src/app/session_startup.rs:441

    let cli_attach = cli_attach.map(str::trim).filter(|s| !s.is_empty());
    let cli_requested = cli_own.is_some() || cli_attach.is_some();
    let env_requested = env_enable || env_mode.is_some() || env_server_id.is_some();
    if !cli_requested && !env_requested {
        return Ok(None);
    }
    if !chat {
        anyhow::bail!("{LOCAL_WORKSPACE_REQUIRES_CHAT}");
    }
    let mode = if cli_attach.is_some() {
        LocalWorkspaceMode::Attach
    } else if cli_own.is_some() {
        LocalWorkspaceMode::Own
    } else if let Some(ref m) = env_mode {
        match m.as_str() {
            "attach" => LocalWorkspaceMode::Attach,
            "own" => LocalWorkspaceMode::Own,
            other => {
                anyhow::bail!(
                    "invalid {GROK_CHAT_LOCAL_WORKSPACE_MODE_ENV}={other:?}; expected own|attach"
                )
            }
        }
    } else if env_server_id.is_some() {
        LocalWorkspaceMode::Attach
    } else {
        LocalWorkspaceMode::Own
    };
    let cwd = cli_cwd
        .map(std::path::Path::to_path_buf)
        .or_else(|| cli_own.and_then(|inner| inner.map(std::path::Path::to_path_buf)))
        .or(env_cwd)
        .unwrap_or_else(|| {
            std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from("."))
        });
    let cwd = if cwd.is_absolute() {
        cwd

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Set the env var to exactly `own` or `attach` (lowercase, no whitespace)
  2. Unset GROK_CHAT_LOCAL_WORKSPACE_MODE and rely on CLI flags instead
  3. Check the value for typos/case with `echo $GROK_CHAT_LOCAL_WORKSPACE_MODE`

Example fix

// before
export GROK_CHAT_LOCAL_WORKSPACE_MODE=Own
// after
export GROK_CHAT_LOCAL_WORKSPACE_MODE=own
Defensive patterns

Strategy: validation

Validate before calling

fn valid_ws_mode() -> Result<(), String> {
    match std::env::var("GROK_CHAT_LOCAL_WORKSPACE_MODE") {
        Ok(m) if matches!(m.trim(), "own" | "attach") => Ok(()),
        Ok(m) => Err(format!("invalid GROK_CHAT_LOCAL_WORKSPACE_MODE={m:?}; expected own|attach")),
        Err(_) => Ok(()),
    }
}

Type guard

fn is_valid_mode(m: &str) -> bool { matches!(m, "own" | "attach") }

Try / catch

match resolve_local_workspace_config(chat, own, attach, cwd) {
    Err(e) if e.to_string().contains("expected own|attach") => {
        eprintln!("fix GROK_CHAT_LOCAL_WORKSPACE_MODE to 'own' or 'attach': {e}")
    }
    other => other?,
}

Prevention

When it happens

Trigger: Setting GROK_CHAT_LOCAL_WORKSPACE_MODE to a typo, different casing (e.g. `Own`, `ATTACH`), or an unsupported value like `shared` while any local-workspace request is active.

Common situations: Copy-pasted config from docs of another tool; shell profile exports with wrong casing; YAML/JSON values pasted with surrounding characters.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/a7de0799bc1f20cf. Report an issue: GitHub.