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: give the merge train a merge bot app token and never enqueue as GITHUB_TOKEN (#487)
Ruben Lütke09cb8e96c3be
diff --git a/.github/workflows/merge-train.yml b/.github/workflows/merge-train.ymlindex 5332eaf1e1..5949d676c1 100644--- a/.github/workflows/merge-train.yml+++ b/.github/workflows/merge-train.yml@@ -35,12 +35,17 @@# excluded), so a pushed update is no more trusted than their own push: CI# and the merge queue test it before anything lands.#-# Tokens: with the optional INTEGRATION_TOKEN secret (a fine-grained PAT or App-# token with contents + pull-requests write), pushes fire the normal-# pull_request events. Without it the train uses GITHUB_TOKEN: the-# pull_request run its own push triggers parks in "action_required" and the-# train approves it on the next tick (a dispatched run would never count for-# the pull request).+# Tokens: the `apply` job runs in the `merge-train` environment (deployable+# from main only) and mints a short-lived installation token of the+# "PersonalJarvis Merge Bot" GitHub App (variable MERGE_APP_ID, environment+# secret MERGE_APP_PRIVATE_KEY; contents, pull requests, workflows and actions+# write; no ruleset bypass). Its pushes and enqueues fire the normal events,+# so the queue's merge_group runs start, and it may push merges that carry+# main's .github/workflows changes. Without the app the train falls back to+# GITHUB_TOKEN: its pull_request runs park in "action_required" and the train+# approves them on the next tick, and it does NOT enqueue, because GitHub+# starts no merge_group run for an entry GITHUB_TOKEN added - the entry would+# sit until the queue's timeout. With no queue on main it merges directly.## AI conflict resolution is optional: set ANTHROPIC_API_KEY (Claude Code) or# OPENAI_API_KEY (Codex CLI). Without a key, semantic conflicts are reported.@@ -183,15 +188,27 @@ jobs:if: ${{ !cancelled() && needs.plan.result == 'success' }}runs-on: ubuntu-latesttimeout-minutes: 20+ environment: merge-trainpermissions:contents: writepull-requests: writeactions: writeenv:- GH_TOKEN: ${{ secrets.INTEGRATION_TOKEN || github.token }}- TOKEN_IS_BOT: ${{ secrets.INTEGRATION_TOKEN == '' }}DRY_RUN: ${{ inputs.dry_run }}steps:+ # The only credential that can write. Minted here, after nothing from a+ # pull request ever ran on this machine, and revoked when the job ends.+ - name: Mint a merge bot token+ id: bot+ if: vars.MERGE_APP_ID != ''+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0+ with:+ client-id: ${{ vars.MERGE_APP_ID }}+ private-key: ${{ secrets.MERGE_APP_PRIVATE_KEY }}+ permission-contents: write+ permission-pull-requests: write+ permission-workflows: write+ permission-actions: write# The write token is never persisted into .git; `gh auth setup-git`# hands it to git only for this step's pushes. Nothing from a pull# request executes in this job: bundles are fetched as data.@@ -213,6 +230,9 @@ jobs:name: merge-train-updatespath: ${{ runner.temp }}/train- name: Run the train+ env:+ GH_TOKEN: ${{ steps.bot.outputs.token || github.token }}+ TOKEN_IS_BOT: ${{ steps.bot.outputs.token == '' }}run: |gh auth setup-gitargs=(--dir "$RUNNER_TEMP/train")diff --git a/docs/ci-pipeline.md b/docs/ci-pipeline.mdindex a5b65e5e81..8c94ce7fe5 100644--- a/docs/ci-pipeline.md+++ b/docs/ci-pipeline.md@@ -165,12 +165,18 @@ pull-request code, and only pushes bundles that build on the planned head andmain, labels, comments, approves parked runs and enqueues. No checkoutpersists a token.-**Token.** With the optional `INTEGRATION_TOKEN` secret (a fine-grained token-with contents and pull-request write access), the train's pushes fire the-normal events. Without it the train uses `GITHUB_TOKEN`: the pull-request run-its own push triggers waits in "action required" and the train approves it-on the next tick, because GitHub never counts a dispatched run for a pull-request. The merge queue's own merges fire the normal push to main.+**Token.** The `apply` job runs in the `merge-train` environment (deployable+from main only) and mints a short-lived token of the "PersonalJarvis Merge+Bot" GitHub App (variable `MERGE_APP_ID`, environment secret+`MERGE_APP_PRIVATE_KEY`; contents, pull requests, workflows and actions+write; no ruleset bypass). Its pushes and enqueues fire the normal events, and+it may push merges that carry main's `.github/workflows` changes. Without the+app the train falls back to `GITHUB_TOKEN`: the pull-request run its own push+triggers waits in "action required" and the train approves it on the next+tick, and it does not enqueue, because GitHub starts no `merge_group` run for+an entry `GITHUB_TOKEN` added (the entry would wait until the queue's+timeout). With no queue on main it merges directly. The merge queue's own+merges fire the normal push to main.**Rollback.** If the queue stalls, disable the "main merge queue" ruleset(Settings → Rules → Rulesets, or `gh api -X PUTdiff --git a/scripts/ci/agent_integrate.py b/scripts/ci/agent_integrate.pyindex 5d67d5ba6f..c6e277c6f5 100644--- a/scripts/ci/agent_integrate.py+++ b/scripts/ci/agent_integrate.py@@ -874,8 +874,8 @@ _WORKFLOWS_BODY = ("The merge train merged `main` into this branch, but could not push the result: ""`main` changed files under `.github/workflows/`, and the train's `GITHUB_TOKEN` ""may not push workflow changes. Merge `main` into this branch yourself (for example "- "`python scripts/agent_land.py --pr`), or give the repository an `INTEGRATION_TOKEN` "- "secret with workflow write access."+ "`python scripts/agent_land.py --pr`), or configure the merge bot app "+ "(`MERGE_APP_ID`), whose token may push workflow changes.")@@ -977,6 +977,13 @@ def apply(root: Path, data: dict, dry_run: bool, token_is_bot: bool) -> int:except (subprocess.CalledProcessError, OSError) as exc:outcome = f"update push crashed ({type(exc).__name__}); left for the next tick"summary.append(f"#{number}: {outcome}")+ elif action == "merge" and data.get("queue") and token_is_bot:+ # GitHub starts no merge_group run for an entry GITHUB_TOKEN added:+ # it would wait in the queue until the timeout and block the rest.+ summary.append(+ f"#{number}: green, not enqueued - the merge queue needs the merge bot "+ "token (MERGE_APP_ID); add it to the queue by hand meanwhile"+ )elif action == "merge" and data.get("queue"):if dry_run:summary.append(f"#{number}: would join the merge queue")@@ -1013,7 +1020,7 @@ def apply(root: Path, data: dict, dry_run: bool, token_is_bot: bool) -> int:else:summary.append(f"#{number}: could not {action} CI run {run_id} - approve it in the "- "Actions tab or set the INTEGRATION_TOKEN secret"+ "Actions tab or configure the merge bot app (MERGE_APP_ID)")elif action == "queued":summary.append(f"#{number}: in the merge queue")diff --git a/tests/unit/ci/test_pipeline_scripts.py b/tests/unit/ci/test_pipeline_scripts.pyindex e482b6bd25..f969396863 100644--- a/tests/unit/ci/test_pipeline_scripts.py+++ b/tests/unit/ci/test_pipeline_scripts.py@@ -729,13 +729,28 @@ def test_apply_enqueues_green_pull_requests_and_reports_the_rest(tmp_path, monke{"number": 4, "branch": "claude/d", "head": "d" * 40, "id": "PR_d", "action": "held"},],}- assert agent_integrate.apply(tmp_path, plan, False, True) == 0+ assert agent_integrate.apply(tmp_path, plan, False, False) == 0 # merge bot tokenenqueued = [c for c in fake.calls if c[:2] == ("api", "graphql")]assert len(enqueued) == 2 # a queue takes every green PR, not one per tickassert "head=" + "a" * 40 in enqueued[0] and "id=PR_a" in enqueued[0]assert not any(c[:2] == ("pr", "merge") or c[:2] == ("workflow", "run") for c in fake.calls)+def test_github_token_never_enqueues_because_the_queue_would_stall(tmp_path, monkeypatch):+ fake = _FakeGh()+ monkeypatch.setattr(agent_integrate, "gh", fake)+ plan = {+ "repo": "example/project",+ "main": "m" * 40,+ "queue": True,+ "entries": [+ {"number": 1, "branch": "claude/a", "head": "a" * 40, "id": "PR_a", "action": "merge"}+ ],+ }+ assert agent_integrate.apply(tmp_path, plan, False, True) == 0+ assert not fake.calls # no enqueue, no direct merge past the queue++def test_apply_reruns_only_the_failed_jobs_of_a_cancelled_run(tmp_path, monkeypatch):fake = _FakeGh()monkeypatch.setattr(agent_integrate, "gh", fake)