{"record":{"id":"71de507652945a09","repo":"xai-org/grok-build","slug":"jj-workspace-add-failed-e","errorCode":null,"errorMessage":"jj workspace add failed: {e}","messagePattern":"jj workspace add failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/worktree/mod.rs","lineNumber":2437,"sourceCode":"\n    // Ensure parent directory exists: jj workspace add doesn't create it.\n    if let Some(parent) = Path::new(&dest).parent() {\n        tokio::fs::create_dir_all(parent).await?;\n    }\n\n    tracing::info!(\n        source = %req.source_worktree_path,\n        dest = %dest,\n        name = %name,\n        \"creating jj workspace\"\n    );\n\n    jj_cli_mut(\n        source_path,\n        &[\"workspace\", \"add\", &dest, \"--name\", &name, \"-r\", \"@\"],\n    )\n    .await\n    .map_err(|e| anyhow::anyhow!(\"jj workspace add failed: {e}\"))?;\n\n    let commit = jj_commit_id(Path::new(&dest)).await;\n    tracing::info!(dest = %dest, commit = ?commit, \"jj workspace created\");\n\n    Ok(CreateWorktreeFromWorktreeResponse {\n        status: \"created\".to_string(),\n        new_session_id: req.new_session_id.clone(),\n        worktree_path: dest,\n        commit,\n        copied_changes: None,\n        source_git_root,\n    })\n}\n\n/// Remove a jj workspace: forget + delete directory.\npub async fn remove_jj_workspace(workspace_path: &str) -> Result<()> {\n    let path = Path::new(workspace_path);\n    let name = path","sourceCodeStart":2419,"sourceCodeEnd":2455,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/worktree/mod.rs#L2419-L2455","documentation":"Wraps a failure of `jj workspace add` — the external Jujutsu VCS CLI invoked to create a new workspace at `dest` with the given name, tracking revision `@`. The command is run via jj_cli_mut; any non-zero exit, missing binary, or invalid argument is converted into this anyhow error. It indicates the jj workspace creation step of worktree creation failed before any commit id could be resolved.","triggerScenarios":"Calling create-worktree-from-worktree when the jj CLI exits non-zero: workspace name already exists, destination path already exists or is not a valid location, `-r @` cannot resolve (repo has no working-copy commit), or jj binary is absent/broken.","commonSituations":"Jujutsu not installed or not on PATH in CI images; leftover workspace directory from a previous failed run; trying to reuse a `--name` that already exists in the repo; running outside a jj-backed repository; corrupt or locked jj repo.","solutions":["Run the same `jj workspace add <dest> --name <name> -r @` command manually in source_path to see jj's stderr detail.","Ensure jj is installed and on PATH (`jj --version`) in the environment running the code.","Delete the stale destination directory or choose a fresh dest path/name.","Verify source_path is inside a valid jj repository and `@` resolves (`jj log`)."],"exampleFix":"// before\njj_cli_mut(source_path, &[\"workspace\", \"add\", &dest, \"--name\", &name, \"-r\", \"@\"])\n    .await\n    .map_err(|e| anyhow::anyhow!(\"jj workspace add failed: {e}\"))?;\n// after\nif Path::new(&dest).exists() {\n    anyhow::bail!(\"workspace destination {dest} already exists; remove it first\");\n}\njj_cli_mut(source_path, &[\"workspace\", \"add\", &dest, \"--name\", &name, \"-r\", \"@\"])\n    .await\n    .map_err(|e| anyhow::anyhow!(\"jj workspace add failed: {e}; ensure jj is installed and '{name}' is unused\"))?;","handlingStrategy":"try-catch","validationCode":"// before calling\nif !Path::new(&dest).exists() && which::which(\"jj\").is_ok() {\n    // ensure name is not already used\n    let listed = jj_cli_mut(source_path, &[\"workspace\", \"list\"]).await?;\n    if listed.contains(name) { anyhow::bail!(\"workspace name {name} already exists\"); }\n}","typeGuard":null,"tryCatchPattern":"match create_worktree_from_worktree(src, &dest, name).await {\n    Ok(resp) => resp,\n    Err(e) if e.to_string().contains(\"jj workspace add failed\") => {\n        eprintln!(\"jj unavailable or workspace conflict: {e:#}\");\n        // clean stale dest, then retry once\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Pin jj installation in CI images and assert `jj --version` at startup","Use unique workspace names/dest paths per run to avoid collisions","Clean up stale workspace directories after failed runs","Confirm source_path is a valid jj repository before invoking"],"tags":["vcs","jujutsu","cli","worktree"],"backgroundTag":"jj-workspace-add-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}