{"record":{"id":"c6f782c1f2b4ad85","repo":"can1357/oh-my-pi","slug":"gitcommanderror-git-checkout-detach-failed-non","errorCode":null,"errorMessage":"GitCommandError: git checkout --detach failed (nonzero exit)","messagePattern":"GitCommandError: git checkout --detach failed \\(nonzero exit\\)","errorType":"exception","errorClass":"GitCommandError","httpStatus":null,"severity":"error","filePath":"python/robomp/src/sandbox.py","lineNumber":1056,"sourceCode":"            pool = self.ensure_clone(\n                repo=repo,\n                clone_url=clone_url,\n                default_branch=default_branch,\n                refresh=False,\n            )\n            self.transport.fetch_pool(repo=repo, pool_dir=pool)\n            ws_root = self.workspace_root(repo, \"release\")\n            repo_dir = ws_root / \"repo\"\n            session_dir = ws_root / f\".omp-session-{tag}\"\n            context_dir = ws_root / \"context\"\n            artifacts_dir = ws_root / \"artifacts\"\n            for path in (ws_root, session_dir, context_dir, context_dir / \"repro\", artifacts_dir):\n                path.mkdir(parents=True, exist_ok=True)\n\n            detach = [\"git\", \"checkout\", \"--detach\"]\n            detached = _safe_run(detach, cwd=pool)\n            if detached.returncode != 0:\n                raise GitCommandError(detach, detached.returncode, detached.stdout, detached.stderr)\n\n            if not (repo_dir / \".git\").exists():\n                _worktree_add(\n                    [\n                        \"git\",\n                        \"worktree\",\n                        \"add\",\n                        \"-B\",\n                        default_branch,\n                        str(repo_dir),\n                        f\"origin/{default_branch}\",\n                    ],\n                    pool=pool,\n                    repo_dir=repo_dir,\n                )\n\n            _share_git_metadata_with_slots(repo_dir, slot_uid)\n            _provision_runtime_dirs(ws_root)","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/python/robomp/src/sandbox.py#L1038-L1074","documentation":"ensure_release_workspace() runs `git checkout --detach` in the shared clone pool so the release worktree can be cut from the default-branch commit. A nonzero exit raises GitCommandError, aborting release workspace setup before `git worktree add` runs.","triggerScenarios":"Calling ensure_release_workspace() when the pool clone has no commits (empty upstream repo), is mid-rebase/merge with conflicts, has a locked index, or `git checkout --detach` hits a corrupt object database.","commonSituations":"First release event for a repo whose clone pool was seeded from an empty or unreachable remote; concurrent process holding the pool's index.lock; corrupted clone after a container kill.","solutions":["Inspect GitCommandError.stderr — 'index.lock exists' means remove the stale lock, 'invalid object' means the pool clone is corrupt.","Delete the affected pool clone (under /data) and let the retry re-clone from the remote.","Verify the upstream repo actually has a default branch with commits.","If caused by concurrency, avoid running a second orchestrator against the same /data volume."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"proc = subprocess.run(['git', 'rev-parse', 'HEAD'], cwd=pool, capture_output=True)\nif proc.returncode != 0:\n    raise RuntimeError(f'pool clone unusable: {proc.stderr.decode()}')","typeGuard":"from robomp.sandbox import GitCommandError\n\ndef has_returncode(exc: BaseException, code: int) -> bool:\n    return isinstance(exc, GitCommandError) and exc.returncode == code","tryCatchPattern":"try:\n    ws = manager.ensure_release_workspace(repo=repo, tag=tag)\nexcept GitCommandError as e:\n    if e.returncode == 124:\n        ...  # timeout: check for hung git / locks before retrying\n    else:\n        ...  # re-clone pool and retry once","preventionTips":["Never run two orchestrators against the same /data volume","Verify upstream repos have a non-empty default branch before enabling releases","Watch for stale index.lock files after container crashes"],"tags":["git","worktree","release","subprocess"],"backgroundTag":"git-command-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}