Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
ci: let a green pull request join the merge queue by itself (#539)
Ruben Lütke76b28c6da885
diff --git a/docs/ci-pipeline.md b/docs/ci-pipeline.mdindex e21400fba7..be19df3277 100644--- a/docs/ci-pipeline.md+++ b/docs/ci-pipeline.md@@ -215,6 +215,14 @@ an entry `GITHUB_TOKEN` added (the entry would wait until the queue'stimeout). With no queue on main it merges directly. The merge queue's ownmerges fire the normal push to main.+**Without the app: auto-merge.** A green pull request the train cannot+enqueue would wait for a person. The repository therefore allows GitHub's+auto-merge, and `scripts/agent_land.py` requests it with the agent's own+login (`gh pr merge <branch> --auto --squash`): once `CI gate` is green,+GitHub adds the pull request to the merge queue itself and the `merge_group`+run starts normally. A pull request opened another way gets the same with+that one command. Drafts and the opt-out labels are left alone.+**Rollback.** If the queue stalls, disable the "main merge queue" ruleset(Settings → Rules → Rulesets, or `gh api -X PUTrepos/<owner>/<repo>/rulesets/<id> -f enforcement=disabled`). The train sees@@ -230,8 +238,9 @@ python scripts/agent_land.py --direct # fast-forward main itself```It rebases onto the latest main with the same conflict engine, runs the-static gates, runs the tests the diff can reach, and pushes. It refuses a-dirty worktree and never stashes or force-pushes.+static gates, runs the tests the diff can reach, pushes, and asks GitHub to+queue the pull request once it is green. It refuses a dirty worktree and+never stashes or force-pushes.## 3. Releases, installers and updatesdiff --git a/scripts/agent_land.py b/scripts/agent_land.pyindex 6621781c12..3349829c2a 100644--- a/scripts/agent_land.py+++ b/scripts/agent_land.py@@ -17,8 +17,9 @@ What it does, in order — and it stops at the first real problem:3. **Relevant tests** — ``scripts/ci/select_tests.py`` picks the test filesthe diff can affect and ``scripts/ci/run_tests_parallel.py`` runs them inisolated processes. The full suite runs in CI.-4. **Push** — a feature branch gets a pull request labelled ``auto-merge``;- the merge train keeps it current and lands it once the CI gate is green.+4. **Push** — a feature branch gets a pull request labelled ``auto-merge``+ with GitHub's auto-merge requested: once the CI gate is green GitHub adds+ it to the merge queue by itself. The merge train keeps it current.It never stashes, never force-pushes, and refuses a dirty worktree: the maincheckout is shared with other sessions, so this belongs in your own worktree.@@ -27,6 +28,7 @@ checkout is shared with other sessions, so this belongs in your own worktree.from __future__ import annotationsimport argparse+import jsonimport osimport subprocessimport sys@@ -59,6 +61,40 @@ def step(title: str) -> None:print(f"\n== {title}", flush=True)+def wants_queue(pull_request: dict) -> bool:+ """Whether a pull request may be queued on green: open for merging and not opted out."""+ labels = {str(label.get("name", "")) for label in pull_request.get("labels") or []}+ return not pull_request.get("isDraft") and not labels & agent_integrate.OPT_OUT_LABELS+++def queue_when_green(branch: str, runner=run) -> bool:+ """Ask GitHub to add the pull request to the merge queue once its checks pass.++ The merge train enqueues only with its bot token; without one a green pull+ request waits until a person adds it by hand. Auto-merge is requested with+ the agent's own login, so the queue's ``merge_group`` run starts normally.+ Never blocking: a refusal leaves the pull request to the train.+ """+ view = runner(["gh", "pr", "view", branch, "--json", "number,isDraft,labels"])+ try:+ pull_request = json.loads(view.stdout or "null") if view.returncode == 0 else None+ except ValueError:+ pull_request = None+ if not isinstance(pull_request, dict):+ print("Could not read the pull request; the merge train lands it when green.")+ return False+ if not wants_queue(pull_request):+ print("Draft or opted out: not asking GitHub to queue it.")+ return False+ asked = runner(["gh", "pr", "merge", branch, "--auto", "--squash"])+ if asked.returncode != 0:+ print("GitHub did not accept auto-merge; the merge train lands it when green.")+ print((asked.stdout + asked.stderr).strip())+ return False+ print(f"PR #{pull_request.get('number')} joins the merge queue by itself once CI is green.")+ return True++def main(argv: list[str] | None = None) -> int:parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])parser.add_argument("--remote", default="origin")@@ -176,11 +212,15 @@ def main(argv: list[str] | None = None) -> int:return 6existing = run(["gh", "pr", "view", branch, "--json", "number", "-q", ".number"])if existing.returncode == 0 and existing.stdout.strip():- print(f"PR #{existing.stdout.strip()} updated; the merge train lands it when green.")+ print(f"PR #{existing.stdout.strip()} updated.")+ queue_when_green(branch)return 0created = run(["gh", "pr", "create", "--fill", "--base", "main", "--label", "auto-merge"])print(created.stdout + created.stderr)- return 0 if created.returncode == 0 else 7+ if created.returncode != 0:+ return 7+ queue_when_green(branch)+ return 0if __name__ == "__main__":diff --git a/tests/unit/ci/test_agent_land.py b/tests/unit/ci/test_agent_land.pynew file mode 100644index 0000000000..55fbb7107b--- /dev/null+++ b/tests/unit/ci/test_agent_land.py@@ -0,0 +1,48 @@+"""`scripts/agent_land.py` asks GitHub to queue a green pull request."""++from __future__ import annotations++import json+import subprocess++from scripts import agent_land+++class FakeGh:+ """Records every command and answers `gh pr view` / `gh pr merge`."""++ def __init__(self, view: dict | None, *, view_code: int = 0, merge_code: int = 0) -> None:+ self.view, self.view_code, self.merge_code = view, view_code, merge_code+ self.commands: list[list[str]] = []++ def __call__(self, cmd: list[str], **_: object) -> subprocess.CompletedProcess[str]:+ self.commands.append(cmd)+ if cmd[:3] == ["gh", "pr", "view"]:+ return subprocess.CompletedProcess(cmd, self.view_code, json.dumps(self.view), "")+ return subprocess.CompletedProcess(cmd, self.merge_code, "", "refused")+++def test_a_ready_pull_request_is_queued_on_green_with_the_agents_own_login():+ gh = FakeGh({"number": 7, "isDraft": False, "labels": [{"name": "auto-merge"}]})+ assert agent_land.queue_when_green("claude/x", gh) is True+ assert gh.commands[-1] == ["gh", "pr", "merge", "claude/x", "--auto", "--squash"]+++def test_a_draft_or_an_opted_out_pull_request_is_never_queued():+ for view in (+ {"number": 7, "isDraft": True, "labels": []},+ {"number": 7, "isDraft": False, "labels": [{"name": "no-auto-merge"}]},+ {"number": 7, "isDraft": False, "labels": [{"name": "needs-human"}]},+ {"number": 7, "isDraft": False, "labels": [{"name": "wip"}]},+ ):+ gh = FakeGh(view)+ assert agent_land.queue_when_green("claude/x", gh) is False+ assert all(cmd[:3] != ["gh", "pr", "merge"] for cmd in gh.commands), view+++def test_a_refusal_or_an_unreadable_pull_request_never_fails_the_landing():+ refused = FakeGh({"number": 7, "isDraft": False, "labels": []}, merge_code=1)+ assert agent_land.queue_when_green("claude/x", refused) is False+ unreadable = FakeGh(None, view_code=1)+ assert agent_land.queue_when_green("claude/x", unreadable) is False+ assert len(unreadable.commands) == 1