Skip to content

fix(run): refuse an auto-detected branch that is not on the remote - #266

Merged
Rome-1 merged 1 commit into
mainfrom
mayor-agent/run-branch-on-remote
Oct 2, 2026
Merged

Rome-1 merged 1 commit into
mainfrom
mayor-agent/run-branch-on-remote

Conversation

@Rome-1

@Rome-1 Rome-1 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

rafter run scans the remote repository.
When it auto-detects the current local branch, it never checked that the branch had been pushed, so a scan of an unpushed branch was queued and then failed on the backend with branch-not-found.
This is common for coding agents that run rafter on a task branch before pushing it.

When both repo and branch come from the local checkout (origin remote + current HEAD), both CLIs now run git ls-remote --exit-code --heads origin refs/heads/<branch> (15 s timeout, no credential prompt):

  • remote answers and the branch is absent: exit 1 with "push the branch first, or pass --branch"
  • branch present but its commit differs from local HEAD: a one-line note that the scan covers the pushed commit
  • origin unreachable (offline, auth, timeout): proceed as before

An explicit --repo/--branch and CI-provided branches (GITHUB_REF_NAME, CI_COMMIT_BRANCH, CI_BRANCH) are unchanged.
Exit code 1 (general error) is used rather than 2, which the remote-command exit-code contract reserves for "scan not found".
CLI_SPEC documents the check.

Tests

  • node/tests/remote-branch.test.ts and python/tests/test_git_utils.py::test_remote_branch_sha_tells_unpushed_from_pushed_and_unreachable: real git against a local bare origin, checking pushed (SHA), unpushed (absent) and unreachable origin (unknown).
  • Three existing Python _do_remote_scan tests that mock an auto-detected repo now also stub the lookup so they stay off the network.

Manual check from an unpushed branch of this repo: the published 0.10.5 CLIs (Node and Python) submit the scan; this branch exits 1 with the message before any API call.
From a local branch whose name exists on the remote, the build notes the pushed commit and submits.

tsc clean. Python suite: 1754 passed, 1 skipped. Node suite: 2275 passed; the 3 Cursor hook tests that fail also fail on main in a local checkout and are unrelated.

`rafter run` scans the remote repository, but when it auto-detected the
current local branch it never checked that the branch had been pushed.
The scan was queued and then failed on the backend minutes later.

When both repo and branch come from the local checkout, ask origin with
`git ls-remote --exit-code --heads`. If the remote answers without the
branch, exit 1 with a message to push it or pass --branch. If origin
cannot be reached, proceed as before. If the pushed commit differs from
local HEAD, note that the scan covers the pushed commit. Explicit
--branch and CI-provided branches are unchanged.

Same behavior in the Node and Python CLIs, each with a test against a
real local bare remote.
@Rome-1
Rome-1 merged commit 48bf044 into main Oct 2, 2026
10 checks passed
@Rome-1
Rome-1 deleted the mayor-agent/run-branch-on-remote branch October 2, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant