can1357/oh-my-pi · error · ValueError
refusing to rename non-farm branch {workspace.branch!r}
Error message
refusing to rename non-farm branch {workspace.branch!r} What it means
rename_workspace_branch() only renames branches matching the workspace convention `farm/<8-hex>/<slug>`. Before running git it splits workspace.branch on '/' and refuses any branch that does not have exactly three segments with the literal prefix 'farm' and a non-empty hex part. This guard prevents mangling arbitrary branches (like 'main' or 'feature/x') that were not created by the sandbox worktree pool.
Source
Thrown at python/robomp/src/sandbox.py:189
(which updates the shared refs in the pool) and mutates
``workspace.branch`` in place.
Idempotent when the computed branch already matches ``workspace.branch``.
Raises ``ValueError`` for syntactically invalid slugs or for a
workspace whose branch isn't on the ``farm/<hex>/<slug>`` shape.
Raises ``GitCommandError`` if the underlying ``git`` invocation fails
(e.g. the target branch name is already taken).
When ``pr_number`` is provided (non-None), the rename is a no-op: an
open PR on origin still tracks ``workspace.branch``, and renaming it
locally would orphan the PR by leaving its head on a branch that no
longer receives pushes. The slug is still validated so callers see
the same input errors as the rename path.
"""
validate_branch_slug(new_slug)
parts = workspace.branch.split("/", 2)
if len(parts) != 3 or parts[0] != "farm" or not parts[1]:
raise ValueError(f"refusing to rename non-farm branch {workspace.branch!r}")
new_branch = f"farm/{parts[1]}/{new_slug}"
if new_branch == workspace.branch:
return new_branch
if pr_number is not None:
log.warning(
"rename_workspace_branch skipped: PR #%d already tracks %r; refusing to rename to %r",
pr_number,
workspace.branch,
new_branch,
)
return workspace.branch
proc = _safe_run(
["git", "branch", "-m", workspace.branch, new_branch],
cwd=workspace.repo_dir,
env=_git_env_for_repo(workspace.repo_dir),
**_slot_subprocess_kwargs(slot_uid),
)
if proc.returncode != 0:View on GitHub (pinned to 9690622007)
Solutions
- Only call rename_workspace_branch on issue workspaces created by ensure_workspace (branch always farm/<hex>/<slug>).
- Check the shape before calling: workspace.branch.count('/') == 2 and workspace.branch.startswith('farm/').
- For release/default-branch workspaces there is nothing to rename — skip the call.
- If a legacy workspace must be renamed, create a new ensure_workspace worktree on a proper farm branch instead of renaming in place.
Example fix
// before
new = rename_workspace_branch(release_ws, "hotfix") # ValueError: non-farm branch 'main'
// after
if release_ws.branch.startswith("farm/"):
new = rename_workspace_branch(release_ws, "hotfix")
else:
log.info("skip rename: %s is not a farm branch", release_ws.branch) Defensive patterns
Strategy: validation
Validate before calling
def is_farm_branch(branch: str) -> bool:
parts = branch.split("/", 2)
return len(parts) == 3 and parts[0] == "farm" and bool(parts[1])
if not is_farm_branch(workspace.branch):
log.info("skip rename: %s is not a farm branch", workspace.branch)
return Try / catch
try:
rename_workspace_branch(ws, slug)
except ValueError as e:
log.warning("rename refused: %s", e) # non-farm branch; skip Prevention
- Only rename workspaces produced by ensure_workspace, never release/default-branch workspaces.
- Check branch shape with a small predicate before calling.
- Treat ValueError from this API as 'not applicable' (skip), not a retryable failure.
When it happens
Trigger: Calling rename_workspace_branch(workspace, new_slug) when workspace.branch is 'main', 'master', a default-branch checkout (e.g. release workspaces on the default branch), a two-segment name like 'feature/x', or any branch not produced by ensure_workspace's farm/<hex>/<slug> scheme. It is also reachable when a caller hand-crafts a Workspace dataclass with a non-farm branch string.
Common situations: Attempting to rename the release workspace's branch (it checks out the default branch, not a farm branch); renaming a workspace created manually or by an older robomp version that predates the farm/<hex>/<slug> naming; test fixtures populating Workspace with plain branch names.
Related errors
- Cannot resolve revision: ${options.revision}
- Security scans require a Git repository: ${request.cwd}
- local branch ${localBranch} does not exist
- ref_diff preflight requires base_revision and head_revision
- invalid PR number: {pr_number!r}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/bad93ef55a5e4a28.
Report an issue: GitHub.