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
fix(ci): merge train approves parked pull_request runs instead of dispatching
rubenluetke10-beepc97bd263f399
diff --git a/.github/workflows/merge-train.yml b/.github/workflows/merge-train.ymlindex ab69840975..381de12225 100644--- a/.github/workflows/merge-train.yml+++ b/.github/workflows/merge-train.yml@@ -19,9 +19,10 @@## Tokens: with the optional INTEGRATION_TOKEN secret (a fine-grained PAT or App# token with contents + pull-requests write), pushes and merges fire the normal-# pull_request / push events. Without it the train uses GITHUB_TOKEN, whose-# pushes fire no events, so it dispatches ci.yml itself for every branch it-# updates and for main after every merge.+# pull_request / push 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), and it dispatches ci.yml for main after every merge.## AI conflict resolution is optional: set ANTHROPIC_API_KEY (Claude Code) or# OPENAI_API_KEY (Codex CLI). Without a key, semantic conflicts are reported.diff --git a/docs/ci-pipeline.md b/docs/ci-pipeline.mdindex f11831a3ad..c1e097fb19 100644--- a/docs/ci-pipeline.md+++ b/docs/ci-pipeline.md@@ -46,7 +46,7 @@ produces one.### Concurrency-A pull request (or a branch run the merge train dispatched) keeps only its+A pull request keeps only itsnewest run. A run on main is never cancelled once it started; pushes to mainshare one queue slot, so a burst of pushes leaves one pending run that coversevery commit before it instead of a backlog behind the organisation's@@ -84,9 +84,10 @@ the train.**Token.** With the optional `INTEGRATION_TOKEN` secret (a fine-grained tokenwith contents and pull-request write access), the train's pushes and merges-fire the normal events. Without it the train uses `GITHUB_TOKEN`, whose pushes-fire no events, and dispatches `ci.yml` itself for each updated branch and for-main after each merge.+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. After each merge it dispatches `ci.yml` for main.### Locally: `scripts/agent_land.py`diff --git a/scripts/ci/agent_integrate.py b/scripts/ci/agent_integrate.pyindex 4dcc304235..bc26184beb 100644--- a/scripts/ci/agent_integrate.py+++ b/scripts/ci/agent_integrate.py@@ -411,31 +411,39 @@ def eligible(pr: dict) -> bool:_ACTIVE = {"queued", "in_progress", "waiting", "pending", "requested"}-# A pull_request run a bot push triggers waits for approval and never runs;-# it says nothing about the commit.-_NO_VERDICT = {"action_required", "skipped", "stale", "neutral"}-def run_state(runs: list[dict]) -> str:- """success | failure | pending | missing from the CI workflow runs of one commit.+def run_state(runs: list[dict]) -> tuple[str, int | None]:+ """(state, run id) for a pull request's head commit, from its ci.yml runs.++ Only ``pull_request`` runs count: GitHub attaches the `CI gate` check of a+ workflow_dispatch run to the commit but NOT to the pull request, so branch+ protection never sees it. A pull_request run triggered by the train's own+ GITHUB_TOKEN push parks in ``action_required``; the train approves it.Read from the workflow RUNS, not the `CI gate` check: the gate is the last- job, so while CI is still running it has no check yet — reading that as- "missing" re-dispatched CI and cancelled the run in flight, forever.+ job, so a running CI has no gate check yet.++ States: pending | success | failure | approve | rerun | missing."""- if any(r.get("status") in _ACTIVE for r in runs):- return "pending"- done = [r for r in runs if r.get("conclusion") not in _NO_VERDICT]- if not done:- return "missing"- latest = max(done, key=lambda r: r.get("created_at") or "")+ pr_runs = [r for r in runs if r.get("event") == "pull_request"]+ if any(r.get("status") in _ACTIVE for r in pr_runs):+ return "pending", None+ if not pr_runs:+ return "missing", None+ latest = max(pr_runs, key=lambda r: r.get("created_at") or "")conclusion = latest.get("conclusion")+ run_id = latest.get("id")if conclusion == "success":- return "success"- return "missing" if conclusion == "cancelled" else "failure"+ return "success", run_id+ if conclusion == "action_required":+ return "approve", run_id+ if conclusion in ("cancelled", "stale", "skipped", "neutral", None):+ return "rerun", run_id+ return "failure", run_id-def gate_state(repo: str, sha: str) -> str:+def gate_state(repo: str, sha: str) -> tuple[str, int | None]:data = gh_json("api", f"repos/{repo}/actions/workflows/ci.yml/runs?head_sha={sha}&per_page=50")runs = (data or {}).get("workflow_runs", []) if isinstance(data, dict) else []return run_state(runs)@@ -462,8 +470,8 @@ def decide(mergeable: str, state: str, behind: bool) -> str:return "wait" # GitHub is still computing mergeabilityif state == "success":return "merge"- if state == "missing":- return "dispatch"+ if state in ("approve", "rerun"):+ return stateif state == "failure" and behind:return "update"return "wait"@@ -496,7 +504,7 @@ def train(repo: str, max_updates: int, resolver_cmd: str, dry_run: bool, token_inumber, branch, sha = pr["number"], pr["headRefName"], pr["headRefOid"]git("fetch", "--quiet", "origin", "main", branch)behind = git("merge-base", "--is-ancestor", "origin/main", sha, check=False).returncode != 0- state = gate_state(repo, sha)+ state, run_id = gate_state(repo, sha)action = decide(pr.get("mergeable") or "", state, behind)if action == "merge" and merged:action = "wait" # one landing per tick; the next tick sees the new main@@ -528,10 +536,21 @@ def train(repo: str, max_updates: int, resolver_cmd: str, dry_run: bool, token_idispatch_ci("main") # a GITHUB_TOKEN merge fires no push eventelse:summary.append(f"#{number}: merge refused (protection or conflict)")- elif action == "dispatch":- summary.append(f"#{number}: no CI on {sha[:8]}, dispatching")- if not dry_run:- dispatch_ci(branch)+ elif action in ("approve", "rerun"):+ if dry_run:+ summary.append(f"#{number}: would {action} CI run {run_id}")+ continue+ if action == "approve":+ code = gh("api", "-X", "POST", f"repos/{repo}/actions/runs/{run_id}/approve")+ else:+ code = gh("run", "rerun", str(run_id), "--repo", repo)+ if code == 0:+ summary.append(f"#{number}: CI run {run_id} {action}d")+ else:+ summary.append(+ f"#{number}: could not {action} CI run {run_id} - approve it in the "+ "Actions tab or set the INTEGRATION_TOKEN secret"+ )else:summary.append(f"#{number}: waiting (CI {state}, {pr.get('mergeable') or 'unknown'})")lines = ["## Merge train", "", *[f"- {line}" for line in summary]]@@ -581,8 +600,8 @@ def update_pr(pr: dict, resolver_cmd: str, dry_run: bool, token_is_bot: bool) ->f"Merge train: conflicts in {listing} were resolved by the configured AI ""resolver. CI re-runs on the result before anything lands; please skim them.",)- if token_is_bot:- dispatch_ci(branch) # a GITHUB_TOKEN push fires no pull_request event+ # A GITHUB_TOKEN push parks the pull_request run in action_required; the+ # next tick approves it (a dispatched run would never reach the PR).return f"updated with main ({len(report.get('resolved', []))} conflicts auto-resolved)" # type: ignore[arg-type]diff --git a/tests/unit/ci/test_pipeline_scripts.py b/tests/unit/ci/test_pipeline_scripts.pyindex 23f15d9e8c..c889f494d9 100644--- a/tests/unit/ci/test_pipeline_scripts.py+++ b/tests/unit/ci/test_pipeline_scripts.py@@ -289,22 +289,38 @@ def test_train_eligibility():assert not agent_integrate.eligible({**base, "headRefName": "dependabot/pip/x"})-def test_train_reads_a_running_ci_as_pending_not_missing():- running = {"status": "in_progress", "conclusion": None, "created_at": "2"}- ignored = {"status": "completed", "conclusion": "action_required", "created_at": "3"}- assert agent_integrate.run_state([running, ignored]) == "pending"- assert agent_integrate.run_state([ignored]) == "missing"- assert agent_integrate.run_state([]) == "missing"+def _run(event, status, conclusion, created, run_id=1):+ return {+ "event": event,+ "status": status,+ "conclusion": conclusion,+ "created_at": created,+ "id": run_id,+ }-def test_train_uses_the_newest_verdict_and_redispatches_a_cancelled_run():- old = {"status": "completed", "conclusion": "failure", "created_at": "1"}- new = {"status": "completed", "conclusion": "success", "created_at": "2"}- cancelled = {"status": "completed", "conclusion": "cancelled", "created_at": "3"}- assert agent_integrate.run_state([old, new]) == "success"- assert agent_integrate.run_state([new, old]) == "success"- assert agent_integrate.run_state([old]) == "failure"- assert agent_integrate.run_state([old, new, cancelled]) == "missing"+def test_train_reads_a_running_ci_as_pending():+ runs = [_run("pull_request", "in_progress", None, "2")]+ assert agent_integrate.run_state(runs) == ("pending", None)+++def test_train_ignores_dispatch_runs_because_the_pr_never_sees_them():+ runs = [_run("workflow_dispatch", "completed", "success", "3")]+ assert agent_integrate.run_state(runs) == ("missing", None)+++def test_train_approves_a_parked_bot_run_and_reruns_a_cancelled_one():+ parked = _run("pull_request", "completed", "action_required", "4", 7)+ assert agent_integrate.run_state([parked]) == ("approve", 7)+ cancelled = _run("pull_request", "completed", "cancelled", "5", 8)+ assert agent_integrate.run_state([parked, cancelled]) == ("rerun", 8)+++def test_train_uses_the_newest_pull_request_verdict():+ old = _run("pull_request", "completed", "failure", "1", 1)+ new = _run("pull_request", "completed", "success", "2", 2)+ assert agent_integrate.run_state([new, old]) == ("success", 2)+ assert agent_integrate.run_state([old]) == ("failure", 1)def test_train_updates_only_conflicting_or_stale_red_branches():@@ -312,7 +328,9 @@ def test_train_updates_only_conflicting_or_stale_red_branches():assert decide("CONFLICTING", "success", True) == "update"assert decide("MERGEABLE", "success", True) == "merge" # behind main is fineassert decide("MERGEABLE", "pending", True) == "wait"- assert decide("MERGEABLE", "missing", False) == "dispatch"+ assert decide("MERGEABLE", "approve", False) == "approve"+ assert decide("MERGEABLE", "rerun", True) == "rerun"+ assert decide("MERGEABLE", "missing", False) == "wait"assert decide("MERGEABLE", "failure", True) == "update"assert decide("MERGEABLE", "failure", False) == "wait"assert decide("UNKNOWN", "success", False) == "wait"