xai-org/grok-build · error · anyhow::Error
ls-remote origin '{session_branch}' failed (exit {other}); n
Error message
ls-remote origin '{session_branch}' failed (exit {other}); not treating as missing: {} What it means
Before deciding a session branch is missing from origin, the code runs `git ls-remote origin <branch>` and only exit codes 0 (exists) and 2 (missing) are accepted; any other exit status bails with the scrubbed output, deliberately NOT treating the branch as missing to avoid destructive false negatives.
Source
Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:3180
if local_exists {
checkout_branch(git_root, session_branch, false).await?;
} else {
let (ls_code, ls_out) = git_cli_status(
git_root,
&[
"ls-remote",
"--exit-code",
"--heads",
"origin",
session_branch,
],
)
.await?;
let remote_exists = match ls_code {
0 => true,
2 => false,
other => {
anyhow::bail!(
"ls-remote origin '{session_branch}' failed (exit {other}); not treating as missing: {}",
scrub_git_output(&ls_out)
);
}
};
if remote_exists {
let refspec =
format!("+refs/heads/{session_branch}:refs/remotes/origin/{session_branch}");
git_cli(git_root, &["fetch", "origin", "--end-of-options", &refspec]).await?;
git_cli(
git_root,
&[
"checkout",
"-b",
session_branch,
"--track",
&format!("origin/{session_branch}"),
],View on GitHub (pinned to bc7f02eddd)
Solutions
- Run `git ls-remote origin <branch>` manually and fix the reported auth/network error
- Fix the origin remote URL (`git remote set-url origin ...`)
- Renew credentials (ssh-agent, PAT) and retry
- Check proxy/firewall settings if behind a corporate network
Example fix
// before let url = "git@oldhost:team/repo.git"; // host retired, exit 128 // after git remote set-url origin git@newhost:team/repo.git # ls-remote now exits 0/2
Defensive patterns
Strategy: validation
Validate before calling
let out = std::process::Command::new("git").args(["ls-remote","--exit-code","origin",branch]).output()?;
if !(out.status.code() == Some(0) || out.status.code() == Some(2)) {
anyhow::bail!("ls-remote unhealthy (exit {:?}): {}", out.status.code(), String::from_utf8_lossy(&out.stderr));
} Type guard
fn ls_remote_healthy(code: Option<i32>) -> bool { matches!(code, Some(0) | Some(2)) } Try / catch
match check_remote_branch(git_root, branch).await {
Err(e) if e.to_string().contains("ls-remote origin") => {
// auth/network problem surfaced in scrubbed output: fix creds/remote, retry
return Err(e.context("origin unreachable while checking session branch"));
}
other => other,
} Prevention
- Validate origin URL and credentials before publish flows
- Run a cheap ls-remote health check at session start
- Keep PATs/ssh keys fresh; fail fast with GIT_TERMINAL_PROMPT=0
- Treat unknown ls-remote exits as infra failures, never as 'branch missing'
When it happens
Trigger: ls-remote exits with a code other than 0/2 — network failure, authentication error, malformed remote URL, or DNS failure while checking whether the session branch exists on origin.
Common situations: Expired SSH key or token; origin URL wrong after repo migration; corporate proxy blocking git; offline machine running publish flows.
Related errors
- Failed to push tag: {stderr}
- git fetch --no-tags origin {spec} failed ({status}): {stderr
- {e} Not adding "{url}": it doesn't look like a reachable git
- targeted fetch task failed: {e}
- fetch of base ref '{base}' failed: {fetch_out}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/a98dbce59ba79552.
Report an issue: GitHub.