{"record":{"id":"a98dbce59ba79552","repo":"xai-org/grok-build","slug":"ls-remote-origin-session-branch-failed-exit","errorCode":null,"errorMessage":"ls-remote origin '{session_branch}' failed (exit {other}); not treating as missing: {}","messagePattern":"ls-remote origin '(.+?)' failed \\(exit (.+?)\\); not treating as missing: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":3180,"sourceCode":"    if local_exists {\n        checkout_branch(git_root, session_branch, false).await?;\n    } else {\n        let (ls_code, ls_out) = git_cli_status(\n            git_root,\n            &[\n                \"ls-remote\",\n                \"--exit-code\",\n                \"--heads\",\n                \"origin\",\n                session_branch,\n            ],\n        )\n        .await?;\n        let remote_exists = match ls_code {\n            0 => true,\n            2 => false,\n            other => {\n                anyhow::bail!(\n                    \"ls-remote origin '{session_branch}' failed (exit {other}); not treating as missing: {}\",\n                    scrub_git_output(&ls_out)\n                );\n            }\n        };\n        if remote_exists {\n            let refspec =\n                format!(\"+refs/heads/{session_branch}:refs/remotes/origin/{session_branch}\");\n            git_cli(git_root, &[\"fetch\", \"origin\", \"--end-of-options\", &refspec]).await?;\n            git_cli(\n                git_root,\n                &[\n                    \"checkout\",\n                    \"-b\",\n                    session_branch,\n                    \"--track\",\n                    &format!(\"origin/{session_branch}\"),\n                ],","sourceCodeStart":3162,"sourceCodeEnd":3198,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L3162-L3198","documentation":"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.","triggerScenarios":"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.","commonSituations":"Expired SSH key or token; origin URL wrong after repo migration; corporate proxy blocking git; offline machine running publish flows.","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"],"exampleFix":"// before\nlet url = \"git@oldhost:team/repo.git\"; // host retired, exit 128\n// after\ngit remote set-url origin git@newhost:team/repo.git  # ls-remote now exits 0/2","handlingStrategy":"validation","validationCode":"let out = std::process::Command::new(\"git\").args([\"ls-remote\",\"--exit-code\",\"origin\",branch]).output()?;\nif !(out.status.code() == Some(0) || out.status.code() == Some(2)) {\n    anyhow::bail!(\"ls-remote unhealthy (exit {:?}): {}\", out.status.code(), String::from_utf8_lossy(&out.stderr));\n}","typeGuard":"fn ls_remote_healthy(code: Option<i32>) -> bool { matches!(code, Some(0) | Some(2)) }","tryCatchPattern":"match check_remote_branch(git_root, branch).await {\n    Err(e) if e.to_string().contains(\"ls-remote origin\") => {\n        // auth/network problem surfaced in scrubbed output: fix creds/remote, retry\n        return Err(e.context(\"origin unreachable while checking session branch\"));\n    }\n    other => other,\n}","preventionTips":["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'"],"tags":["git","ls-remote","network","authentication"],"backgroundTag":"git-ls-remote-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}