xai-org/grok-build · error · anyhow::Error
exactly one of worktreePath or idOrPath must be set, not bot
Error message
exactly one of worktreePath or idOrPath must be set, not both
What it means
remove_worktree requires the caller to identify the target worktree in exactly one way: either an explicit worktree_path or an id_or_path that gets resolved to a path. This error is thrown from an exclusivity check when both fields of RemoveWorktreeRequest are populated, because the request is ambiguous — the API refuses to guess which identifier is authoritative.
Source
Thrown at crates/codegen/xai-grok-workspace/src/worktree/mod.rs:1329
session_id: req.session_id.clone(),
worktree_path: absolute_path,
commit: report.commit,
source_git_root,
copied_changes: Some(copied_changes),
}
}
// ============================================================================
// Remove Worktree
// ============================================================================
pub async fn remove_worktree(
req: &RemoveWorktreeRequest,
copy_context: &BackgroundCopyContext,
) -> Result<RemoveWorktreeResponse> {
let resolved = match (&req.worktree_path, &req.id_or_path) {
(Some(_), Some(_)) => {
anyhow::bail!("exactly one of worktreePath or idOrPath must be set, not both")
}
(Some(path), None) => path.clone(),
(None, Some(id)) => match resolve_worktree_by_id_or_path(id)? {
Some(p) => p.display().to_string(),
None => anyhow::bail!("worktree not found: {id}"),
},
(None, None) => anyhow::bail!("either worktreePath or idOrPath must be set"),
};
let worktree_path = Path::new(&resolved);
tracing::info!(
target: WORKTREE_LOG,
path = %resolved,
force = req.force,
dry_run = req.dry_run,
"REMOVE_START: removing worktree"
);
View on GitHub (pinned to bc7f02eddd)
Solutions
- Set only one of worktree_path or id_or_path to Some and clear the other before calling remove_worktree
- If you already know the absolute path, drop id_or_path and use worktree_path directly
- If you only have an id or short path, drop worktree_path and let resolve_worktree_by_id_or_path resolve it
- Fix the caller/serializer to omit None/default fields so both never get populated together
Example fix
// before
let req = RemoveWorktreeRequest { worktree_path: Some(path.clone()), id_or_path: Some(id) };
// after
let req = RemoveWorktreeRequest { worktree_path: Some(path), id_or_path: None }; Defensive patterns
Strategy: validation
Validate before calling
fn validate_remove(req: &RemoveWorktreeRequest) -> Result<()> {
if req.worktree_path.is_some() && req.id_or_path.is_some() {
anyhow::bail!("set only one of worktree_path or id_or_path");
}
if req.worktree_path.is_none() && req.id_or_path.is_none() {
anyhow::bail!("worktree_path or id_or_path is required");
}
Ok(())
} Type guard
fn has_exactly_one_target(req: &RemoveWorktreeRequest) -> bool {
req.worktree_path.is_some() ^ req.id_or_path.is_some()
} Prevention
- Construct requests via a helper that takes an enum (Path(PathBuf) | Id(String)) instead of two Option fields
- Never blanket-serialize optional fields; use skip_serializing_if = "Option::is_none"
- Unit-test request builders to assert exactly one identifier is set
When it happens
Trigger: Calling remove_worktree (or the remove-worktree command backed by it) with a RemoveWorktreeRequest where both req.worktree_path = Some(...) and req.id_or_path = Some(...) are set. Typically caused by a client that fills all optional fields, or by a wrapper layer that adds id_or_path on top of an already path-based request.
Common situations: CLI tools or HTTP clients that serialize the whole request struct without omitting unset fields; scripts that copy an example setting both fields; a middle-layer that auto-injects id_or_path while the caller also passes a path.
Related errors
- either worktreePath or idOrPath must be set
- invalid deny glob {glob:?}: {e}
- hook JSON alias validation failed: {e}
- Invalid viewport height: {} (terminal height: {})
- invalid worktree id from dest: {worktree_id}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/493db6ed38d910a3.
Report an issue: GitHub.