Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 286 additions & 0 deletions .github/scripts/fixtures/merge-decision-3406.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
{
"head": "5072d22dbda12a31b15c4a50071fbcf1ee3fdad7",
"gate": {
"number": 3406,
"head": "5072d22dbda12a31b15c4a50071fbcf1ee3fdad7",
"pass": true,
"gates": [
{
"n": 1,
"name": "head and state",
"pass": true,
"detail": [
"open, not a draft, mergeable, base main, head 5072d22dbda12a31b15c4a50071fbcf1ee3fdad7"
]
},
{
"n": 2,
"name": "required checks",
"pass": true,
"detail": [
"15 required checks and FlyBot required checks completed success on 5072d22d"
]
},
{
"n": 3,
"name": "evidence on this head",
"pass": true,
"detail": [
"QA #7210114758; review #7210116921 - both name 5072d22d"
]
},
{
"n": 4,
"name": "risk (advisory)",
"pass": true,
"detail": [
"risk:T3 - advisory only, merge is Lead's call"
]
}
]
},
"checks": [
{
"name": "Web and compose planner",
"attempts": [
{
"run": 140310751362,
"conclusion": "success",
"started_at": "2026-11-27T04:23:24Z"
},
{
"run": 140314992386,
"conclusion": "success",
"started_at": "2026-11-27T04:37:05Z"
}
]
},
{
"name": "Management API · Python 3.11",
"attempts": [
{
"run": 140310751281,
"conclusion": "success",
"started_at": "2026-11-27T04:23:25Z"
},
{
"run": 140314992356,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "Management API · Python 3.13",
"attempts": [
{
"run": 140310751136,
"conclusion": "success",
"started_at": "2026-11-27T04:23:24Z"
},
{
"run": 140314992099,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "upstream / Pin and vendor tree",
"attempts": [
{
"run": 140310751490,
"conclusion": "success",
"started_at": "2026-11-27T04:23:25Z"
},
{
"run": 140314992492,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "upstream / Upstream suite · Node 22 · DSH from pin",
"attempts": [
{
"run": 140310856686,
"conclusion": "success",
"started_at": "2026-11-27T04:23:44Z"
},
{
"run": 140315115128,
"conclusion": "success",
"started_at": "2026-11-27T04:37:29Z"
}
]
},
{
"name": "upstream / Upstream suite · Node 24 · DSH from pin",
"attempts": [
{
"run": 140310856705,
"conclusion": "success",
"started_at": "2026-11-27T04:23:44Z"
},
{
"run": 140315115142,
"conclusion": "success",
"started_at": "2026-11-27T04:37:29Z"
}
]
},
{
"name": "upstream / Container startup smoke",
"attempts": [
{
"run": 140310856661,
"conclusion": "success",
"started_at": "2026-11-27T04:23:45Z"
},
{
"run": 140315115169,
"conclusion": "success",
"started_at": "2026-11-27T04:37:29Z"
}
]
},
{
"name": "runtime-image / Image recipe contract tests",
"attempts": [
{
"run": 140310751359,
"conclusion": "success",
"started_at": "2026-11-27T04:23:25Z"
},
{
"run": 140314992438,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "runtime-image / Build and smoke under the manager contract",
"attempts": [
{
"run": 140310751457,
"conclusion": "failure",
"started_at": "2026-11-27T04:23:24Z"
},
{
"run": 140314992429,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "social-host / Social plugin on the pinned DS-Bot host",
"attempts": [
{
"run": 140310751294,
"conclusion": "success",
"started_at": "2026-11-27T04:23:25Z"
},
{
"run": 140314992324,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "social-host / Façade and ledger unit tests",
"attempts": [
{
"run": 140310751398,
"conclusion": "success",
"started_at": "2026-11-27T04:23:25Z"
},
{
"run": 140314992479,
"conclusion": "success",
"started_at": "2026-11-27T04:37:07Z"
}
]
},
{
"name": "browser / screenshots",
"attempts": [
{
"run": 140310751237,
"conclusion": "success",
"started_at": "2026-11-27T04:23:24Z"
},
{
"run": 140314992347,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "provenance / provenance",
"attempts": [
{
"run": 140310751451,
"conclusion": "success",
"started_at": "2026-11-27T04:23:25Z"
},
{
"run": 140314992483,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "provenance / flybot-social-plugin-tests",
"attempts": [
{
"run": 140310751303,
"conclusion": "success",
"started_at": "2026-11-27T04:23:24Z"
},
{
"run": 140314992316,
"conclusion": "success",
"started_at": "2026-11-27T04:37:05Z"
}
]
},
{
"name": "provenance / bot-social-source-tests",
"attempts": [
{
"run": 140310751437,
"conclusion": "success",
"started_at": "2026-11-27T04:23:25Z"
},
{
"run": 140314992526,
"conclusion": "success",
"started_at": "2026-11-27T04:37:06Z"
}
]
},
{
"name": "FlyBot required checks",
"attempts": [
{
"run": 140312199514,
"conclusion": "failure",
"started_at": "2026-11-27T04:28:04Z"
},
{
"run": 140316751442,
"conclusion": "success",
"started_at": "2026-11-27T04:42:58Z"
}
]
}
],
"tier": "T3",
"note": "Replay snapshot of PR #3406 (merged 2026-11-27T04:49:03Z): the gate block is reconstructed from the record, the check-run attempts were re-read with filter=all at 05:06Z."
}
89 changes: 89 additions & 0 deletions .github/scripts/merge-decision-core.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// The decision itself (issue #3407): read the four merge-gate results plus the run history of this
// head, and say whether to merge, with the reasons and a paste-ready merge record. Pure: no network,
// no process.argv, no writes.
//
// The four gates come from merge-gate.mjs: (1) head and state, (2) required checks, (3) QA evidence
// and Lead review on this head, (4) exactly one risk:T* label. Gates 1-3 are the evidence the merge
// rests on; gate 4 is the record, not the tier. The tier is read into an advisory line only: since
// 2026-11-26 the merge is the FlyBot Lead's call and no tier blocks or authorises it.
//
// Two facts about the run history are treated as first class, because "green" alone hides them:
//
// flake a failed attempt followed by a success on the identical head -> merge, recorded
// as a flake, never as clean green
// contradiction gate 2 says success but the newest attempt is not a success -> hold
//
// Required checks whose history was not supplied are not called clean: the verdict states the
// coverage instead.
import { EXIT, REQUIRED, VERDICT, attemptText, byStart, detailLines, tierOf, validate } from './merge-decision-input.mjs'
import { mergeRecord } from './merge-decision-record.mjs'
import { render } from './merge-decision-render.mjs'

// The module other files import: the decision, its input checks, and its two renderers.
export { EXIT, REQUIRED, VERDICT, attemptText, byStart, detailLines, tierOf, validate, render }

export function decide(input) {
const { ok, errors } = validate(input)
if (!ok) {
return { verdict: VERDICT.invalid, code: EXIT.invalid, head: input?.head, pr: input?.gate?.number ?? null, blockers: errors, caveats: [], flakes: [], coverage: null, tier: tierOf(input || {}), record: undefined }
}

const gates = input.gate.gates
const tier = tierOf(input)
const blockers = []
const caveats = []
const flakes = []

// Gates 1-3 are the evidence the merge rests on: any failure is a hold.
for (const gate of gates.slice(0, 3)) {
if (!gate.pass) blockers.push(`gate ${gate.n} (${gate.name}) failed: ${detailLines(gate.detail).join('; ') || 'no detail'}`)
}
// Gate 4 is the record, not the tier: a missing or doubled label means the record is incomplete.
if (!gates[3].pass) blockers.push(`gate 4 (${gates[3].name}) failed: ${detailLines(gates[3].detail).join('; ') || 'no detail'} - the record is incomplete, not the tier`)
if (gates[3].pass && !tier) blockers.push('gate 4 passes but the tier is not stated (input.tier or a risk:T* line in gate 4 detail)')

const history = new Map()
for (const check of input.checks) {
const attempts = [...check.attempts].sort(byStart)
history.set(check.name, [...(history.get(check.name) || []), ...attempts].sort(byStart))
}

// A gate-2 pass and a newest attempt that is not a success are two statements about one fact.
if (gates[1].pass) {
for (const name of REQUIRED) {
const attempts = history.get(name)
if (!attempts) continue
const newest = attempts[attempts.length - 1]
if (newest.conclusion !== 'success') blockers.push(`gate 2 says this check is success, but the newest attempt of "${name}" is ${attemptText(newest)}`)
}
}

// A failed attempt followed by a success on the identical head is a flake. It does not block the
// merge, and it must never be reported as green.
for (const [name, attempts] of history) {
if (attempts.length < 2) continue
const bad = attempts.filter((a) => a.conclusion !== 'success')
const good = attempts.filter((a) => a.conclusion === 'success')
if (bad.length === 0 || good.length === 0) continue
if (attempts[attempts.length - 1].conclusion !== 'success') continue
flakes.push({ name, attempts })
}
for (const flake of flakes) {
const first = flake.attempts.find((a) => a.conclusion !== 'success')
const last = flake.attempts[flake.attempts.length - 1]
caveats.push(`flake: "${flake.name}" ${attemptText(first)} then ${attemptText(last)} on the identical head - one red and one green run on the same bytes. Recorded as a flake, not clean green; it does not prove the first failure was a false alarm.`)
}

// Coverage: which required names the history actually holds. Uncovered names are not called clean.
const supplied = REQUIRED.filter((name) => history.has(name))
const missing = REQUIRED.filter((name) => !history.has(name))
const coverage = { required: REQUIRED.length, supplied: supplied.length, missing }
if (gates[1].pass && missing.length > 0) {
caveats.push(`run history covers ${supplied.length} of ${REQUIRED.length} required checks; ${missing.length} not read here, so this verdict does not call them clean (no flake evidence either way)`)
}

const verdict = blockers.length === 0 ? VERDICT.merge : VERDICT.hold
const result = { verdict, code: EXIT[verdict], head: input.head, pr: input.gate.number ?? null, gates, tier, blockers, caveats, flakes, coverage }
result.record = mergeRecord(result, input.note)
return result
}
Loading
Loading