From 573fe9dadc907b96c417c06f21758b7aac112672 Mon Sep 17 00:00:00 2001 From: repeat98 Date: Wed, 2 Dec 2026 10:08:23 +0100 Subject: [PATCH] Improvement: the maintenance bot never proposes a merge GitHub would refuse The bot's weekly retro (30 Nov 2026) flagged 3 of 28 merges failed. One (#2080, required checks not reported) is already held back since #2257. The other two still pass the policy: #2110 conflicted with main, and #2344 still carried the bot's own change request, so the owner tapped Approve and GitHub refused. The policy and the executor now hold back a merge that conflicts with main or that a reviewer's latest verdict still requests changes on. Co-Authored-By: Claude Opus 5.5 --- changelog/2026-12-02-bot-merge-guard.md | 1 + docs/MAINTENANCE_BOT.md | 2 +- scripts/maintenance-bot/act.mjs | 3 ++- scripts/maintenance-bot/lib.mjs | 3 ++- scripts/maintenance-bot/policy.mjs | 13 ++++++++++++- scripts/maintenance-bot/policy.test.mjs | 9 +++++++++ scripts/maintenance-bot/prompt.md | 2 +- 7 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 changelog/2026-12-02-bot-merge-guard.md diff --git a/changelog/2026-12-02-bot-merge-guard.md b/changelog/2026-12-02-bot-merge-guard.md new file mode 100644 index 0000000000..ba483b2574 --- /dev/null +++ b/changelog/2026-12-02-bot-merge-guard.md @@ -0,0 +1 @@ +Improvement: the maintenance bot no longer asks to merge a pull request GitHub would refuse. A merge that conflicts with main, or that a review still requests changes on (the bot's own included), is neither proposed nor run, so the owner never approves a merge that then fails. diff --git a/docs/MAINTENANCE_BOT.md b/docs/MAINTENANCE_BOT.md index 21ab303ed6..27af534604 100644 --- a/docs/MAINTENANCE_BOT.md +++ b/docs/MAINTENANCE_BOT.md @@ -17,7 +17,7 @@ The maintenance bot does the routine part of the [daily pass](MAINTENANCE.md) on A **decision** is a question only the owner can answer, such as an OK for a port or a shared hook. The bot does not file it as a to-do: it proposes the reply it recommends (a comment or board reply with `intent: "decision"`), which is posted after 24 hours unless the owner stops it. An answer that grants what the rules do not already allow (a waiver, a scope exception) or touches a unit's safety is marked `exception` and waits for Approve; the policy also asks whenever the answer's own words name a waiver or an exception. Only a decision the owner stopped becomes a to-do. -Only an ask, a failure and an urgent to-do make the owner's phone buzz. A window arrives silently, and the morning report names the next eight that can still be stopped. Each pass also drops what waits but can no longer happen (the item closed, new commits arrived, someone replied), so every message in Telegram is live. A merge whose required checks have not all reported waits for the next pass instead of failing. The model also sees the open to-dos: it adds one to-do per cause and drops those it sees settled (`drop` in its proposals). +Only an ask, a failure and an urgent to-do make the owner's phone buzz. A window arrives silently, and the morning report names the next eight that can still be stopped. Each pass also drops what waits but can no longer happen (the item closed, new commits arrived, someone replied), so every message in Telegram is live. A merge whose required checks have not all reported waits for the next pass instead of failing, and one that conflicts with main or that a review still requests changes on is not proposed or run. The model also sees the open to-dos: it adds one to-do per cause and drops those it sees settled (`drop` in its proposals). The bot never pushes, releases, deploys, touches secrets, or works on firmware, a unit or an emulator. Those become **to-dos** for a desktop session, each with the `/modwerk-*` command that does it, kept in the ledger (`maintenance_bot_todos`, migration 0092). They are the owner's private list. Work others could take is public already as its GitHub issue or pull request; the bot posts nothing to the agent board for it and opens no issues for to-dos. In any session at the owner's computer, `/modwerk-todo` lists them (`npm run todo`, signed in with the owner's `npm run board -- login`), runs the command, and ticks it off. A to-do whose item closes is dropped on the next daily run. Every action pins the head commit and comment count it was proposed against. If either changes before the action runs, the action is dropped and proposed again next pass. A merge is checked again for green checks at the moment it runs. The Worker then merges it in the owner's name (`POST /api/maintenance-bot/merge`) at exactly that commit, which starts the usual push workflows. A model-proposed release of someone else's module needs the owner's Approve. An explicit [reviewed merge](DEVELOPER_WORKFLOW.md#who-reviews-a-first-release) uses the worker's authenticated `/merge/reviewed` route and the same merge operation and ledger after the trusted GitHub job verifies the human review. A paused worker or an owner veto for that head stops it. Registered authors keep their separate self-merge workflow. diff --git a/scripts/maintenance-bot/act.mjs b/scripts/maintenance-bot/act.mjs index 799dbaf0fa..1f3ef5ed45 100644 --- a/scripts/maintenance-bot/act.mjs +++ b/scripts/maintenance-bot/act.mjs @@ -7,7 +7,7 @@ import { tagDiscordLinks } from '../../server/site-link-tags.ts' import { existsSync, readFileSync } from 'node:fs' import { join } from 'node:path' import { HARD_ONLY } from './lanes.mjs' -import { TODO_COMMAND, actionId, classify } from './policy.mjs' +import { TODO_COMMAND, actionId, classify, mergeBlock } from './policy.mjs' import { MARKER, approveRun, boardGet, discord, github, ledger, pages, readBoardTarget, readDiscordTarget, readTarget } from './lib.mjs' import { pilotReport } from './eval-pilot.mjs' import { dailyReport, weeklyRetro } from './report.mjs' @@ -206,6 +206,7 @@ async function carryOut(action) { return ['done', ''] case 'merge': { if (now.draft || !now.checksGreen) return ['expired', now.draft ? 'it became a draft' : 'its checks are no longer green'] + if (mergeBlock(now)) return ['expired', mergeBlock(now)] // The Worker merges with the owner's token, at exactly the commit that was checked, so the merge counts as // the owner's for the site's release gate and starts the usual push workflows. let result diff --git a/scripts/maintenance-bot/lib.mjs b/scripts/maintenance-bot/lib.mjs index fc1f07d7df..6d217b0db1 100644 --- a/scripts/maintenance-bot/lib.mjs +++ b/scripts/maintenance-bot/lib.mjs @@ -55,7 +55,8 @@ export async function readTarget(api, number) { const files = await pages(api, '/pulls/' + number + '/files') const waitingRuns = ((await api('/actions/runs?status=action_required&head_sha=' + pull.head.sha + '&per_page=30')).workflow_runs ?? []).length const checks = await checkSummary(api, pull.head.sha) - return { ...target, waitingRuns, draft: !!pull.draft, head: pull.head.sha, baseRef: pull.base.ref, headRef: pull.head.ref, files: files.flatMap(file => [file.filename, file.previous_filename].filter(Boolean)), firstTime: ['FIRST_TIMER', 'FIRST_TIME_CONTRIBUTOR', 'NONE'].includes(pull.author_association), checks, checksGreen: checks === 'green' } + const reviews = (await pages(api, '/pulls/' + number + '/reviews')).map(review => ({ user: review.user?.id, state: review.state })) + return { ...target, waitingRuns, mergeable: pull.mergeable, reviews, draft: !!pull.draft, head: pull.head.sha, baseRef: pull.base.ref, headRef: pull.head.ref, files: files.flatMap(file => [file.filename, file.previous_filename].filter(Boolean)), firstTime: ['FIRST_TIMER', 'FIRST_TIME_CONTRIBUTOR', 'NONE'].includes(pull.author_association), checks, checksGreen: checks === 'green' } } /** The agent board's public reads (threads and claims need no sign-in). */ diff --git a/scripts/maintenance-bot/policy.mjs b/scripts/maintenance-bot/policy.mjs index 86fa73a2b6..3574d30942 100644 --- a/scripts/maintenance-bot/policy.mjs +++ b/scripts/maintenance-bot/policy.mjs @@ -59,9 +59,19 @@ export function checkText(body, author) { const waives = proposal => proposal.exception === true || WAIVES.test([proposal.summary, proposal.reason, proposal.body].join(' ')) +/** + * Why GitHub would refuse a merge whose checks are green, or '': a conflict with main, or a reviewer whose latest + * verdict still requests changes, the bot's own included (#2110 and #2344 failed on these, November 2026). + */ +export function mergeBlock(target) { + if (target.mergeable === false) return 'it conflicts with main' + const latest = new Map((target.reviews ?? []).filter(review => ['APPROVED', 'CHANGES_REQUESTED', 'DISMISSED'].includes(review.state)).map(review => [review.user, review.state])) + return [...latest.values()].includes('CHANGES_REQUESTED') ? 'a review still requests changes' : '' +} + /** * Decides one proposal against the target's live state. `target` is what the executor read from GitHub: - * { number, isPull, author, state, draft, head, comments, files, firstTime, checksGreen }. + * { number, isPull, author, state, draft, head, comments, files, firstTime, checksGreen, mergeable, reviews }. * Returns { tier, windowHours, id, payload } or { reject }. */ export function classify(proposal, target, existingLabels = new Set()) { @@ -100,6 +110,7 @@ export function classify(proposal, target, existingLabels = new Set()) { if (!target.isPull) return { reject: 'only a pull request merges' } if (target.draft) return { reject: 'it is a draft' } if (!target.checksGreen) return { reject: 'its checks are not green' } + if (mergeBlock(target)) return { reject: mergeBlock(target) } if (proposal.head !== target.head) return { reject: 'it was reviewed at another commit' } // A merge runs in the owner's name (the site only publishes owner merges), so someone else's release always // asks the owner. The owner marked their own pull request ready, so it merges after a short window. diff --git a/scripts/maintenance-bot/policy.test.mjs b/scripts/maintenance-bot/policy.test.mjs index 24858e7c6a..9957a60672 100644 --- a/scripts/maintenance-bot/policy.test.mjs +++ b/scripts/maintenance-bot/policy.test.mjs @@ -52,6 +52,15 @@ describe('maintenance bot policy', () => { expect(classify(merge(), pull({ state: 'closed' })).reject).toBeTruthy() }) + it('never proposes a merge GitHub would refuse: a conflict, or a change request its reviewer has not lifted', () => { + expect(classify(merge(), pull({ mergeable: false })).reject).toBe('it conflicts with main') + expect(classify(merge(), pull({ mergeable: null })).reject).toBeUndefined() + const asked = { user: 1, state: 'CHANGES_REQUESTED' } + expect(classify(merge(), pull({ reviews: [asked, { user: 1, state: 'COMMENTED' }] })).reject).toBe('a review still requests changes') + expect(classify(merge(), pull({ reviews: [{ user: 2, state: 'APPROVED' }, asked] })).reject).toBe('a review still requests changes') + for (const state of ['APPROVED', 'DISMISSED']) expect(classify(merge(), pull({ reviews: [asked, { user: 1, state }] })).reject).toBeUndefined() + }) + it('gives every action it accepts a summary the ledger takes', () => { // A merge once lost its summary to a shadowed name, and the Worker refused the whole pass (26 November 2026). const thread = { kind: 'thread', id: 't1', number: 0, author: 'alice', to: 'repeat98', replies: 0, state: 'open' } diff --git a/scripts/maintenance-bot/prompt.md b/scripts/maintenance-bot/prompt.md index fef9151b34..12558738ff 100644 --- a/scripts/maintenance-bot/prompt.md +++ b/scripts/maintenance-bot/prompt.md @@ -24,7 +24,7 @@ Your answer is the proposals, as structured output: `{"actions": [...], "todos": - A **decision**: a question only the owner can answer (an OK for a port, whether a gesture or menu may be taken, which of two plans, a shared hook) is a `comment` (or `board_reply`) with `"intent": "decision"` and the reply you recommend, in the owner's voice. It is posted after 24 hours unless the owner stops it. Add `"exception": true` when your answer grants anything the rules do not already allow (a waiver, a scope exception, an OK the modding guidelines would refuse, a merge without its test record) or touches a unit's safety: that one waits for the owner's Approve and never runs without it. When you are unsure which it is, mark it an exception. The `summary` is the question with your answer ("OK Kits 0.1.1 in the shared Part Edit menu: yes"), the `reason` the case for and against in two sentences. Recommend what the guidelines, MAINTENANCE.md and the owner's earlier answers in the ledger point to. Only if the ledger shows the owner stopped your answer and the question still waits does it become a to-do. - A first-time contributor's waiting checks are started for you; do not propose that. - `review`: `body` and `event` (`COMMENT` or `REQUEST_CHANGES`), on a contributor's pull request, with the changes the rules require and how to make them (`npm run pr:ready`, the guide's anchor). Waits 15 minutes, so it posts at the next pass. A pull request's `botReviews` are your own earlier reviews of it, in full. A push or a draft toggle is no reason to review again: when nothing you asked for was settled and nothing new is wrong, propose no review, because your last one still stands. If the author marked it ready since, one sentence is enough, naming what still stands. Otherwise write a follow-up that names only what changed since your last review: what is now settled, and anything new. Point to the rest in one line ("The rest of my review from 29 November still stands") instead of repeating it. Never restate an ask that is already in an earlier review. -- `merge` (hard lane only): `head` (the exact head commit you reviewed). Only for a pull request that is not a draft, has green checks, passes the review rules in MAINTENANCE.md and the review skill, and is the right next step. The owner's own pull request merges after 1 hour, anyone else's after 12; the policy turns it into an owner question when the pull request touches CI, the bot, migrations, dependencies, sign-in, the base or SDK code outside module folders, publishes someone else's module, or comes from a first-time contributor. A base for any device never merges on a timer: a pull request from or into a `base/…` branch, or one that changes a base's sources or built files, always waits for the owner's Approve after its review. Propose its merge only when it is not a draft and its description records the builds that ran on a unit, and say in the reason which ran and who reviewed it; a machine's cumulative draft stays a draft until the owner marks it ready. A module release notifies its followers when it merges: say so in the reason. +- `merge` (hard lane only): `head` (the exact head commit you reviewed). Only for a pull request that is not a draft, has green checks, does not conflict with main, has no change request still standing (your own included: when the author met it, say so in a `review`; GitHub refuses the merge until the owner dismisses it), passes the review rules in MAINTENANCE.md and the review skill, and is the right next step. The owner's own pull request merges after 1 hour, anyone else's after 12; the policy turns it into an owner question when the pull request touches CI, the bot, migrations, dependencies, sign-in, the base or SDK code outside module folders, publishes someone else's module, or comes from a first-time contributor. A base for any device never merges on a timer: a pull request from or into a `base/…` branch, or one that changes a base's sources or built files, always waits for the owner's Approve after its review. Propose its merge only when it is not a draft and its description records the builds that ran on a unit, and say in the reason which ran and who reviewed it; a machine's cumulative draft stays a draft until the owner marks it ready. A module release notifies its followers when it merges: say so in the reason. - `close`: `body` (the reason, to the author) and `reason_code` (`completed` or `not_planned`). For issues that are fixed and live, answered, duplicates (link the original), superseded, or a week past an unanswered question from us. Waits 12 hours. Closing someone else's pull request always needs the owner's OK; propose it only with a clear reason from MAINTENANCE.md. Do not propose the same thing twice for an unchanged item, nor say again on GitHub what an earlier comment or review of yours already said, and never re-propose what the ledger shows the owner stopped, unless the item has changed since. At most 40 actions a run.