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's update slots to pull requests that can land (#557)
Ruben Lütke19d9f5a7d56d
diff --git a/.github/workflows/nightly-alert.yml b/.github/workflows/nightly-alert.ymlindex 15cdc2983d..f4cf90fe1d 100644--- a/.github/workflows/nightly-alert.yml+++ b/.github/workflows/nightly-alert.yml@@ -17,6 +17,18 @@ on:workflows: [CI]types: [completed]branches: [main]+ # A check by hand against a past nightly. It reports what it would do and+ # writes nothing unless `dry_run` is switched off.+ workflow_dispatch:+ inputs:+ run_id:+ description: "A finished nightly (scheduled) CI run on main"+ required: true+ type: string+ dry_run:+ description: "Report only; do not open, edit or close the issue."+ type: boolean+ default: truepermissions: {}@@ -31,10 +43,12 @@ jobs:# A fork pull request can be named `main` too: the repository and event# checks, not the branch filter alone, keep its runs out.if: >-- github.event.workflow_run.event == 'schedule' &&- github.event.workflow_run.head_repository.full_name == github.repository &&- github.event.workflow_run.head_branch == 'main' &&- contains(fromJSON('["success","failure"]'), github.event.workflow_run.conclusion)+ (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') ||+ (github.event_name == 'workflow_run' &&+ github.event.workflow_run.event == 'schedule' &&+ github.event.workflow_run.head_repository.full_name == github.repository &&+ github.event.workflow_run.head_branch == 'main' &&+ contains(fromJSON('["success","failure"]'), github.event.workflow_run.conclusion))runs-on: ubuntu-latesttimeout-minutes: 5permissions:@@ -44,19 +58,32 @@ jobs:- name: Open, update or close the tracking issueenv:GH_TOKEN: ${{ github.token }}- RUN_ID: ${{ github.event.workflow_run.id }}+ RUN_ID: ${{ inputs.run_id || github.event.workflow_run.id }}RUN_URL: ${{ github.event.workflow_run.html_url }}CONCLUSION: ${{ github.event.workflow_run.conclusion }}+ DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}run: |+ # A run id typed by hand is vetted like the event: only a finished+ # nightly run of this repository's CI on main may feed the issue.+ if [ -z "$RUN_URL" ]; then+ case "$RUN_ID" in (''|*[!0-9]*) echo "::error::not a run id: $RUN_ID"; exit 1 ;; esac+ vetted="$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID" --jq \+ 'select(.head_repository.full_name == env.GITHUB_REPOSITORY and .path == ".github/workflows/ci.yml" and .head_branch == "main" and .event == "schedule" and .status == "completed") | "\(.conclusion) \(.html_url)"')"+ [ -n "$vetted" ] || { echo "::error::run $RUN_ID is not a finished nightly CI run on main"; exit 1; }+ CONCLUSION="${vetted%% *}"; RUN_URL="${vetted#* }"+ fi+ write() { if [ "$DRY_RUN" = "true" ]; then echo "dry run, not executed: gh $*"; else gh "$@"; fi; }# The label lists issues without the search index, which lags behind# a freshly created issue and would invite a duplicate.number="$(gh issue list --repo "$GITHUB_REPOSITORY" --label nightly-ci --state open \--limit 1 --json number --jq '.[0].number // empty')"if [ "$CONCLUSION" = "success" ]; thenif [ -n "$number" ]; then- gh issue close "$number" --repo "$GITHUB_REPOSITORY" \+ write issue close "$number" --repo "$GITHUB_REPOSITORY" \--comment "The nightly run is green again: $RUN_URL"echo "Closed issue #$number" | tee -a "$GITHUB_STEP_SUMMARY"+ else+ echo "The nightly run is green and no issue is open." | tee -a "$GITHUB_STEP_SUMMARY"fiexit 0fi@@ -72,13 +99,14 @@ jobs:echo "was blocked by them. Reproduce on a branch with"echo '`gh workflow run ci.yml --ref <branch> -f full=false -f include_macos=true`.'} > "$RUNNER_TEMP/issue.md"+ tee -a "$GITHUB_STEP_SUMMARY" < "$RUNNER_TEMP/issue.md"if [ -n "$number" ]; then- gh issue edit "$number" --repo "$GITHUB_REPOSITORY" --body-file "$RUNNER_TEMP/issue.md"+ write issue edit "$number" --repo "$GITHUB_REPOSITORY" --body-file "$RUNNER_TEMP/issue.md"echo "Updated issue #$number" | tee -a "$GITHUB_STEP_SUMMARY"else- gh label create nightly-ci --repo "$GITHUB_REPOSITORY" --force \+ write label create nightly-ci --repo "$GITHUB_REPOSITORY" --force \--color B60205 --description "The nightly CI run on main is red"- url="$(gh issue create --repo "$GITHUB_REPOSITORY" --title "Nightly CI is red" \+ url="$(write issue create --repo "$GITHUB_REPOSITORY" --title "Nightly CI is red" \--label nightly-ci --body-file "$RUNNER_TEMP/issue.md")"echo "Created $url" | tee -a "$GITHUB_STEP_SUMMARY"fidiff --git a/docs/ci-pipeline.md b/docs/ci-pipeline.mdindex aca7119cdb..dfa5c64248 100644--- a/docs/ci-pipeline.md+++ b/docs/ci-pipeline.md@@ -185,6 +185,10 @@ merge queue), and hourly as a safety net:(`scripts/ci/agent_integrate.py`). No force push, so an agent that keepspushing to its branch is never overwritten. A pull request that is merelybehind is left alone: the queue re-tests it on the newest main anyway.+ Three branches are updated per tick. The slots go first to pull requests+ with green CI that only conflict with main, then to red ones, and last to+ those already labelled `needs-rebase`: in number order the three oldest+ pull requests, two of them unresolvable, had held every slot for days.2. Conflicts resolve by file class: **generated** files (frontend `dist/`,agent mirrors, CLI reference docs, lockfiles, timing caches) take main'scopy and are regenerated; **append-only** files (CHANGELOG, allowlists,diff --git a/scripts/ci/agent_integrate.py b/scripts/ci/agent_integrate.pyindex c6e277c6f5..38d474ab2c 100644--- a/scripts/ci/agent_integrate.py+++ b/scripts/ci/agent_integrate.py@@ -624,6 +624,30 @@ def decide(return "wait"+def grant_updates(wanted: list[dict[str, object]], max_updates: int) -> set[int]:+ """Which pull requests get this tick's update slots.++ The slots used to go to the lowest numbers. A pull request the train+ cannot update (an unresolved conflict, labelled ``needs-rebase``) and one+ whose own CI is red both ask again on every tick: three of them held all+ three slots for days while green pull requests that merely conflicted+ with main waited behind them. First come ``priority``, then the ones the+ train has not already failed on, then green CI, then the number.+ """++ def rank(entry: dict[str, object]) -> tuple[bool, bool, bool, int]:+ labels = {str(label) for label in entry.get("labels") or ()} # type: ignore[attr-defined]+ return (+ "priority" not in labels,+ "needs-rebase" in labels,+ entry.get("state") != "success",+ int(str(entry["number"])),+ )++ chosen = sorted(wanted, key=rank)[: max(0, max_updates)]+ return {int(str(entry["number"])) for entry in chosen}++def plan(repo: str, max_updates: int) -> dict[str, object]:"""Decide what the train does this tick. Reads only; runs no PR code."""prs = gh_json(@@ -651,7 +675,6 @@ def plan(repo: str, max_updates: int) -> dict[str, object]:)print(f"[train] {len(order)} eligible pull request(s); merge queue: {queued is not None}")entries: list[dict[str, object]] = []- updates = 0landing = Falsefor pr in order:number, branch, sha = pr["number"], pr["headRefName"], pr["headRefOid"]@@ -668,12 +691,7 @@ def plan(repo: str, max_updates: int) -> dict[str, object]:queue_failed=queue_rejected(queue_runs.get(number), runs),)note = f"CI {state}, {mergeable or 'unknown'}"- if action == "update":- if updates >= max_updates:- action, note = "wait", "needs an update, waits for a free slot"- else:- updates += 1- elif action == "merge" and queued is None:+ if action == "merge" and queued is None:if landing:action, note = ("wait",@@ -689,9 +707,14 @@ def plan(repo: str, max_updates: int) -> dict[str, object]:"action": action,"run_id": run_id,"note": note,+ "state": state,"labels": sorted(lb["name"] for lb in pr.get("labels", [])),})+ granted = grant_updates([e for e in entries if e["action"] == "update"], max_updates)+ for entry in entries:+ if entry["action"] == "update" and entry["number"] not in granted:+ entry["action"], entry["note"] = "wait", "needs an update, waits for a free slot"return {"repo": repo, "main": main_sha, "queue": queued is not None, "entries": entries}diff --git a/tests/unit/ci/test_pipeline_audit.py b/tests/unit/ci/test_pipeline_audit.pyindex 4cc23647df..786c43925a 100644--- a/tests/unit/ci/test_pipeline_audit.py+++ b/tests/unit/ci/test_pipeline_audit.py@@ -438,7 +438,16 @@ def test_a_red_nightly_reaches_someone_and_only_a_nightly_on_main_can_write_issu# No pull-request code runs next to the issue token.assert all("uses" not in step for step in job["steps"])script = job["steps"][0]["run"]- assert "--label nightly-ci" in script and "gh issue close" in script+ assert "--label nightly-ci" in script and "write issue close" in script+ # A check by hand runs from main only, vets the run it is given like the+ # event, and writes nothing unless the dry run is switched off.+ by_hand = "github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'"+ assert by_hand in job["if"]+ assert '.event == "schedule"' in script and '.head_branch == "main"' in script+ triggers = alert.get("on", alert.get(True))+ assert triggers["workflow_dispatch"]["inputs"]["dry_run"]["default"] is True+ for direct in ("gh issue close", "gh issue edit", "gh issue create", "gh label create"):+ assert direct not in script, direct# The legs that left the per-change tiers are exactly what the nightly keeps.nightly, queue = plan_run.plan("schedule"), plan_run.plan("merge_group")only_nightly = [leg for leg in nightly["e2e_matrix"] if leg not in queue["e2e_matrix"]]diff --git a/tests/unit/ci/test_pipeline_scripts.py b/tests/unit/ci/test_pipeline_scripts.pyindex d19627ea6e..7181b85260 100644--- a/tests/unit/ci/test_pipeline_scripts.py+++ b/tests/unit/ci/test_pipeline_scripts.py@@ -560,6 +560,27 @@ def test_train_updates_only_conflicting_or_stale_red_branches():assert decide("UNKNOWN", "approve", False) == "approve"+def test_train_gives_its_update_slots_to_the_pull_requests_that_can_land():+ wanted = [+ # The oldest ones: an unresolved conflict and a pull request with red CI.+ {"number": 1, "labels": ["needs-rebase"], "state": "success"},+ {"number": 2, "labels": [], "state": "failure"},+ {"number": 3, "labels": ["needs-rebase"], "state": "failure"},+ # Green pull requests that only conflict with main.+ {"number": 4, "labels": ["auto-merge"], "state": "success"},+ {"number": 5, "labels": [], "state": "success"},+ {"number": 6, "labels": [], "state": "success"},+ ]+ assert agent_integrate.grant_updates(wanted, 3) == {4, 5, 6}+ # A free slot still goes to the red one before the conflict nobody resolved.+ assert agent_integrate.grant_updates(wanted, 4) == {2, 4, 5, 6}+ assert agent_integrate.grant_updates(wanted, 6) == {1, 2, 3, 4, 5, 6}+ # `priority` moves a pull request to the front, whatever its state.+ urgent = [*wanted, {"number": 9, "labels": ["priority", "needs-rebase"], "state": "failure"}]+ assert agent_integrate.grant_updates(urgent, 1) == {9}+ assert agent_integrate.grant_updates(wanted, 0) == set()++def test_train_leaves_a_queued_pull_request_to_the_queue():decide = agent_integrate.decideassert decide("MERGEABLE", "success", True, queued=True) == "queued"