xai-org/grok-build · error
'{}' is not a valid revision: {}
Error message
'{}' is not a valid revision: {} What it means
For GitRef::Treeish, read_version_bytes resolves the refspec with git2's revparse_single. If the string is not a valid revision (unknown branch/tag/SHA or malformed syntax), this error is thrown. It validates the user- or session-supplied version identifier before any content is read.
Source
Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:768
};
diff_compare(repo, base_ref, head_ref, merge_base, opts)
}
}
fn read_version_bytes(repo: &Repository, path: &str, version: &str) -> Result<Vec<u8>> {
match GitRef::parse(version) {
GitRef::Workdir => {
let full_path = repo
.workdir()
.ok_or_else(|| anyhow::anyhow!("cannot read working files from bare repository"))?
.join(path);
std::fs::read(&full_path)
.map_err(|e| anyhow::anyhow!("failed to read '{}': {}", path, e))
}
GitRef::Index => read_blob_from_index(repo, path),
GitRef::Treeish(refspec) => {
let obj = repo
.revparse_single(&refspec)
.map_err(|e| anyhow::anyhow!("'{}' is not a valid revision: {}", refspec, e))?;
let commit = obj
.peel_to_commit()
.map_err(|e| anyhow::anyhow!("'{}' does not refer to a commit: {}", refspec, e))?;
let tree = commit.tree()?;
read_blob_from_tree(repo, &tree, path)
}
}
}
/// Binary files return empty content with is_binary=true.
fn read_version_content(repo: &Repository, path: &str, version: &str) -> Result<(String, bool)> {
let bytes = read_version_bytes(repo, path, version)?;
match String::from_utf8(bytes) {
Ok(text) => Ok((text, false)),
Err(_) => Ok((String::new(), true)),
}
}
fn read_version_text(repo: &Repository, path: &str, version: &str) -> Option<String> {
read_version_content(repo, path, version)View on GitHub (pinned to bc7f02eddd)
Solutions
- Validate the ref with `git rev-parse --verify <refspec>` before reading
- Use a full commit SHA instead of a branch name so history stays stable after branch deletion
- Check `git branch -a` / `git tag -l` for the correct name; fetch if the object is missing (`git fetch --all`)
- Handle the error by listing available versions instead of propagating a raw failure
Example fix
// before
let bytes = read_version_bytes(&repo, "src/main.rs", "feature-x")?; // branch deleted
// after
let bytes = match read_version_bytes(&repo, "src/main.rs", "feature-x") {
Ok(b) => b,
Err(e) if e.to_string().contains("is not a valid revision") => {
read_version_bytes(&repo, "src/main.rs", "HEAD")? // stable fallback
}
Err(e) => return Err(e),
}; Defensive patterns
Strategy: validation
Validate before calling
fn revision_exists(repo: &git2::Repository, refspec: &str) -> bool {
repo.revparse_single(refspec).is_ok()
}
if !revision_exists(&repo, version) {
anyhow::bail!("unknown revision: {}", version);
} Try / catch
match read_version_bytes(repo, path, version) {
Ok(b) => b,
Err(e) if e.to_string().contains("is not a valid revision") => {
read_version_bytes(repo, path, "HEAD")? // stable fallback
}
Err(e) => return Err(e),
} Prevention
- Persist full commit SHAs, not branch names, in version metadata
- Validate refspecs with `git rev-parse --verify` before storing them
- Fetch missing objects (`git fetch --all`) when external SHAs are referenced
When it happens
Trigger: Calling read_version_content with a treeish version string that does not resolve: deleted branch, typo'd SHA, nonexistent tag, or invalid syntax like an empty or dangling refspec.
Common situations: Session history referencing a branch that was later deleted, truncated SHAs that no longer resolve after garbage collection, tags removed on the remote, or versions stored with wrong format.
Related errors
- path '{}' not found in commit: {}
- '{}' does not refer to a commit: {}
- git reset --hard {} failed: {}
- git clean {} failed: {}
- git checkout {} failed: {}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/b7e7549a36d6d560.
Report an issue: GitHub.