rose-merge-branch (CLI)¶
The rose-merge-branch CLI tool automates GitHub merge workflows with pre-flight checks and test validation. It supports two modes:
- Feature Mode: Squash merge feature branches to
develop - Release Mode: Merge commit from
developtomain(auto-detected)
Installation¶
The CLI tool is available after activating the Poetry shell in the backend directory:
Once in the Poetry shell, the rose-merge-branch command is available.
Usage¶
Options¶
| Option | Default | Description |
|---|---|---|
--skip-tests |
false |
Skip backend tests; also skips frontend tests in release mode, but never the required local frontend gate for develop |
--full |
false |
Run every check, ignoring change detection |
--confirm |
false |
Ask before a history-rewriting rebase and before merging |
--no-watch |
false |
Release mode only: merge without following the deployment workflows on GitHub |
--no-ci-wait |
false |
Also run backend lint locally, then merge without waiting for GitHub checks; frontend validation is always local |
--dry-run |
false |
Show what would happen without executing |
--run-checks AREA |
— | Only run one merge gate on HEAD (backend, frontend or github), then stop; refuses --dry-run and --full (merge checklist) |
Examples¶
# Standard merge to develop with all checks (squash merge)
rose-merge-branch
# Skip backend tests (the develop frontend gate still runs)
rose-merge-branch --skip-tests
# Preview what would happen
rose-merge-branch --dry-run
# Force every check even if the diff does not warrant it
rose-merge-branch --full
# Ask before rebasing and before merging
rose-merge-branch --confirm
# Also run backend lint locally and merge without waiting for GitHub checks
rose-merge-branch --no-ci-wait
Release Mode Examples¶
# Checkout develop branch
git checkout develop
# Preview release merge (develop → main)
rose-merge-branch --dry-run
# Execute release merge, then follow the deploy workflows until they finish
rose-merge-branch
# Execute release merge and return immediately
rose-merge-branch --no-watch
Merge Modes¶
Behavior Matrix¶
| Current Branch | Target | Merge Type | PR Handling |
|---|---|---|---|
| Feature branch | develop |
Squash merge | Must exist |
develop |
main |
Merge commit | Auto-created if missing |
Feature Mode (Default)¶
When running from a feature branch:
- Target:
develop(deterministic) - Merge Type: Squash merge (combines all commits into one)
- PR: Auto-created from the branch commits (
gh pr create --fill) if it doesn't exist
Release Mode (Auto-detected)¶
When running from the develop branch:
- Target:
main(deterministic) - Merge Type: Merge commit (preserves commit history)
- PR: Auto-created if it doesn't exist
This mode is designed for releasing develop to main while preserving the full commit history.
Workflow Steps¶
The command executes 9 automated steps:
Step 1: Pre-flight Checks¶
- Verifies working directory is clean (no uncommitted changes)
- Validates current branch is not the target branch or main/master
- Fetches latest changes from origin
- Pushes any unpushed local commits
- Replays the branch on the target branch when it is behind:
- lists the incoming commits so you can see what changed
- fast-forwards silently when the branch has no commits of its own
- rebases and pushes with
--force-with-lease(asks first with--confirm) - aborts the rebase and stops on conflict, leaving the working tree untouched
- retries up to twice when another git process holds the index lock
- Runs
just target shared --yes, so the tests and evals run in remote mode and no preview namespace or corpus outlives the merge: it purges a preview corpus, unwires the branch or stops local Supabase, and removes the.rose-targetmarker. A failure stops the merge.
Step 2: PR Verification/Creation¶
Feature Mode:
- Checks if a Pull Request exists for the current branch
- Auto-creates it with
gh pr create --fillif missing, so the title and body come from the branch commits (the PR title becomes the squash commit subject) - Displays PR number, title, and URL
Release Mode:
- Checks if a PR exists for
develop → main - Auto-creates the PR titled
Release: develop → mainif it doesn't exist - Displays PR number, title, and URL
Step 3: Mergeability Check¶
- Checks GitHub PR mergeability status
- Handles UNKNOWN status with retries (GitHub may take time to compute)
- Detects merge conflicts, blocked status, or behind-base-branch issues
Steps 4–6: what runs locally¶
For a feature PR targeting develop, frontend validation and backend tests run on
the machine executing rose-merge-branch, which publishes the required
frontend-checks and backend-unit-tests statuses. GitHub runs them only on a PR
labeled ci-tests (below).
The command installs the locked frontend dependencies, builds shared components,
runs Biome on changed files, checks frontend types, runs the affected Vitest
projects, and runs the frontend tooling regression tests. Shared/config changes
run every Vitest project. Frontend tooling-only changes run their Python tests;
changes without frontend code or tooling need no frontend commands.
The CLI publishes the existing required frontend-checks commit status: pending
before validation, then success only when the working tree is clean and the local
commit still matches the PR head. Failed checks or a changed head stop the merge.
Publishing requires GitHub repository write access (a fine-grained token needs
commit-status write permission). The status trusts the repository writer running
the CLI; it is not a GitHub-hosted execution or independent attestation.
Merges on one machine take turns on the heavy local checks: the frontend and backend
test runs and the step 7 evaluations hold a lock on ~/.cache/rose/merge-checks.lock,
shared by every worktree. A merge that finds it held prints Waiting for another merge's
checks to finish (pid … in …) and runs once the other finishes. Lint, type checks, the
push and the wait on GitHub stay outside the lock. The lock is released when its holder
exits or is killed, even while the test processes it started still run, so a stale file
never blocks a merge. The pid in the waiting line is the holder when the merge started to
wait; a waiting merge runs as soon as it gets the lock. Never delete the file to unblock
one: a merge waits only while another merge runs, and deleting it would let two run at once.
--skip-tests and --skip-lint do not bypass this frontend gate for develop.
--full validates all frontend projects even without detected frontend changes.
The CLI publishes backend-unit-tests the same way around the backend tests
(step 6), or success when the diff has no backend Python changes.
--skip-tests publishes nothing for backend changes, so GitHub blocks the merge
unless CI reported the status. Backend ruff still runs in pr-checks-backend.yml;
evaluations remain local. The normal command continues waiting for GitHub validation,
including backend, Supabase and security checks. --no-ci-wait additionally runs
backend lint locally and explicitly skips that wait.
Control Room merge checklist¶
control-room.json at the repository root declares the merge checklist Control Room
shows on each commit; its Merge runs the missing items first. It has one item, Ship:
bento-ship ran on HEAD through its PR to develop, shown by its ship record
(git rev-parse --git-path bento-ship.head) naming HEAD and by HEAD being the PR's
head. bento-ship owns the ticket, docs, QA, security and pre-PR review steps; this
command owns the tests, evaluations and GitHub checks, during the merge
(Ship and merge). The checklist repeats neither, so Control
Room no longer starts a test run of its own before the merge.
--run-checks AREA runs one of this command's gates on HEAD by hand, with no rebase,
PR creation or merge. It refuses a worktree with uncommitted or untracked files.
backendandfrontendrun the same test selection as steps 4–6. When HEAD is the head of the branch's PR todevelopon GitHub, they also reportbackend-unit-testsorfrontend-checksfor it; otherwise they only run the tests. Backend tests need the shared target: the command stops withjust target sharedto run when the worktree points at a preview branch or a local stack.githubwaits for the PR's checks on HEAD the way a merge does (required checks count until they register; push-triggered deployments do not). It first runs the backend or frontend gate for a required status GitHub has no result for yet, such as one whose tests passed before the PR existed. It fails until HEAD is pushed as a PR head.
Run the tests on GitHub instead¶
Add the ci-tests label to a PR built in the cloud, or that you will not merge with
this CLI. pr-checks-frontend.yml then runs the frontend validation and
pr-checks-backend-unit.yml runs the unit tests of the changed backend packages
(the pre-commit hook's selection), and each publishes its status for the PR head.
Every new push reruns them while the label stays. The Night Shift factory adds the
label to each PR it opens (pr_labels in .nightshift/defaults.toml), so GitHub
runs its checks and an auto-merge job can merge once they pass.
Release merges from develop to main keep their existing local checks and do
not publish the develop frontend status. The frontend deploy workflows (widget,
backoffice, Chrome plugin) do not rerun type checks or Vitest: this gate already ran them.
After this change lands, update existing workspaces before using the merge CLI.
The frontend-checks and backend-unit-tests required contexts accept statuses
from repository writers. Direct web merges need
a successful local status for the current head. A new commit or rebase needs a
fresh local validation. An old GitHub frontend check already attached to that
commit must also pass; the local status does not override a failing cloud check.
Rebase an old candidate onto the updated develop and rerun the CLI to use the
new workflow.
Step 4: Lint Checks¶
- For develop candidates, runs the required local frontend gate described above
- Runs
ruff checkandruff format --checklocally for releases or--no-ci-wait(skipped if no backend Python changes) - Runs
biome checkon changed frontend files (.ts,.tsx,.js,.jsx,.css, plus.mjsfor develop candidates); configured ignored files are allowed
Step 5: Type Checks¶
- Runs
just type-checkin thefrontend/directory (tsc across shared, widget, playground, client-backoffice) - Skipped if the branch only touches frontend markdown
Step 6: Test Execution¶
- Runs the vitest projects the diff can break, via
just test-projects <projects>infrontend/(a change underfrontend/shared/runs all of them, since every project aliasesshared/src) - Runs
just testin thebackend/directory when backend Python, dependency or test files changed, and for develop candidates reports the result asbackend-unit-testson the tested PR head - Narrows that to
just test --no-parallel apps/<app>/testswhen the diff is confined to a single leaf app (xdist takes longer to bring up its workers than one app's tests take to run) (BACKEND_LEAF_APPS, currently justcli) — nothing imports those, so nothing else can break. A package, a second app or a root config file in the diff runs the whole suite. - Both must pass for merge to proceed
The frontend runner cleans up only its own Vitest process group, including when
interrupted. Merge commands leave concurrent tests in other workspaces running.
An exit code of 143 means SIGTERM interrupted the run; inspect concurrent
commands or terminal cancellation when there is no assertion failure. The Vite
native-config __dirname warning does not fail the tests.
Step 7: E2E Evaluation¶
- Runs
rose-eval e2e main-dataset --sample-size 5 - Runs
rose-eval features run --sample-size 1 - An item that errors (no score) fails the step even when the mean passes. The output names
each errored item, its query and its exception (
metrics.error_messagesin--json). - Gated on
EVAL_PATH_PREFIXES(everything underbackend/apps/andbackend/packages/) minusEVAL_EXEMPT_PREFIXES. Test-only edits inside a covered path do not count, and root-level changes such aspoetry.lockskip the eval. - Runs
just e2einbackend/apps/r4a_mcpwhen the diff touchesR4A_PATH_PREFIXES(the Rose for Agents connector, therose_mcpplumbing it reuses, the Ibanly demo vendor). It checks every R4A tool against known hosts on the branch's own code, with the local connector, the Ibanly Worker and your gcloud credentials, which CI does not have. Those paths are exempt from the chat eval above.--skip-evalskips both.
Keeping the gate honest as the backend grows: the default is inclusive, so a package or app
added later runs the eval until someone deliberately adds it to EVAL_EXEMPT_PREFIXES. Forgetting
costs eval minutes, never a missed chat regression. Adding an exemption is the deliberate act, and
apps/cli/tests/unit/test_merge_branch_gates.py checks that every exemption still points at a real
directory inside a covered tree. The same file asserts FRONTEND_PROJECTS matches the projects
declared in frontend/vitest.config.ts, so a new vitest project fails the suite instead of
silently never running.
Step 8: Merge Execution¶
First polls the PR's GitHub validation checks and stops on any failing or cancelled
check, required or not. GitHub also attaches push-triggered Deploy ... runs on the
PR head commit; those deploy the test environment and are omitted from this gate.
PR-triggered validation jobs in deploy-named workflows remain in the gate.
The gate also reads the checks the target branch's rulesets require
(gh api repos/{owner}/{repo}/rules/branches/<target>) and counts each one as
pending until it registers: Supabase Preview on main can start after every other
check has passed. If the rules cannot be read, the gate follows the PR's checks only.
A PR with no validation checks and no required checks merges after a short
registration grace period.
Once checks register, polling stops after 15 minutes if any remain pending or
disappear. The command stops without merging and prints pending check names,
links, and a gh pr checks <PR> command for diagnosis. A successful test log with
a pending check can indicate stale GitHub status; inspect both the check and its
workflow before retrying. Each GitHub status read has a 30-second timeout and
repeated read failures stop the merge. The timeout does not turn pending checks
into passes.
--no-ci-wait skips the wait; GitHub still refuses the merge while a required check
is pending or failing. The final squash merge uses --match-head-commit to reject
a PR that changed after local validation or while waiting for GitHub checks.
A failed merge is retried up to 3 times, after 5, 10 and 20 seconds, so a GitHub error does not throw away a run whose gates passed. A permanent refusal takes the same retries before it stops the run. If GitHub reports an error but the PR is merged, the merge counts as a success.
Feature Mode:
- Prompts (only with
--confirm): "Proceed with squash merge to develop?" - Executes
gh pr merge --squash
Release Mode:
- Prompts (only with
--confirm): "Proceed with merge commit to main?" - Executes
gh pr merge --merge(preserves history)
Step 9: Deployment Watch (release mode only)¶
After the merge commit lands on main, the tool follows every GitHub workflow run
triggered by that commit (Release and its deploy fan-out, Rose Security Scan, ...)
and renders a live table: one row per workflow with a per-job tally, plus a detail row
for each job still running or already failed.
The Release workflow deploys to production. Earlier Deploy ... runs on develop
deploy to test and are separate runs for a different commit.
- Polls every 15s, gives up after 30 minutes
- Exits
1if any run ends infailure,cancelledortimed_out, printing the run URL Ctrl-Cstops watching without affecting the deployments (exit0— the merge landed)--no-watchskips the step entirely- Feature merges to
developnever watch
Exit Codes¶
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Error (failed checks, tests, merge, or a failed deployment) |
2 |
Cancelled by user |
Prerequisites¶
- GitHub CLI (
gh): Must be installed and authenticated - Poetry environment: Run
poetry shellin the backend directory - Clean working directory: Commit or stash changes before running
- Existing PR: Not required — auto-created in both feature and release mode
Ship and merge (agents)¶
When the operator tells an agent "ship and merge":
- Finish
bento-ship, including its ticket update. That skill never merges, so the merge stays a separate step. - Check that
backend/.env.testexists. It shows the worker has the credentials for the merge gates. If it is missing, stop after the PR and say the merge did not run. - Fetch the branch, then run
git cherry -v HEAD origin/<branch>andgit log --merges HEAD..origin/<branch>. If a remote-only commit has no local equivalent (a+line), or there is a merge, stop and ask: the command would overwrite it. - Run
rose-merge-branchfrom the feature branch, never fromdevelop: from there it releases tomain. - If a check fails, report it. Do not bypass it with
--skip-testsor--no-ci-wait.
The file check does not prove the values work. A missing gh login, or gcloud credentials on
an R4A change, fails at that gate rather than merging. Once step 3 passes, the operator's
request covers the command's rebase and --force-with-lease push. It fetches first, so the
lease alone does not protect a collaborator's commits.
Development Workflow Integration¶
This tool integrates with the Development Workflow:
Why Use This Tool?¶
- Consistency: Ensures all merges follow the same process
- Safety: Runs tests before merging to prevent breaking changes
- Automation: Handles pushing and PR creation
- Feedback: Clear step-by-step progress with colored output
- History Preservation: Release mode uses merge commits to preserve full history in main
Troubleshooting¶
"Working directory has uncommitted changes"¶
Commit or stash your changes:
"Rebase onto origin/develop hit a conflict"¶
The rebase was aborted, so your branch is exactly as it was. Resolve it by hand,
then re-run rose-merge-branch:
git rebase origin/develop
# fix the conflicts, then
git rebase --continue
git push --force-with-lease
"Rebase failed: another git process holds the index lock"¶
Another git process (in Control Room, often a tool reading git status) held the
worktree's index.lock through every retry. Nothing changed and nothing conflicts:
re-run rose-merge-branch once that process has finished.
"Failed to create PR"¶
The PR is auto-created in both modes, so this means gh pr create itself
failed (unauthenticated gh, no commits on the branch, protected base, etc.).
Create it manually to see the underlying error:
"PR has merge conflicts"¶
Resolve conflicts locally:
git fetch origin
git rebase origin/develop
# Resolve conflicts
git add .
git rebase --continue
git push --force-with-lease
"PR is blocked (check required status checks)" or "GitHub checks failed"¶
Run gh pr checks <number> and fix the failing check. If the same check also fails on
develop, fix develop first, then click Update branch on the PR: re-running the
check reuses the old base.
"A Release deploy job failed"¶
gh run view <run> --log-failed prints nothing until the whole run finishes. Read one
job's log while the rest still run (gh run view <run> --json jobs lists the job ids):
gh api --allow-escape-sequences repos/inboundx/inboundx/actions/jobs/<job-id>/logs > .context/job.log
A Cloud Run deploy that "failed the configured startup probe checks" crashed at boot. The job log names the revision; its traceback is in that revision's logs:
gcloud logging read 'resource.type="cloud_run_revision" AND resource.labels.revision_name="<revision>" AND severity>=ERROR' --freshness=2h --limit 30 --format='value(textPayload,jsonPayload.message)'
The previous revision keeps serving traffic, so production stays up until the fix ships.
If website-mapping fails inside _setup-website-scrape-snapshot-events, check
which admin-api image the failed revision used. In release run 40475960021,
event setup updated the admin service while its fixed image was still building,
booting the previous image with the already-fixed ixchat import crash. The
admin deployment later succeeded, but the earlier job failure kept Release red.
The admin deploy recipe now sets its expected Pub/Sub push identity together
with the new image. Shared event setup provisions Pub/Sub and IAM without
creating an admin revision, so website-mapping can deploy independently.
Changes to the shared event recipe trigger both deployments on release. If you
change the admin runtime service account manually, redeploy admin to update its
expected push identity; just job setup-events website-mapping <env> only
reconciles Pub/Sub and IAM.