From c85251a0203d08dc91c184c865e0473a9d7a185d Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 14:26:33 -0400 Subject: [PATCH 01/14] =?UTF-8?q?=E2=9C=A8=20Complete=20native=20queue=20C?= =?UTF-8?q?I=20and=20admission=20evidence=20integration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/scripts/native-queue-policy.cjs | 201 ++++++++++++++++ .github/scripts/native-queue-policy.test.cjs | 197 ++++++++++++++++ .github/scripts/pr-auto-update.sh | 34 +++ .../scripts/test-native-queue-workflows.py | 63 +++++ .github/scripts/test_pr-auto-update.sh | 39 +++- .github/workflows/go-security-analysis.yml | 2 + .github/workflows/native-queue-policy.yml | 52 +++++ .github/workflows/pr-auto-update-test.yml | 16 ++ .github/workflows/pr-auto-update.yml | 3 + .github/workflows/v2-ci.yml | 2 + .github/workflows/v2-tests.yml | 32 ++- .../added-native-queue-ci-integration.md | 1 + src/docs/native-merge-queue.md | 221 +++++++++++++++++- src/pkg/dashboard/api_config_automerge.go | 6 + .../dashboard/native_queue_settings_test.go | 42 ++++ .../static-src/js/config-features.js | 12 +- src/pkg/dashboard/static/index.html | 12 +- 17 files changed, 926 insertions(+), 9 deletions(-) create mode 100644 .github/scripts/native-queue-policy.cjs create mode 100644 .github/scripts/native-queue-policy.test.cjs create mode 100644 .github/scripts/test-native-queue-workflows.py create mode 100644 .github/workflows/native-queue-policy.yml create mode 100644 changelog.d/added-native-queue-ci-integration.md create mode 100644 src/pkg/dashboard/native_queue_settings_test.go diff --git a/.github/scripts/native-queue-policy.cjs b/.github/scripts/native-queue-policy.cjs new file mode 100644 index 0000000000..9f3b245c3e --- /dev/null +++ b/.github/scripts/native-queue-policy.cjs @@ -0,0 +1,201 @@ +'use strict'; + +// This is an owned evidence gate, not a publisher of another App's statuses. +const ACTIONS_APP_ID = 15368; +const DCO_APP_ID = 1861; +const POLICY_CHECKS = { + gate: ['docker.yml', ['push', 'pull_request']], + DCO: null, + 'changelog-fragment-guard': ['changelog-fragment-guard.yml', ['pull_request']], + 'verify PR contents': ['pr-verifier.yml', ['pull_request_target']], + 'Sign-off survives the squash': ['dco-squash-attribution.yml', ['pull_request']], +}; +const BUILD_CHECKS = { + 'build-and-test': ['v2-ci.yml', ['pull_request']], + test: ['v2-tests.yml', ['pull_request']], + coverage: ['v2-tests.yml', ['pull_request']], + 'golangci-lint': ['go-security-analysis.yml', ['pull_request']], + 'gosec (insecure patterns)': ['go-security-analysis.yml', ['pull_request']], + 'govulncheck (known vulnerabilities)': ['go-security-analysis.yml', ['pull_request']], +}; +const SHA = /^[a-f0-9]{40}$/; +const BLOCKED_LABEL = /^(hold|needs-human|release-in-progress|do-not-merge(?:\/.*)?)$/i; +const MAX_QUEUE_PAGES = 10; + +class PendingEvidence extends Error {} + +function membersForGroup(entries, group) { + if (!SHA.test(group.head_sha) || !SHA.test(group.base_sha) || + !group.base_ref?.startsWith('refs/heads/') || + !group.head_ref?.startsWith('refs/heads/gh-readonly-queue/')) { + throw new Error('Malformed merge-group identity'); + } + const ordered = [...entries].sort((a, b) => a.position - b.position); + const last = ordered.findIndex(e => e.headCommit?.oid === group.head_sha); + if (last < 0) throw new PendingEvidence('Group SHA is not present in the live queue'); + const members = ordered.slice(0, last + 1); + const seen = new Set(); + for (const [index, entry] of members.entries()) { + const pr = entry.pullRequest; + if (entry.position !== index + 1 || !entry.id || !pr || + !Number.isSafeInteger(pr.number) || pr.number <= 0 || + !SHA.test(pr.headRefOid) || !SHA.test(entry.headCommit?.oid) || + !SHA.test(entry.baseCommit?.oid) || seen.has(pr.number) || + pr.baseRefName !== group.base_ref.slice('refs/heads/'.length)) { + throw new Error('Incomplete or inconsistent queue membership'); + } + seen.add(pr.number); + } + // The event's base and every intermediate merge must describe one chain; + // guessing from the PR number in gh-readonly-queue/... misses earlier PRs. + let base = group.base_sha; + for (const entry of members) { + if (entry.baseCommit.oid !== base) throw new Error('Queue base chain changed'); + base = entry.headCommit.oid; + } + return members; +} + +function assertEligible(pr, head, base) { + if (pr.state !== 'open' || pr.draft || pr.head?.sha !== head || + pr.base?.ref !== base || pr.labels?.some(l => BLOCKED_LABEL.test(l.name))) { + throw new Error(`#${pr.number}: head/base moved, draft, closed, or held`); + } +} + +function evidenceForHead(runs, head, checks) { + return Object.entries(checks).map(([name, source]) => { + const run = runs.filter(r => r.name === name).sort((a, b) => b.id - a.id)[0]; + if (!run) throw new PendingEvidence(`Missing ${name} on ${head}`); + const app = source ? ACTIONS_APP_ID : DCO_APP_ID; + if (run.app?.id !== app || run.head_sha !== head) { + throw new Error(`Untrusted provider or wrong head for ${name}`); + } + if (run.status !== 'completed') throw new PendingEvidence(`${name} is pending`); + // Existing PR path scoping legitimately skips technical jobs only. Policy + // proofs, especially external DCO, must have actually succeeded. + const scopedSkip = Object.hasOwn(BUILD_CHECKS, name) && run.conclusion === 'skipped'; + if (run.conclusion !== 'success' && !scopedSkip) throw new Error(`${name}: ${run.conclusion}`); + return { run, source }; + }); +} + +async function assertEvidence(github, repo, number, head, checks) { + const runs = await github.paginate(github.rest.checks.listForRef, { + ...repo, ref: head, per_page: 100, filter: 'latest', + }); + for (const { run, source } of evidenceForHead(runs, head, checks)) { + if (!source) continue; // Probot DCO is deliberately not impersonated. + const url = new URL(run.details_url); + const prefix = `/${repo.owner}/${repo.repo}/actions/runs/`; + const id = url.pathname.startsWith(prefix) && url.pathname.slice(prefix.length).split('/')[0]; + if (url.hostname !== 'github.com' || !/^[0-9]+$/.test(id)) { + throw new Error(`Invalid Actions provenance for ${run.name}`); + } + const { data: workflow } = await github.rest.actions.getWorkflowRun({ ...repo, run_id: Number(id) }); + const [file, events] = source; + if (workflow.path !== `.github/workflows/${file}` || !events.includes(workflow.event) || + workflow.head_sha !== head) { + throw new Error(`Unexpected workflow/event/head for ${run.name} on #${number}`); + } + } +} + +async function assertReviews(github, repo, number, head) { + const reviews = await github.paginate(github.rest.pulls.listReviews, { + ...repo, pull_number: number, per_page: 100, + }); + const latest = new Map(); + for (const review of reviews.sort((a, b) => a.id - b.id)) { + if (['APPROVED', 'CHANGES_REQUESTED', 'DISMISSED'].includes(review.state)) { + latest.set(review.user?.login, review); + } + } + for (const review of latest.values()) { + if (review.state === 'CHANGES_REQUESTED' || review.state === 'DISMISSED' || + (review.state === 'APPROVED' && review.commit_id !== head)) { + throw new Error(`#${number}: changes requested or stale approval`); + } + } +} + +async function readQueue(github, repo, group) { + const entries = []; + let cursor = null; + for (let page = 0; page < MAX_QUEUE_PAGES; page++) { + const data = await github.graphql(`query($owner:String!,$repo:String!,$base:String!,$cursor:String) { + repository(owner:$owner,name:$repo) { mergeQueue(branch:$base) { + entries(first:100,after:$cursor) { + nodes { id position baseCommit { oid } headCommit { oid } + pullRequest { number headRefOid baseRefName } } + pageInfo { hasNextPage endCursor } + } + } } + }`, { ...repo, base: group.base_ref.slice('refs/heads/'.length), cursor }); + const queue = data.repository?.mergeQueue?.entries; + if (!queue) throw new Error('Live queue unavailable'); + entries.push(...queue.nodes); + if (entries.some(e => e.headCommit?.oid === group.head_sha) || !queue.pageInfo.hasNextPage) { + return membersForGroup(entries, group); + } + cursor = queue.pageInfo.endCursor; + if (!cursor) throw new Error('Incomplete queue pagination'); + } + throw new Error('Queue exceeds bounded membership lookup'); +} + +function snapshot(members) { + return JSON.stringify(members); +} + +async function evaluate({ github, context }) { + const repo = context.repo; + if (context.eventName === 'pull_request_target') { + const event = context.payload.pull_request; + const { data: pr } = await github.rest.pulls.get({ ...repo, pull_number: event.number }); + assertEligible(pr, event.head.sha, event.base.ref); + await assertEvidence(github, repo, pr.number, pr.head.sha, POLICY_CHECKS); + const { data: current } = await github.rest.pulls.get({ ...repo, pull_number: event.number }); + assertEligible(current, event.head.sha, event.base.ref); + return `PR #${pr.number}: five existing policy providers succeeded on ${pr.head.sha}`; + } + if (context.eventName !== 'merge_group' || context.payload.action !== 'checks_requested') { + throw new Error('Unsupported policy event'); + } + const group = context.payload.merge_group; + const members = await readQueue(github, repo, group); + for (const entry of members) { + const { number, headRefOid: head } = entry.pullRequest; + const { data: pr } = await github.rest.pulls.get({ ...repo, pull_number: number }); + assertEligible(pr, head, group.base_ref.slice('refs/heads/'.length)); + const { data: comparison } = await github.rest.repos.compareCommitsWithBasehead({ + ...repo, basehead: `${head}...${group.head_sha}`, + }); + if (!['ahead', 'identical'].includes(comparison.status) || comparison.merge_base_commit?.sha !== head) { + throw new Error(`#${number}: current PR head is not contained in the tested group`); + } + await assertReviews(github, repo, number, head); + await assertEvidence(github, repo, number, head, { ...POLICY_CHECKS, ...BUILD_CHECKS }); + } + // Re-read both membership and mutable gates after all evidence reads. This + // bounds TOCTOU, but GitHub/Hive reconciliation is not an atomic transaction. + if (snapshot(await readQueue(github, repo, group)) !== snapshot(members)) { + throw new Error('Queue membership/head changed during validation'); + } + for (const entry of members) { + const { number, headRefOid: head } = entry.pullRequest; + const { data: pr } = await github.rest.pulls.get({ ...repo, pull_number: number }); + assertEligible(pr, head, group.base_ref.slice('refs/heads/'.length)); + await assertReviews(github, repo, number, head); + } + const { data: ref } = await github.rest.git.getRef({ + ...repo, ref: group.head_ref.slice('refs/'.length), + }); + if (ref.object?.sha !== group.head_sha) throw new Error('Synthetic group ref moved'); + return `Group ${group.head_sha}: validated all ${members.length} member heads`; +} + +module.exports = { + ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS, + PendingEvidence, membersForGroup, assertEligible, evidenceForHead, evaluate, +}; diff --git a/.github/scripts/native-queue-policy.test.cjs b/.github/scripts/native-queue-policy.test.cjs new file mode 100644 index 0000000000..11144d5e20 --- /dev/null +++ b/.github/scripts/native-queue-policy.test.cjs @@ -0,0 +1,197 @@ +'use strict'; +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const { + ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS, + PendingEvidence, membersForGroup, assertEligible, evidenceForHead, evaluate, +} = require('./native-queue-policy.cjs'); + +const sha = n => n.toString(16).padStart(40, '0'); +const group = { + base_sha: sha(1), head_sha: sha(4), base_ref: 'refs/heads/v5', + head_ref: 'refs/heads/gh-readonly-queue/v5/pr-2-example', +}; +const entries = [ + { id: 'one', position: 1, baseCommit: { oid: sha(1) }, headCommit: { oid: sha(3) }, + pullRequest: { number: 1, headRefOid: sha(11), baseRefName: 'v5' } }, + { id: 'two', position: 2, baseCommit: { oid: sha(3) }, headCommit: { oid: sha(4) }, + pullRequest: { number: 2, headRefOid: sha(12), baseRefName: 'v5' } }, +]; +const clone = x => structuredClone(x); +const eligible = n => ({ + number: n, state: 'open', draft: false, head: { sha: sha(10 + n) }, + base: { ref: 'v5' }, labels: [], +}); + +function checks(head, definitions = { ...POLICY_CHECKS, ...BUILD_CHECKS }) { + return Object.entries(definitions).map(([name, source], index) => ({ + id: 100 + index, name, head_sha: head, status: 'completed', conclusion: 'success', + app: { id: source ? ACTIONS_APP_ID : DCO_APP_ID }, + details_url: `https://github.com/acme/widget/actions/runs/${100 + index}/job/1`, + })); +} + +function fixture(eventName = 'merge_group') { + const state = { + queue: clone(entries), prs: [eligible(1), eligible(2)], seen: [], reviews: [], + runs: new Map([1, 2].map(n => [sha(10 + n), checks(sha(10 + n))])), + ancestry: 'ahead', ref: group.head_sha, queueReads: 0, + }; + const github = { + rest: { + checks: { listForRef: 'checks' }, pulls: { + get: async ({ pull_number: n }) => ({ data: clone(state.prs[n - 1]) }), + listReviews: 'reviews', + }, + actions: { + getWorkflowRun: async ({ run_id: id }) => { + const definition = [...Object.entries(POLICY_CHECKS), ...Object.entries(BUILD_CHECKS)][id - 100]; + const source = definition[1]; + return { data: { + path: state.badWorkflow || `.github/workflows/${source[0]}`, + event: source[1][0], head_sha: state.workflowHead, + } }; + }, + }, + repos: { compareCommitsWithBasehead: async ({ basehead }) => { + state.seen.push(basehead); + return { data: { status: state.ancestry, merge_base_commit: { sha: basehead.split('...')[0] } } }; + } }, + git: { getRef: async () => ({ data: { object: { sha: state.ref } } }) }, + }, + paginate: async (method, args) => { + if (method === 'checks') { + state.workflowHead = args.ref; + return clone(state.runs.get(args.ref)); + } + return clone(state.reviews); + }, + graphql: async () => { + state.queueReads++; + if (state.mutateOnReread && state.queueReads === 2) state.queue[0].pullRequest.headRefOid = sha(99); + return { repository: { mergeQueue: { entries: { + nodes: clone(state.queue), pageInfo: { hasNextPage: false }, + } } } }; + }, + }; + const context = { + repo: { owner: 'acme', repo: 'widget' }, eventName, + payload: eventName === 'merge_group' ? { action: 'checks_requested', merge_group: clone(group) } : + { pull_request: clone(state.prs[0]) }, + }; + return { github, context, state }; +} + +test('all members, not merely the PR encoded in the group ref', () => { + assert.deepEqual(membersForGroup(entries, group).map(e => e.pullRequest.number), [1, 2]); +}); + +test('missing, duplicate, reordered and changed-base membership fail closed', () => { + for (const mutate of [ + es => es.shift(), + es => { es[0].pullRequest.number = 2; }, + es => { es[1].baseCommit.oid = sha(99); }, + es => { es[0].pullRequest.baseRefName = 'v6'; }, + es => { es[1].headCommit = null; }, + es => { es[0].pullRequest.headRefOid = ''; }, + ]) { + const es = clone(entries); + mutate(es); + assert.throws(() => membersForGroup(es, group)); + } +}); + +test('malformed group identity is rejected', () => { + for (const change of [{ head_sha: '' }, { base_sha: '' }, { head_ref: 'refs/heads/v5' }, { base_ref: 'v5' }]) { + assert.throws(() => membersForGroup(entries, { ...group, ...change })); + } +}); + +test('every one of the eleven protections needs exact-head evidence', () => { + const definitions = { ...POLICY_CHECKS, ...BUILD_CHECKS }; + assert.equal(Object.keys(definitions).length, 11); + const runs = checks(sha(11)); + assert.equal(evidenceForHead(runs, sha(11), definitions).length, 11); + for (const run of runs) { + assert.throws(() => evidenceForHead(runs.filter(r => r.id !== run.id), sha(11), definitions), PendingEvidence); + for (const change of [ + { status: 'in_progress' }, { conclusion: 'failure' }, { conclusion: 'neutral' }, + { app: { id: 999 } }, { head_sha: sha(99) }, + ]) { + assert.throws(() => evidenceForHead(runs.map(r => r.id === run.id ? { ...r, ...change } : r), sha(11), definitions)); + } + } +}); + +test('no Actions-generated DCO, stale success, or skipped policy proof', () => { + const runs = checks(sha(11)); + const dco = runs.find(r => r.name === 'DCO'); + for (const change of [{ app: { id: ACTIONS_APP_ID } }, { conclusion: 'skipped' }, { status: 'queued' }]) { + assert.throws(() => evidenceForHead([...runs, { ...dco, id: 999, ...change }], sha(11), POLICY_CHECKS)); + } + const technical = runs.map(r => Object.hasOwn(BUILD_CHECKS, r.name) ? { ...r, conclusion: 'skipped' } : r); + assert.equal(evidenceForHead(technical, sha(11), BUILD_CHECKS).length, 6); +}); + +test('draft, closed, held and moved-head/base PRs cannot pass', () => { + for (const change of [ + { draft: true }, { state: 'closed' }, { head: { sha: sha(99) } }, { base: { ref: 'v6' } }, + ...['hold', 'needs-human', 'do-not-merge', 'do-not-merge/security', 'release-in-progress'].map(name => ({ labels: [{ name }] })), + ]) assert.throws(() => assertEligible({ ...eligible(1), ...change }, sha(11), 'v5')); +}); + +test('group evaluation checks each member head, all evidence, and live synthetic ref', async () => { + const f = fixture(); + assert.match(await evaluate(f), /all 2 member heads/); + assert.deepEqual(f.state.seen, [`${sha(11)}...${sha(4)}`, `${sha(12)}...${sha(4)}`]); + assert.equal(f.state.queueReads, 2); +}); + +test('PR-target admission consumes policy providers without group APIs', async () => { + const f = fixture('pull_request_target'); + assert.match(await evaluate(f), /five existing policy providers/); + assert.equal(f.state.queueReads, 0); + assert.equal(f.state.seen.length, 0); +}); + +test('untrusted events and workflow provenance are rejected', async () => { + const f = fixture('pull_request'); + await assert.rejects(evaluate(f), /Unsupported/); + const g = fixture(); + g.state.badWorkflow = '.github/workflows/untrusted.yml'; + await assert.rejects(evaluate(g), /Unexpected workflow/); +}); + +test('earlier member failure blocks the whole group', async () => { + const f = fixture(); + f.state.runs.get(sha(11)).find(r => r.name === 'DCO').conclusion = 'failure'; + await assert.rejects(evaluate(f), /DCO: failure/); +}); + +test('changed membership, missing ancestry and moved ref fail closed', async () => { + for (const change of [ + { mutateOnReread: true }, { ancestry: 'diverged' }, { ref: sha(99) }, + ]) { + const f = fixture(); + Object.assign(f.state, change); + await assert.rejects(evaluate(f)); + } +}); + +test('changes requested, withdrawn and stale approvals block group validation', async () => { + for (const review of [ + { state: 'CHANGES_REQUESTED', commit_id: sha(11) }, + { state: 'DISMISSED', commit_id: sha(11) }, + { state: 'APPROVED', commit_id: sha(99) }, + ]) { + const f = fixture(); + f.state.reviews = [{ id: 1, user: { login: 'reviewer' }, ...review }]; + await assert.rejects(evaluate(f), /approval|changes requested/); + } +}); + +test('API failure is never interpreted as an empty successful member list', async () => { + const f = fixture(); + f.github.graphql = async () => { throw new Error('403 queue read forbidden'); }; + await assert.rejects(evaluate(f), /403/); +}); diff --git a/.github/scripts/pr-auto-update.sh b/.github/scripts/pr-auto-update.sh index 89ee3d250e..baae1a468e 100755 --- a/.github/scripts/pr-auto-update.sh +++ b/.github/scripts/pr-auto-update.sh @@ -28,6 +28,35 @@ need jq api() { gh api "$@"; } summary_rows='' +native_queue_owns_freshness() { + local pr=$1 entry configured=false base enabled + for entry in ${HIVE_NATIVE_QUEUE_FRESHNESS:-}; do + [[ "$entry" != "${REPO}#"* ]] || configured=true + done + if [[ "$configured" != true ]]; then printf 'false\n'; return; fi + # Capture the result, rather than a process substitution: a failed queue + # read must stop writes, not look like a non-queue branch. + local result + result=$(api graphql -f query='query($owner:String!,$repo:String!,$number:Int!){ + repository(owner:$owner,name:$repo){pullRequest(number:$number){ + baseRefName isMergeQueueEnabled + }} + }' -f owner="${REPO%/*}" -f repo="${REPO#*/}" -F number="$pr" \ + --jq '.data.repository.pullRequest | [.baseRefName, .isMergeQueueEnabled] | @tsv') || return 1 + IFS=$'\t' read -r base enabled <<<"$result" + [[ -n "$base" && ( "$enabled" == true || "$enabled" == false ) ]] || { + echo "queue detection unavailable for #${pr}; refusing branch update" >&2 + return 1 + } + for entry in ${HIVE_NATIVE_QUEUE_FRESHNESS:-}; do + if [[ "$entry" == "${REPO}#${base}" && "$enabled" == true ]]; then + printf 'true\n' + return + fi + done + printf 'false\n' +} + push_files=() if [[ -z "$INCIDENT" ]]; then if [[ -z "$BEFORE" || "$BEFORE" == "$ZERO_SHA" ]]; then @@ -81,6 +110,11 @@ if [[ -z "$INCIDENT" ]]; then pulls_endpoint+="&base=${BASE_BRANCH}"; fi prs=$(api "$pulls_endpoint" --paginate --slurp) while IFS=$'\t' read -r number title _head_repo; do [[ -n "${number:-}" ]] || continue + queue_owned=$(native_queue_owns_freshness "$number") + if [[ "$queue_owned" == true ]]; then + add_row "$number" "$title" 'skipped' 'native queue owns freshness' + continue + fi if [[ -n "$INCIDENT" ]]; then body=$(jq -r --argjson number "$number" '.[][] | select(.number == $number) | .body // ""' <<<"$prs") if [[ "$body" != *"$MARKER"* ]]; then diff --git a/.github/scripts/test-native-queue-workflows.py b/.github/scripts/test-native-queue-workflows.py new file mode 100644 index 0000000000..9379ea999c --- /dev/null +++ b/.github/scripts/test-native-queue-workflows.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +"""Structural contracts for required native queue workflows (not a Go runner).""" +import pathlib +import unittest + +import yaml + +ROOT = pathlib.Path(__file__).resolve().parents[2] + + +def workflow(name): + return yaml.safe_load((ROOT / ".github/workflows" / name).read_text()) + + +class NativeQueueWorkflows(unittest.TestCase): + def test_six_required_contexts_have_unfiltered_group_triggers(self): + expected = { + "v2-ci.yml": ["build-and-test"], + "v2-tests.yml": ["test", "coverage"], + "go-security-analysis.yml": [ + "golangci-lint", + "gosec (insecure patterns)", + "govulncheck (known vulnerabilities)", + ], + } + for file, contexts in expected.items(): + with self.subTest(file=file): + data = workflow(file) + # PyYAML's YAML 1.1 loader interprets the key `on` as True. + events = data.get("on", data.get(True)) + self.assertEqual(events["merge_group"], {"types": ["checks_requested"]}) + self.assertTrue(all(value == "read" for value in data["permissions"].values())) + jobs = {job.get("name", key): job for key, job in data["jobs"].items()} + for context in contexts: + self.assertIn(context, jobs) + for step in jobs[context].get("steps", []): + if step.get("uses", "").startswith("actions/checkout@"): + self.assertNotIn("ref", step.get("with", {})) + + def test_group_coverage_is_not_pr_only(self): + coverage = workflow("v2-tests.yml")["jobs"]["coverage"] + self.assertIn("github.event_name == 'merge_group'", coverage["if"]) + self.assertNotIn("issues", coverage.get("permissions", {})) + comment = workflow("v2-tests.yml")["jobs"]["patch-coverage"] + self.assertIn("github.event_name == 'pull_request'", comment["if"]) + self.assertEqual(comment["permissions"]["issues"], "write") + self.assertIn(".coverage-tools/.github/scripts/patch-coverage.sh", + comment["steps"][-1]["run"]) + + def test_owned_gate_uses_trusted_base_not_member_code(self): + data = workflow("native-queue-policy.yml") + events = data.get("on", data.get(True)) + self.assertIn("pull_request_target", events) + self.assertNotIn("pull_request", events) + self.assertTrue(all(value == "read" for value in data["permissions"].values())) + checkout = data["jobs"]["policy"]["steps"][0]["with"] + self.assertEqual(checkout["ref"], + "${{ github.event.merge_group.base_sha || github.event.pull_request.base.sha }}") + self.assertFalse(checkout["persist-credentials"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/scripts/test_pr-auto-update.sh b/.github/scripts/test_pr-auto-update.sh index 77d3f5bce7..1f822d2b58 100644 --- a/.github/scripts/test_pr-auto-update.sh +++ b/.github/scripts/test_pr-auto-update.sh @@ -3,7 +3,8 @@ set -euo pipefail unset GITHUB_STEP_SUMMARY # Capture summaries on stdout, including on GitHub runners. ROOT=$(cd "$(dirname "$0")/../.." && pwd) -TMP=$(mktemp -d) +TMP="$ROOT/.pr-auto-update-test-$$" +mkdir "$TMP" trap 'rm -rf "$TMP"' EXIT mkdir -p "$TMP/bin" export FIXTURE="$TMP" GITHUB_REPOSITORY=example/repo @@ -15,6 +16,15 @@ set -euo pipefail printf '%s\n' "$*" >> "$FIXTURE/calls" [[ "$1" == api ]] || exit 90 shift +if [[ "$1" == graphql ]]; then + [[ "${LOOKUP_FAIL:-}" != queue ]] || exit 1 + number='' + for arg in "$@"; do [[ "$arg" != number=* ]] || number=${arg#number=}; done + enabled=false + for pr in ${QUEUED_PRS:-}; do [[ "$pr" != "$number" ]] || enabled=true; done + printf '%s\t%s\n' "${QUEUE_BASE:-v5}" "$enabled" + exit 0 +fi if [[ "$1" == -X ]]; then number=${3%/update-branch}; number=${number##*/} [[ "$number" != "${FAIL_PR:-}" ]] || { echo "HTTP ${FAIL_CODE:-500}" >&2; exit 1; } @@ -128,6 +138,33 @@ reject 'pulls/1/update-branch' "$TMP/calls" require 'pulls/2/update-branch' "$TMP/calls" reject '/comments?' "$TMP/calls" require 'no changed-file intersection' "$TMP/output" + +# Explicitly opted-in, detected queue bases own freshness on both entry points. +export HIVE_NATIVE_QUEUE_FRESHNESS='example/repo#v5' QUEUED_PRS='1 2' +run +reject 'update-branch' "$TMP/calls" +require 'native queue owns freshness' "$TMP/output" +export SHARED_CI_INCIDENT=42 +run +reject 'update-branch' "$TMP/calls" +require 'native queue owns freshness' "$TMP/output" +# Same repo but a non-queue base or a base outside the allow-list keeps direct mode. +unset QUEUED_PRS +run +require 'pulls/1/update-branch' "$TMP/calls" +export QUEUED_PRS='1 2' QUEUE_BASE=v6 +run +require 'pulls/1/update-branch' "$TMP/calls" +unset QUEUE_BASE +export HIVE_NATIVE_QUEUE_FRESHNESS='another/repo#v5' +run +require 'pulls/1/update-branch' "$TMP/calls" +reject 'graphql' "$TMP/calls" +export HIVE_NATIVE_QUEUE_FRESHNESS='example/repo#v5' LOOKUP_FAIL=queue +if run; then echo 'queue read failure was swallowed' >&2; exit 1; fi +reject 'update-branch' "$TMP/calls" +unset HIVE_NATIVE_QUEUE_FRESHNESS LOOKUP_FAIL QUEUED_PRS SHARED_CI_INCIDENT + export GITHUB_EVENT_BEFORE=0000000000000000000000000000000000000000 run reject 'api ' "$TMP/calls" diff --git a/.github/workflows/go-security-analysis.yml b/.github/workflows/go-security-analysis.yml index 3bd404010a..c8c09925b7 100644 --- a/.github/workflows/go-security-analysis.yml +++ b/.github/workflows/go-security-analysis.yml @@ -46,6 +46,8 @@ name: Go Security Analysis # Same shape as dashboard/openapi.json in v2-tests.yml: guarded by a job whose # filter excluded it. on: + merge_group: + types: [checks_requested] push: branches: [v4, v5, v6] # release PRs touch only these; the required contexts must report — #10795 diff --git a/.github/workflows/native-queue-policy.yml b/.github/workflows/native-queue-policy.yml new file mode 100644 index 0000000000..f15da6cec5 --- /dev/null +++ b/.github/workflows/native-queue-policy.yml @@ -0,0 +1,52 @@ +name: Native queue policy + +on: + pull_request_target: + branches: [v5, v6] + types: [opened, synchronize, reopened, ready_for_review, edited, labeled, unlabeled] + merge_group: + types: [checks_requested] + +permissions: + contents: read + pull-requests: read + checks: read + actions: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.number || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request_target' }} + +jobs: + policy: + name: native-queue-policy + # Read-only, GitHub-hosted: do not run candidate code with write credentials + # or put fork/group policy scripts on a privileged self-hosted runner. + runs-on: ubuntu-latest + timeout-minutes: 25 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # A group's candidates must not supply their own evidence validator. + # PR-target also uses trusted base code, never candidate code. + ref: ${{ github.event.merge_group.base_sha || github.event.pull_request.base.sha }} + persist-credentials: false + - name: Test policy behavior + run: node --test .github/scripts/native-queue-policy.test.cjs + - name: Validate exact-head evidence (bounded wait for PR providers) + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + script: | + const { evaluate, PendingEvidence } = require('./.github/scripts/native-queue-policy.cjs'); + const attempts = 90; + const intervalMs = 15000; + for (let attempt = 0; attempt < attempts; attempt++) { + try { + core.info(await evaluate({github, context})); + return; + } catch (error) { + if (!(error instanceof PendingEvidence) || attempt === attempts - 1) throw error; + core.info(error.message); + await new Promise(resolve => setTimeout(resolve, intervalMs)); + } + } diff --git a/.github/workflows/pr-auto-update-test.yml b/.github/workflows/pr-auto-update-test.yml index 56554de251..aad28295f3 100644 --- a/.github/workflows/pr-auto-update-test.yml +++ b/.github/workflows/pr-auto-update-test.yml @@ -6,12 +6,24 @@ on: - '.github/scripts/pr-auto-update.sh' - '.github/scripts/test_pr-auto-update.sh' - '.github/workflows/pr-auto-update*.yml' + - '.github/scripts/native-queue-policy*.cjs' + - '.github/scripts/test-native-queue-workflows.py' + - '.github/workflows/native-queue-policy.yml' + - '.github/workflows/v2-ci.yml' + - '.github/workflows/v2-tests.yml' + - '.github/workflows/go-security-analysis.yml' push: branches: [v5, v6] paths: - '.github/scripts/pr-auto-update.sh' - '.github/scripts/test_pr-auto-update.sh' - '.github/workflows/pr-auto-update*.yml' + - '.github/scripts/native-queue-policy*.cjs' + - '.github/scripts/test-native-queue-workflows.py' + - '.github/workflows/native-queue-policy.yml' + - '.github/workflows/v2-ci.yml' + - '.github/workflows/v2-tests.yml' + - '.github/workflows/go-security-analysis.yml' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -28,3 +40,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Exercise push and shared-CI incident recovery with mocked APIs run: bash .github/scripts/test_pr-auto-update.sh + - name: Exercise native queue policy with mocked APIs + run: node --test .github/scripts/native-queue-policy.test.cjs + - name: Check native queue workflow contracts + run: python3 .github/scripts/test-native-queue-workflows.py diff --git a/.github/workflows/pr-auto-update.yml b/.github/workflows/pr-auto-update.yml index e4113b9e0a..57310206f6 100644 --- a/.github/workflows/pr-auto-update.yml +++ b/.github/workflows/pr-auto-update.yml @@ -27,4 +27,7 @@ jobs: # A PR's exact marker is the durable record that this issue was a # shared-CI incident; no new label taxonomy is required. SHARED_CI_INCIDENT: ${{ github.event_name == 'issues' && github.event.issue.number || '' }} + # Explicit repo#base allow-list; requires the matching Hive + # skip_current_base_gate opt-in. A live queue is also probed. + HIVE_NATIVE_QUEUE_FRESHNESS: ${{ vars.HIVE_NATIVE_QUEUE_FRESHNESS }} run: .github/scripts/pr-auto-update.sh diff --git a/.github/workflows/v2-ci.yml b/.github/workflows/v2-ci.yml index ed57da8313..a9aa293ca0 100644 --- a/.github/workflows/v2-ci.yml +++ b/.github/workflows/v2-ci.yml @@ -1,6 +1,8 @@ name: v2 CI on: + merge_group: + types: [checks_requested] push: branches: [v4, v5, v6] # bin/** is in scope because the gh wrapper is a SECURITY boundary (it is the diff --git a/.github/workflows/v2-tests.yml b/.github/workflows/v2-tests.yml index d4990a0158..05cbb86e45 100644 --- a/.github/workflows/v2-tests.yml +++ b/.github/workflows/v2-tests.yml @@ -1,6 +1,8 @@ name: v2 Tests on: + merge_group: + types: [checks_requested] schedule: # Hourly, at :30 — deliberately offset from coverage-hourly.yml's :00 run # so the two scheduled nets alternate every half hour instead of firing @@ -49,7 +51,6 @@ on: permissions: contents: read - issues: write env: # The race-enabled shards require cgo even on lean self-hosted runner images. @@ -2004,7 +2005,7 @@ jobs: # still parsed for the two states a profile cannot express: FAIL and # `? ... [no test files]` — both hard failures, as before. coverage: - if: ${{ always() && github.event_name == 'pull_request' && !startsWith(github.head_ref, 'release-gate/') }} + if: ${{ always() && (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'release-gate/'))) }} # Required on v5: keep on the self-hosted pool so a GitHub-hosted runner # outage does not make otherwise-mergeable PRs impossible to merge. runs-on: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && fromJSON(vars.HIVE_RUNNER_LABELS || '["ubuntu-latest"]') || 'ubuntu-latest' }} @@ -2457,8 +2458,29 @@ jobs: fi echo "All packages meet their coverage floor" >> "$GITHUB_STEP_SUMMARY" - - name: Patch coverage on changed Go lines (advisory) - if: ${{ steps.cov-scope.outputs.score == 'true' && github.event_name == 'pull_request' && !cancelled() }} + patch-coverage: + if: ${{ github.event_name == 'pull_request' && needs.coverage.result == 'success' && needs.required-context-scope.outputs.run-tests == 'true' && !cancelled() }} + needs: [coverage, required-context-scope] + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: read + issues: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.pull_request.base.sha }} + path: .coverage-tools + persist-credentials: false + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: test-shard-* + path: shards + merge-multiple: true + - name: Patch coverage on changed Go lines (advisory, trusted base tool) continue-on-error: true env: BASE_REF: ${{ github.base_ref }} @@ -2471,7 +2493,7 @@ jobs: END { print "mode: atomic"; for (key in hits) print key, hits[key] }' \ shards/coverage-*.out > shards/coverage-merged.out 2>/dev/null || true fi - bash .github/scripts/patch-coverage.sh \ + bash .coverage-tools/.github/scripts/patch-coverage.sh \ --base "origin/$BASE_REF" \ --profile shards/coverage-merged.out \ --min-percent 80 --min-uncovered 5 \ diff --git a/changelog.d/added-native-queue-ci-integration.md b/changelog.d/added-native-queue-ci-integration.md new file mode 100644 index 0000000000..05f381eef9 --- /dev/null +++ b/changelog.d/added-native-queue-ci-integration.md @@ -0,0 +1 @@ +- Add native merge-group CI and an owned PR-evidence gate, opt-in external freshness-writer suppression, and native queue configuration visibility with a conservative pilot runbook. diff --git a/src/docs/native-merge-queue.md b/src/docs/native-merge-queue.md index dc7135c314..59998444c2 100644 --- a/src/docs/native-merge-queue.md +++ b/src/docs/native-merge-queue.md @@ -1,5 +1,27 @@ # Native GitHub merge queues +## Composable capabilities, not three merge engines + +1. **Conventional direct merge:** coordinated, per-repo/base preparation + ([#15836](https://github.com/hivecommons/hive/pull/15836)) reduces competing + refresh writers and separates ready seats from pending preparation. It is + independently useful without a native queue. Check that PR's merge and the + deployed version before assuming it is available on a particular hive. +2. **Native GitHub queue:** the admission hand-off shipped in + [#15308](https://github.com/hivecommons/hive/pull/15308). This page describes + the accompanying CI/policy integration. It is per-repository opt-in; + merged code, deployed code, Hive's enabled flag, and GitHub's queue rule + are four different states. Hive controls admission and repair; GitHub is + the sole integration/landing writer. +3. **Integration-aware multi-agent orchestration:** planned coordination + layered on these capabilities, not implemented or selectable here. + +The existing Features settings panel shows native-queue configuration and +links here. Configuration remains in `hive.yaml`; the panel does not change +GitHub rules or activate a queue. Hive's visual train is not GitHub's FIFO +queue. A pending native group can still block later landings, and a queue's +merge limits do **not** combine CI builds or eliminate head-of-line blocking. + ## Opting in The hand-off is **off by default** and opt-in per repository. A hive that @@ -98,6 +120,203 @@ Read and enqueue failures (`native-merge-queue-read`, `-enqueue`) stay at read failure too, not a refusal, and is reported as `native-merge-queue-read`. Required workflows must subscribe to `merge_group` in addition to their PR -triggers. Workflow-trigger diagnosis is not automatic in this implementation. +triggers. `v2-ci.yml`, `v2-tests.yml` and `go-security-analysis.yml` subscribe +to `merge_group: {types: [checks_requested]}`. Their default checkout tests +the synthetic `github.sha`, not a member's head. Group events always select +the full suite/scans, including coverage; the PR-only affected-package and +out-of-scope shortcuts do not apply. Distinct groups use independent run IDs +and cannot cancel each other. Failure issue creation/publishing stays scoped +to its existing push/schedule events; candidate test jobs have read-only +tokens. The coverage reporter's write permissions are job-scoped, not +inherited by group test jobs. + +## Required checks and provider boundaries + +The existing eleven v5 checks cannot simply be required under their old +names on a group SHA. Probot DCO (App **1861**) checks PR commits; GitHub +Actions (App **15368**) cannot legitimately impersonate that provider on a +synthetic commit. PR verifier/changelog/attribution checks also need real PR +metadata, not a fabricated last-member PR event. + +`native-queue-policy.yml` owns the **new** `native-queue-policy` check: + +- On `pull_request_target`, it executes only the trusted base's validator + and waits up to 22.5 minutes for the five existing policy checks on that + exact PR head. No candidate code is executed; tokens are read-only. +- On a group it executes the event's trusted `base_sha` validator. It reads + the live queue prefix ending at the event's exact synthetic head, + verifies contiguous membership and the base/head commit chain, and checks + **every** member, not the PR number encoded in the temporary branch name. + Each current member head must be an ancestor of the synthetic head. +- Every member must have all eleven original check results on its exact + head from the expected App. Actions results additionally bind to their + actual workflow file, event and head through the Actions API, not merely + their check name or a copied commit status. Only technical PR jobs may + carry their existing path-scoped `skipped` result; the five policy proofs + require `success`. No missing, neutral, failed or unavailable evidence is + treated as success. The verifier retains its existing advisory behavior; + this bridge does not turn its underlying implementation into a strict + content validator. +- Draft/closed/held PRs, changes requested, dismissed approvals and approvals + on an old head fail closed. Membership and mutable PR/review state are + re-read before success, and the synthetic ref must still name this group. + Missing/pending evidence has a bounded wait; API errors, inconsistent + membership and untrusted provenance fail the check. A later owner rerun + must read current evidence again; it cannot bless a vanished group. + +Hive's per-head author trust, internal reviewer verdicts, admission approvals, +soak and mutation boundary remain authoritative **before enqueue**. The +bridge does not recreate Hive's private approval store or invent another +reviewer. Admission loss is also reconciled by Hive's App-owned withdrawal; +[#15781](https://github.com/hivecommons/hive/pull/15781) is a rollout +dependency for release-freeze and human-merge-path withdrawal. It is not +included in this implementation. A label/approval/config change after the +final reads can race GitHub landing; neither this check nor periodic +withdrawal is an atomic lock spanning two systems. An urgent stop must +remove entries/disable the GitHub queue, not merely wait for a Hive sweep. + +### Equivalent check mapping (manual migration) + +Do **not** change live protection until the rollout below. The intended v5 +required set is seven contexts, all bound to GitHub Actions App **15368**: + +| Required on PR **and** group | What it enforces | +| --- | --- | +| `native-queue-policy` | PR-head `gate` (`docker.yml`), external `DCO`, `changelog-fragment-guard`, `verify PR contents`, `Sign-off survives the squash`; on groups, all eleven original member-head proofs plus live membership/holds/reviews | +| `build-and-test` | Real synthetic-group build/validation (`v2-ci.yml`) | +| `test` | Real synthetic-group aggregate; fails on missing/failed shards (`v2-tests.yml`) | +| `coverage` | Real synthetic-group shard profiles and unchanged package floors (`v2-tests.yml`) | +| `golangci-lint` | Real synthetic-group lint (`go-security-analysis.yml`) | +| `gosec (insecure patterns)` | Real synthetic-group security analysis | +| `govulncheck (known vulnerabilities)` | Real synthetic-group vulnerability analysis | + +The five replaced names **continue to run on PR heads** and are transitively +required by the new owned check; DCO has not been removed as a logical +requirement or relabeled as an Actions result. Do not retain those five as +direct group requirements without a supported provider implementation: that +would deadlock the queue. Do not add fake success statuses to get past it. +Do not bind `native-queue-policy` to Probot. Any `auto_merge.required_checks` +override must agree with the new required set; original member evidence is +still checked by the bridge. Non-pilot branches retain their current rules. + +## Pilot rollout + +No deployment, repository-variable update, branch-rule mutation or runtime +enablement is performed by this code. An owner must do the following, in order: + +1. Land and deploy #15836 first, and land #15781 plus this integration with + their latest-head CI green. Keep native queue disabled during preparation. + Do not cherry-pick or silently bundle those other branches. A Go fixture + repair on #15836 is independent of this integration. +2. Confirm the trusted base contains the new workflows and validator. Obtain + a real green `native-queue-policy` PR-target run on a disposable v5 PR, + including DCO from App 1861 and all original PR checks. This initial + integration PR cannot demonstrate its new PR-target base workflow until + that workflow exists on v5. Test a multi-member group in a controlled + queue pilot before expanding beyond one member; mocked fixtures are not + proof of GitHub's live membership/commit-chain representation. +3. In repository **Settings → Branches → v5 protection → required status + checks**, first add `native-queue-policy` (GitHub Actions) **alongside** + all eleven old checks. Confirm an ordinary PR passes all twelve. Preserve + every other protection, including `strict=false` and current review + policy; do not broaden bypass actors. Ensure the owner/reviewer workflow + fence protects changes to these trusted workflows/scripts. +4. Configure the external writer's repository Actions variable, initially + inert unless a real queue is detected: + + ```sh + unset GITHUB_TOKEN && gh variable set HIVE_NATIVE_QUEUE_FRESHNESS \ + --repo hivecommons/hive --body 'hivecommons/hive#v5' + ``` + + This is a space-separated, **case-sensitive** `owner/repo#base` allow-list. + Set Hive's repository allow-list to `[hivecommons/hive]` and explicitly + set `skip_current_base_gate: true`, leaving `enabled: false` for now. + The workflow variable alone cannot enable a queue or Hive admission. +5. In **Settings → Branches → v5 protection**, in a single saved rule edit, + enable **Require merge queue** and replace the old eleven-check binding + with the seven-context mapping above, each with expected source + **GitHub Actions**. The new owned gate is already verified and required + before this edit; never remove old bindings first in a separate save. + If the UI/plan cannot express this, stop rather than leave an interval + with incomplete requirements. Use **MERGE** (merge commits), build + concurrency **1**, minimum merge group size **1**, maximum **1** for + the first pilot, and a check timeout exceeding the 25-minute policy job + budget plus runner wait. Keep “only merge non-failing pull requests” + enabled. Build concurrency counts groups, not individual runner jobs. + Do not change rules for v6 or any other repo/base. +6. Only after that GitHub rule is saved, enable Hive: + + ```yaml + auto_merge: + native_merge_queue: + enabled: true + repos: [hivecommons/hive] + skip_current_base_gate: true + probe_ttl: 30m + ``` + + Hive probes actual queues per base; only v5 has a queue in this pilot. + Other bases keep direct merge and coordinated refresh. The absence of a + base allow-list in Hive means the operator must **not** enable a v6 + queue until its separate rollout is ready. Allow for probe-cache expiry + (or a controlled owner restart) before diagnosing stale queue detection. +7. Enqueue one signed, reviewed PR through the App. Record its expected head, + enqueuer, synthetic SHA, all seven group checks, merge method, resulting + commit and issue closure **after actual merge**. Exercise an intentionally + failing check, hold/review withdrawal, and the external updater on both + v5 and a non-queue branch. A queued membership observation is not merge + evidence. Expand concurrency/member count only after the controlled + multi-member test validates every member head and earlier-member failure. + +The safe initial method is **MERGE**, preserving existing commit authors and +their DCO trailers. A repository-wide squash preference does not override +the mixed-authorship guard. Keep existing `merge-method/merge` attribution +decisions; do not rewrite sign-offs or drop authors merely to make admission +green. A queue configured for SQUASH/REBASE can still park mixed-authorship +PRs at `stage/085-needs-decision`. + +### One freshness owner + +`pr-auto-update.sh` normally retains its push file-intersection and +shared-incident recovery behavior. Only an exact allow-listed repo/base +**and** a successful live `isMergeQueueEnabled` probe suppress author-head +updates, including incident recovery. This covers waiting PRs, not just +members already enqueued. A queue-read error in an opted-in repo stops the +writer rather than guessing “direct mode”. Outside that allow-list, or on +a positively detected non-queue base, behavior is unchanged. + +The variable and Hive's explicit `skip_current_base_gate` must be activated +together as above. #15836 owns conventional direct-mode preparation; +GitHub owns opted-in queue freshness. Existing return-to-author repair +handles rejected/broken heads; there is no second fixer or merge engine. + +## Diagnostics and rollback + +- Inspect the PR's exact-head checks and the **group SHA** checks separately. + A green member head does not establish green integration evidence. + `native-queue-policy` logs the failing provider, provenance, membership, + hold or review condition. An unknown/changed GitHub queue schema fails + closed and needs investigation; it is not permission to bypass the gate. +- A group waiting on `DCO` or another old policy name indicates an incomplete + binding migration. A missing build/test/security context indicates workflow + trigger, permission, runner or checkout failure. Read the actual run; + do not infer success from absence. +- A pending GitHub-hosted policy job can delay the queue independently of + self-hosted build capacity. The policy's minimal read token must read + queues, PRs/reviews, check runs and Actions provenance; permission failures + stop validation. Workflow-file push permissions are also required to land + this integration. +- To roll back, first disable new Hive admissions and remove/stop GitHub queue + entries through the owner UI (disabling Hive alone does not stop entries + already owned by GitHub). In one v5 rule edit restore the original eleven + required check bindings and remove **Require merge queue**; preserve all + other protections. Remove `HIVE_NATIVE_QUEUE_FRESHNESS`, restore + `skip_current_base_gate: false`, and leave native admission off. The + external updater resumes only after actual queue detection says false; + clear/expire Hive's probe cache. Conventional coordinated refresh remains + available. No history rewrite is needed. + +Workflow-trigger diagnosis is not automatic in the Hive runtime. See GitHub's [merge queue guide](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue) and [GraphQL pull request reference](https://docs.github.com/en/graphql/reference/pulls). diff --git a/src/pkg/dashboard/api_config_automerge.go b/src/pkg/dashboard/api_config_automerge.go index d07602c54e..3c0d3f9365 100644 --- a/src/pkg/dashboard/api_config_automerge.go +++ b/src/pkg/dashboard/api_config_automerge.go @@ -422,6 +422,12 @@ func autoMergeSectionResponse(cfg *config.Config) map[string]interface{} { "require_current_base_default": am.CurrentBaseDefaultEnabled(), "require_current_base": emptyIfNilStrings(am.RequireCurrentBase), "skip_current_base": emptyIfNilStrings(am.SkipCurrentBase), + "native_merge_queue": map[string]interface{}{ + "enabled": am.NativeMergeQueue.Enabled, + "repos": emptyIfNilStrings(am.NativeMergeQueue.Repos), + "skip_current_base_gate": am.NativeMergeQueue.SkipCurrentBaseGate, + "probe_ttl": am.NativeMergeQueue.EffectiveProbeTTL().String(), + }, "trusted_authors": map[string]interface{}{ "enabled": ta.Enabled, "repos": trustedAuthorRepos, diff --git a/src/pkg/dashboard/native_queue_settings_test.go b/src/pkg/dashboard/native_queue_settings_test.go new file mode 100644 index 0000000000..756347fc3b --- /dev/null +++ b/src/pkg/dashboard/native_queue_settings_test.go @@ -0,0 +1,42 @@ +package dashboard + +import ( + "encoding/json" + "net/http" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" +) + +func TestAutoMergeResponseNativeQueueConfiguration(t *testing.T) { + s := covApiServer(t) + assertQueue := func(enabled, freshness bool, repos int, ttl string) { + t.Helper() + rec := doPut(s, "/api/config/auto-merge", map[string]any{}) + if rec.Code != http.StatusOK { + t.Fatalf("auto-merge PUT: %d: %s", rec.Code, rec.Body.String()) + } + var body struct { + Queue struct { + Enabled bool `json:"enabled"` + Repos []string `json:"repos"` + Freshness bool `json:"skip_current_base_gate"` + TTL string `json:"probe_ttl"` + } `json:"native_merge_queue"` + } + if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil { + t.Fatal(err) + } + q := body.Queue + if q.Enabled != enabled || q.Freshness != freshness || len(q.Repos) != repos || q.TTL != ttl || q.Repos == nil { + t.Fatalf("native queue response: %+v", q) + } + } + assertQueue(false, false, 0, config.DefaultNativeMergeQueueProbeTTL.String()) + s.deps.Config.AutoMerge.NativeMergeQueue = config.NativeMergeQueueAutoMergeConfig{ + Enabled: true, Repos: []string{"hivecommons/hive"}, + SkipCurrentBaseGate: true, ProbeTTL: time.Minute, + } + assertQueue(true, true, 1, time.Minute.String()) +} diff --git a/src/pkg/dashboard/static-src/js/config-features.js b/src/pkg/dashboard/static-src/js/config-features.js index 57154b8833..57177e7a48 100644 --- a/src/pkg/dashboard/static-src/js/config-features.js +++ b/src/pkg/dashboard/static-src/js/config-features.js @@ -476,6 +476,17 @@
Merge only on current base ${yamlHint('auto_merge.require_current_base_default')} ${settingHelpMark('operator-reference', 'app-self-merge-sweep-auto_merge', 'Merge only on current base', `OFF by default. Before auto-merging in any lane, require the PR head to contain the current base tip; a green head tested on an older base is updated with GitHub update-branch and merges once CI is green on the new head. Costs one compare call per merge candidate. Per-repo overrides live on the repo card.`)} +
+ +

Configured: ${am.native_merge_queue && am.native_merge_queue.enabled ? 'enabled' : 'disabled (default)'}. + Repositories: ${esc(((am.native_merge_queue || {}).repos || []).join(', ') || 'all watched repositories once enabled')}. + Queue owns freshness: ${am.native_merge_queue && am.native_merge_queue.skip_current_base_gate ? 'explicitly opted in' : 'no (default)'}. + Probe TTL: ${esc((am.native_merge_queue || {}).probe_ttl || '30m0s')}.

+

Configure these keys in hive.yaml only after the + checks and branch-rule rollout. + Enabled here does not mean deployed or enabled in GitHub. Direct merge with coordinated refresh remains available; this is not Hive's visual train. + Integration-aware multi-agent orchestration is planned, not a selectable implementation.

+
Post review comments ${yamlHint('review.post_comments')} ${settingHelpMark('review-swarm', 'configuration', 'Post review comments', `OFF by default. Reviewers publish their verdict as a PR comment through the hive-review relay, in addition to returning it to the merge queue. Off, the verdict stays internal, which on a hive without auto-merge means nobody reads it. Turn this on so a review reaches the human who has to decide.`)} @@ -1159,4 +1170,3 @@
`)}`; } - diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index a918d7bacd..fa63311163 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -57259,6 +57259,17 @@

${esc(s.title)}

Merge only on current base ${yamlHint('auto_merge.require_current_base_default')} ${settingHelpMark('operator-reference', 'app-self-merge-sweep-auto_merge', 'Merge only on current base', `OFF by default. Before auto-merging in any lane, require the PR head to contain the current base tip; a green head tested on an older base is updated with GitHub update-branch and merges once CI is green on the new head. Costs one compare call per merge candidate. Per-repo overrides live on the repo card.`)} +
+ +

Configured: ${am.native_merge_queue && am.native_merge_queue.enabled ? 'enabled' : 'disabled (default)'}. + Repositories: ${esc(((am.native_merge_queue || {}).repos || []).join(', ') || 'all watched repositories once enabled')}. + Queue owns freshness: ${am.native_merge_queue && am.native_merge_queue.skip_current_base_gate ? 'explicitly opted in' : 'no (default)'}. + Probe TTL: ${esc((am.native_merge_queue || {}).probe_ttl || '30m0s')}.

+

Configure these keys in hive.yaml only after the + checks and branch-rule rollout. + Enabled here does not mean deployed or enabled in GitHub. Direct merge with coordinated refresh remains available; this is not Hive's visual train. + Integration-aware multi-agent orchestration is planned, not a selectable implementation.

+
Post review comments ${yamlHint('review.post_comments')} ${settingHelpMark('review-swarm', 'configuration', 'Post review comments', `OFF by default. Reviewers publish their verdict as a PR comment through the hive-review relay, in addition to returning it to the merge queue. Off, the verdict stays internal, which on a hive without auto-merge means nobody reads it. Turn this on so a review reaches the human who has to decide.`)} @@ -57942,7 +57953,6 @@

${esc(s.title)}

`)}`; } - function markReleaseSentinelList(key, value) { markDirty('release-sentinel', key, splitConfigLines(value)); } From 13abae80127c211e2946f8ce962b65d8f18ba065 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 14:28:45 -0400 Subject: [PATCH 02/14] =?UTF-8?q?=F0=9F=90=9B=20Register=20queue=20policy?= =?UTF-8?q?=20release=20coverage=20and=20exercise=20late=20gate=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/release-lines.yml | 3 ++ .github/scripts/native-queue-policy.test.cjs | 38 +++++++++++++++++-- .../scripts/test-native-queue-workflows.py | 2 + 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/.github/release-lines.yml b/.github/release-lines.yml index 767c6791e3..ff6ec35ba6 100644 --- a/.github/release-lines.yml +++ b/.github/release-lines.yml @@ -121,6 +121,9 @@ pinned: pr-overlap.yml: [v6, -v4] pr-auto-update.yml: [v6, -v4] pr-auto-update-test.yml: [v6, -v4] + # Native queue admission is available on the active feature lines only. + # This is CI coverage, not an opt-in or a queue rule for either branch. + native-queue-policy.yml: [v6, -v4] testutil-guard.yml: [v5, v6] v2-ci.yml: [v5, v6] v2-tests.yml: [v5, v6] diff --git a/.github/scripts/native-queue-policy.test.cjs b/.github/scripts/native-queue-policy.test.cjs index 11144d5e20..c45e231fa1 100644 --- a/.github/scripts/native-queue-policy.test.cjs +++ b/.github/scripts/native-queue-policy.test.cjs @@ -35,12 +35,16 @@ function fixture(eventName = 'merge_group') { const state = { queue: clone(entries), prs: [eligible(1), eligible(2)], seen: [], reviews: [], runs: new Map([1, 2].map(n => [sha(10 + n), checks(sha(10 + n))])), - ancestry: 'ahead', ref: group.head_sha, queueReads: 0, + ancestry: 'ahead', ref: group.head_sha, queueReads: 0, prReads: 0, reviewReads: 0, }; const github = { rest: { checks: { listForRef: 'checks' }, pulls: { - get: async ({ pull_number: n }) => ({ data: clone(state.prs[n - 1]) }), + get: async ({ pull_number: n }) => { + state.prReads++; + if (state.prReads === state.holdOnPRRead) state.prs[n - 1].labels = [{ name: 'hold' }]; + return { data: clone(state.prs[n - 1]) }; + }, listReviews: 'reviews', }, actions: { @@ -64,13 +68,20 @@ function fixture(eventName = 'merge_group') { state.workflowHead = args.ref; return clone(state.runs.get(args.ref)); } + state.reviewReads++; + if (state.reviewReads === state.dismissOnReviewRead) { + state.reviews = [{ id: 2, user: { login: 'reviewer' }, state: 'DISMISSED', commit_id: sha(11) }]; + } return clone(state.reviews); }, - graphql: async () => { + graphql: async (_query, args) => { state.queueReads++; if (state.mutateOnReread && state.queueReads === 2) state.queue[0].pullRequest.headRefOid = sha(99); + const start = Number(args.cursor || 0); + const end = state.pageSize ? start + state.pageSize : state.queue.length; return { repository: { mergeQueue: { entries: { - nodes: clone(state.queue), pageInfo: { hasNextPage: false }, + nodes: clone(state.queue.slice(start, end)), + pageInfo: { hasNextPage: end < state.queue.length, endCursor: String(end) }, } } } }; }, }; @@ -147,6 +158,14 @@ test('group evaluation checks each member head, all evidence, and live synthetic assert.equal(f.state.queueReads, 2); }); +test('membership lookup consumes every page up to this group, not pending successors', async () => { + const f = fixture(); + f.state.pageSize = 1; + f.state.queue.push({ id: 'later', position: 3, headCommit: null, pullRequest: null }); + assert.match(await evaluate(f), /all 2 member heads/); + assert.equal(f.state.queueReads, 4); +}); + test('PR-target admission consumes policy providers without group APIs', async () => { const f = fixture('pull_request_target'); assert.match(await evaluate(f), /five existing policy providers/); @@ -190,6 +209,17 @@ test('changes requested, withdrawn and stale approvals block group validation', } }); +test('late hold or approval withdrawal is caught by the final re-read', async () => { + for (const change of [{ holdOnPRRead: 3 }, { dismissOnReviewRead: 3 }]) { + const f = fixture(); + Object.assign(f.state, change); + await assert.rejects(evaluate(f), /held|approval/); + } + const pr = fixture('pull_request_target'); + pr.state.holdOnPRRead = 2; + await assert.rejects(evaluate(pr), /held/); +}); + test('API failure is never interpreted as an empty successful member list', async () => { const f = fixture(); f.github.graphql = async () => { throw new Error('403 queue read forbidden'); }; diff --git a/.github/scripts/test-native-queue-workflows.py b/.github/scripts/test-native-queue-workflows.py index 9379ea999c..870d3bbb84 100644 --- a/.github/scripts/test-native-queue-workflows.py +++ b/.github/scripts/test-native-queue-workflows.py @@ -57,6 +57,8 @@ def test_owned_gate_uses_trusted_base_not_member_code(self): self.assertEqual(checkout["ref"], "${{ github.event.merge_group.base_sha || github.event.pull_request.base.sha }}") self.assertFalse(checkout["persist-credentials"]) + manifest = yaml.safe_load((ROOT / ".github/release-lines.yml").read_text()) + self.assertEqual(manifest["pinned"]["native-queue-policy.yml"], ["v6", "-v4"]) if __name__ == "__main__": From 3d1006d08f0264161b7eb418cbf431204ba9cd7a Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 14:29:16 -0400 Subject: [PATCH 03/14] =?UTF-8?q?=F0=9F=90=9B=20Provision=20Node=20for=20n?= =?UTF-8?q?ative=20queue=20regression=20tests=20on=20lean=20runners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/workflows/pr-auto-update-test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/pr-auto-update-test.yml b/.github/workflows/pr-auto-update-test.yml index aad28295f3..a63161b96a 100644 --- a/.github/workflows/pr-auto-update-test.yml +++ b/.github/workflows/pr-auto-update-test.yml @@ -40,7 +40,14 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Exercise push and shared-CI incident recovery with mocked APIs run: bash .github/scripts/test_pr-auto-update.sh + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '22' - name: Exercise native queue policy with mocked APIs run: node --test .github/scripts/native-queue-policy.test.cjs + - name: Ensure YAML parser for workflow contracts + run: | + python3 -c 'import yaml' 2>/dev/null && exit 0 + python3 -m pip install --user --break-system-packages 'PyYAML==6.0.3' - name: Check native queue workflow contracts run: python3 .github/scripts/test-native-queue-workflows.py From 0ce49f61e2e19668f7c9db9a064f9cc42632a58a Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 14:37:02 -0400 Subject: [PATCH 04/14] =?UTF-8?q?=F0=9F=90=9B=20Use=20existing=20apt=20YAM?= =?UTF-8?q?L=20setup=20on=20pip-free=20CI=20runners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/workflows/pr-auto-update-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-auto-update-test.yml b/.github/workflows/pr-auto-update-test.yml index a63161b96a..e7feb12680 100644 --- a/.github/workflows/pr-auto-update-test.yml +++ b/.github/workflows/pr-auto-update-test.yml @@ -48,6 +48,8 @@ jobs: - name: Ensure YAML parser for workflow contracts run: | python3 -c 'import yaml' 2>/dev/null && exit 0 - python3 -m pip install --user --break-system-packages 'PyYAML==6.0.3' + # Match v2-ci's lean-runner setup; these images need not carry pip. + sudo apt-get update -qq || true + sudo apt-get install -y -qq python3-yaml - name: Check native queue workflow contracts run: python3 .github/scripts/test-native-queue-workflows.py From 4509bd888a11a25d90118f5757b635da8aefaf1d Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 14:48:41 -0400 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=90=9B=20Bind=20queue=20policy=20ev?= =?UTF-8?q?idence=20to=20workflow=20jobs=20and=20validate=20Dependabot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/scripts/native-queue-policy.cjs | 23 ++++++- .github/scripts/native-queue-policy.test.cjs | 60 ++++++++++++++++++- .../scripts/test-native-queue-workflows.py | 9 +++ .github/workflows/pr-auto-update-test.yml | 2 + .github/workflows/pr-verifier.yml | 1 - src/docs/native-merge-queue.md | 8 ++- 6 files changed, 95 insertions(+), 8 deletions(-) diff --git a/.github/scripts/native-queue-policy.cjs b/.github/scripts/native-queue-policy.cjs index 9f3b245c3e..0818e259c4 100644 --- a/.github/scripts/native-queue-policy.cjs +++ b/.github/scripts/native-queue-policy.cjs @@ -84,6 +84,7 @@ async function assertEvidence(github, repo, number, head, checks) { const runs = await github.paginate(github.rest.checks.listForRef, { ...repo, ref: head, per_page: 100, filter: 'latest', }); + const workflows = new Map(); for (const { run, source } of evidenceForHead(runs, head, checks)) { if (!source) continue; // Probot DCO is deliberately not impersonated. const url = new URL(run.details_url); @@ -92,12 +93,30 @@ async function assertEvidence(github, repo, number, head, checks) { if (url.hostname !== 'github.com' || !/^[0-9]+$/.test(id)) { throw new Error(`Invalid Actions provenance for ${run.name}`); } - const { data: workflow } = await github.rest.actions.getWorkflowRun({ ...repo, run_id: Number(id) }); + const runID = Number(id); + if (!workflows.has(runID)) { + const { data: workflow } = await github.rest.actions.getWorkflowRun({ ...repo, run_id: runID }); + const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, { + ...repo, run_id: runID, per_page: 100, filter: 'latest', + }); + workflows.set(runID, { workflow, jobs }); + } + const { workflow, jobs } = workflows.get(runID); const [file, events] = source; if (workflow.path !== `.github/workflows/${file}` || !events.includes(workflow.event) || - workflow.head_sha !== head) { + workflow.head_sha !== head || workflow.id !== runID) { throw new Error(`Unexpected workflow/event/head for ${run.name} on #${number}`); } + // details_url is only a locator. The API-owned suite and job identities + // must independently bind this exact check run to the expected workflow. + const checkURL = `https://api.github.com/repos/${repo.owner}/${repo.repo}/check-runs/${run.id}`; + if (!Number.isSafeInteger(run.check_suite?.id) || + run.check_suite.id !== workflow.check_suite_id || + !jobs.some(job => job.run_id === runID && job.name === run.name && + job.head_sha === head && job.check_run_url === checkURL && + job.status === 'completed' && job.conclusion === run.conclusion)) { + throw new Error(`Check suite/job identity mismatch for ${run.name} on #${number}`); + } } } diff --git a/.github/scripts/native-queue-policy.test.cjs b/.github/scripts/native-queue-policy.test.cjs index c45e231fa1..b3661bcd74 100644 --- a/.github/scripts/native-queue-policy.test.cjs +++ b/.github/scripts/native-queue-policy.test.cjs @@ -27,7 +27,8 @@ function checks(head, definitions = { ...POLICY_CHECKS, ...BUILD_CHECKS }) { return Object.entries(definitions).map(([name, source], index) => ({ id: 100 + index, name, head_sha: head, status: 'completed', conclusion: 'success', app: { id: source ? ACTIONS_APP_ID : DCO_APP_ID }, - details_url: `https://github.com/acme/widget/actions/runs/${100 + index}/job/1`, + check_suite: { id: 10000 + index }, + details_url: `https://github.com/acme/widget/actions/runs/${1000 + index}/job/1`, })); } @@ -48,10 +49,12 @@ function fixture(eventName = 'merge_group') { listReviews: 'reviews', }, actions: { + listJobsForWorkflowRun: 'jobs', getWorkflowRun: async ({ run_id: id }) => { - const definition = [...Object.entries(POLICY_CHECKS), ...Object.entries(BUILD_CHECKS)][id - 100]; + const definition = [...Object.entries(POLICY_CHECKS), ...Object.entries(BUILD_CHECKS)][id - 1000]; const source = definition[1]; return { data: { + id, check_suite_id: id + 9000, path: state.badWorkflow || `.github/workflows/${source[0]}`, event: source[1][0], head_sha: state.workflowHead, } }; @@ -64,6 +67,15 @@ function fixture(eventName = 'merge_group') { git: { getRef: async () => ({ data: { object: { sha: state.ref } } }) }, }, paginate: async (method, args) => { + if (method === 'jobs') { + const index = args.run_id - 1000; + const [name] = [...Object.entries(POLICY_CHECKS), ...Object.entries(BUILD_CHECKS)][index]; + return [{ + id: 100000 + index, run_id: args.run_id, name, head_sha: state.workflowHead, + check_run_url: `https://api.github.com/repos/acme/widget/check-runs/${100 + index}`, + status: 'completed', conclusion: 'success', + }]; + } if (method === 'checks') { state.workflowHead = args.ref; return clone(state.runs.get(args.ref)); @@ -181,6 +193,50 @@ test('untrusted events and workflow provenance are rejected', async () => { await assert.rejects(evaluate(g), /Unexpected workflow/); }); +test('copied expected-run URL/name cannot substitute a foreign check suite or check identity', async () => { + for (const change of [ + { id: 999, check_suite: { id: 99999 } }, + { id: 999 }, // Even a claimed matching suite cannot replace actual job membership. + { check_suite: null }, + ]) { + const f = fixture('pull_request_target'); + const gate = f.state.runs.get(sha(11)).find(r => r.name === 'gate'); + Object.assign(gate, change); + await assert.rejects(evaluate(f), /suite\/job identity mismatch/); + } +}); + +test('expected workflow suite alone does not accept a wrong job head, name or conclusion', async () => { + for (const change of [ + { head_sha: sha(99) }, { name: 'another job' }, { conclusion: 'failure' }, + { run_id: 99999 }, { status: 'in_progress' }, + ]) { + const f = fixture('pull_request_target'); + const paginate = f.github.paginate; + f.github.paginate = async (method, args) => { + const results = await paginate(method, args); + return method === 'jobs' ? results.map(job => ({ ...job, ...change })) : results; + }; + await assert.rejects(evaluate(f), /suite\/job identity mismatch/); + } +}); + +test('Dependabot PR-target events require an actual successful verifier, never a skipped proof', async () => { + for (const conclusion of ['success', 'skipped', 'failure']) { + const f = fixture('pull_request_target'); + f.context.actor = 'dependabot[bot]'; + f.context.payload.sender = { login: 'dependabot[bot]', type: 'Bot' }; + f.context.payload.pull_request.user = clone(f.context.payload.sender); + f.state.prs[0].user = clone(f.context.payload.sender); + f.state.runs.get(sha(11)).find(r => r.name === 'verify PR contents').conclusion = conclusion; + if (conclusion === 'success') { + assert.match(await evaluate(f), /five existing policy providers/); + } else { + await assert.rejects(evaluate(f), /verify PR contents/); + } + } +}); + test('earlier member failure blocks the whole group', async () => { const f = fixture(); f.state.runs.get(sha(11)).find(r => r.name === 'DCO').conclusion = 'failure'; diff --git a/.github/scripts/test-native-queue-workflows.py b/.github/scripts/test-native-queue-workflows.py index 870d3bbb84..e93334d7fe 100644 --- a/.github/scripts/test-native-queue-workflows.py +++ b/.github/scripts/test-native-queue-workflows.py @@ -60,6 +60,15 @@ def test_owned_gate_uses_trusted_base_not_member_code(self): manifest = yaml.safe_load((ROOT / ".github/release-lines.yml").read_text()) self.assertEqual(manifest["pinned"]["native-queue-policy.yml"], ["v6", "-v4"]) + def test_dependabot_runs_the_same_trusted_pr_verifier(self): + verifier = workflow("pr-verifier.yml") + events = verifier.get("on", verifier.get(True)) + self.assertIn("opened", events["pull_request_target"]["types"]) + job = verifier["jobs"]["verify"] + self.assertNotIn("if", job) + self.assertEqual(job["name"], "verify PR contents") + self.assertIn("docker run --rm", job["steps"][-1]["run"]) + if __name__ == "__main__": unittest.main() diff --git a/.github/workflows/pr-auto-update-test.yml b/.github/workflows/pr-auto-update-test.yml index e7feb12680..d7db616760 100644 --- a/.github/workflows/pr-auto-update-test.yml +++ b/.github/workflows/pr-auto-update-test.yml @@ -12,6 +12,7 @@ on: - '.github/workflows/v2-ci.yml' - '.github/workflows/v2-tests.yml' - '.github/workflows/go-security-analysis.yml' + - '.github/workflows/pr-verifier.yml' push: branches: [v5, v6] paths: @@ -24,6 +25,7 @@ on: - '.github/workflows/v2-ci.yml' - '.github/workflows/v2-tests.yml' - '.github/workflows/go-security-analysis.yml' + - '.github/workflows/pr-verifier.yml' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} diff --git a/.github/workflows/pr-verifier.yml b/.github/workflows/pr-verifier.yml index e296ce3387..a3137bdea6 100644 --- a/.github/workflows/pr-verifier.yml +++ b/.github/workflows/pr-verifier.yml @@ -16,7 +16,6 @@ permissions: jobs: verify: name: verify PR contents - if: github.actor != 'dependabot[bot]' # Required on v5: keep on the self-hosted pool so a GitHub-hosted runner # outage does not make otherwise-mergeable PRs impossible to merge. # Fork PRs still fall back to GitHub-hosted for pull_request_target safety. diff --git a/src/docs/native-merge-queue.md b/src/docs/native-merge-queue.md index 59998444c2..0e5a093fe8 100644 --- a/src/docs/native-merge-queue.md +++ b/src/docs/native-merge-queue.md @@ -150,13 +150,15 @@ metadata, not a fabricated last-member PR event. Each current member head must be an ancestor of the synthetic head. - Every member must have all eleven original check results on its exact head from the expected App. Actions results additionally bind to their - actual workflow file, event and head through the Actions API, not merely - their check name or a copied commit status. Only technical PR jobs may + actual workflow file, event, head, matching check-suite ID and exact job's + `check_run_url` through the Actions API. A copied `details_url` or check + name is not proof of membership in that workflow. Only technical PR jobs may carry their existing path-scoped `skipped` result; the five policy proofs require `success`. No missing, neutral, failed or unavailable evidence is treated as success. The verifier retains its existing advisory behavior; this bridge does not turn its underlying implementation into a strict - content validator. + content validator. Dependabot runs that same trusted PR-target verifier + rather than skipping it; skipped policy evidence is never exempted by actor. - Draft/closed/held PRs, changes requested, dismissed approvals and approvals on an old head fail closed. Membership and mutable PR/review state are re-read before success, and the synthetic ref must still name this group. From f01d119072a10c728da74a668670529e15944052 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 15:13:49 -0400 Subject: [PATCH 06/14] =?UTF-8?q?=F0=9F=90=9B=20Add=20native=20queue=20con?= =?UTF-8?q?figuration=20help=20tooltip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- src/pkg/dashboard/static-src/js/config-features.js | 2 +- src/pkg/dashboard/static/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkg/dashboard/static-src/js/config-features.js b/src/pkg/dashboard/static-src/js/config-features.js index 57177e7a48..7db566d45c 100644 --- a/src/pkg/dashboard/static-src/js/config-features.js +++ b/src/pkg/dashboard/static-src/js/config-features.js @@ -477,7 +477,7 @@ Merge only on current base ${yamlHint('auto_merge.require_current_base_default')} ${settingHelpMark('operator-reference', 'app-self-merge-sweep-auto_merge', 'Merge only on current base', `OFF by default. Before auto-merging in any lane, require the PR head to contain the current base tip; a green head tested on an older base is updated with GitHub update-branch and merges once CI is green on the new head. Costs one compare call per merge candidate. Per-repo overrides live on the repo card.`)}
- +

Configured: ${am.native_merge_queue && am.native_merge_queue.enabled ? 'enabled' : 'disabled (default)'}. Repositories: ${esc(((am.native_merge_queue || {}).repos || []).join(', ') || 'all watched repositories once enabled')}. Queue owns freshness: ${am.native_merge_queue && am.native_merge_queue.skip_current_base_gate ? 'explicitly opted in' : 'no (default)'}. diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index fa63311163..54f7c44dd7 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -57260,7 +57260,7 @@

${esc(s.title)}

Merge only on current base ${yamlHint('auto_merge.require_current_base_default')} ${settingHelpMark('operator-reference', 'app-self-merge-sweep-auto_merge', 'Merge only on current base', `OFF by default. Before auto-merging in any lane, require the PR head to contain the current base tip; a green head tested on an older base is updated with GitHub update-branch and merges once CI is green on the new head. Costs one compare call per merge candidate. Per-repo overrides live on the repo card.`)}
- +

Configured: ${am.native_merge_queue && am.native_merge_queue.enabled ? 'enabled' : 'disabled (default)'}. Repositories: ${esc(((am.native_merge_queue || {}).repos || []).join(', ') || 'all watched repositories once enabled')}. Queue owns freshness: ${am.native_merge_queue && am.native_merge_queue.skip_current_base_gate ? 'explicitly opted in' : 'no (default)'}. From ad7ba5200ea3e7cdce111257f58c51ffb31103be Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 20:49:55 -0400 Subject: [PATCH 07/14] =?UTF-8?q?=E2=9C=A8=20Expose=20guarded=20native=20q?= =?UTF-8?q?ueue=20settings=20with=20exact=20base=20scope?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .../scripts/native-queue-settings.test.cjs | 53 +++++++++ .github/workflows/pr-auto-update-test.yml | 10 +- .../added-native-queue-ci-integration.md | 2 +- src/cmd/hive/main_sweeps.go | 2 +- src/docs/native-merge-queue.md | 26 ++++- .../automerge_native_merge_queue_test.go | 14 +++ src/pkg/config/config.go | 19 ++++ src/pkg/dashboard/api_config_automerge.go | 105 +++++++++++++++++- .../native_queue_settings_mutation_test.go | 75 +++++++++++++ .../dashboard/native_queue_settings_test.go | 1 + .../static-src/js/config-features.js | 22 +++- .../dashboard/static-src/js/config-helpers.js | 11 ++ .../static-src/js/linear-repos-save.js | 1 + src/pkg/dashboard/static/index.html | 34 +++++- .../automerge/automerge_native_queue.go | 10 +- .../automerge/automerge_native_queue_test.go | 23 ++++ 16 files changed, 386 insertions(+), 22 deletions(-) create mode 100644 .github/scripts/native-queue-settings.test.cjs create mode 100644 src/pkg/dashboard/native_queue_settings_mutation_test.go diff --git a/.github/scripts/native-queue-settings.test.cjs b/.github/scripts/native-queue-settings.test.cjs new file mode 100644 index 0000000000..5c33c878e1 --- /dev/null +++ b/.github/scripts/native-queue-settings.test.cjs @@ -0,0 +1,53 @@ +'use strict'; +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); + +function settings() { + const context = { _configState: { dirty: {}, data: { auto_merge: {} } } }; + vm.createContext(context); + vm.runInContext(fs.readFileSync(path.join(__dirname, + '../../src/pkg/dashboard/static-src/js/config-helpers.js'), 'utf8'), context); + return context; +} + +test('native queue staging preserves partial fields and never silently enables', () => { + const context = settings(); + context.markDirtyNativeQueue('repos', ' HiveCommons/Hive, acme/widget '); + context.markDirtyNativeQueue('bases', 'hivecommons/hive#v5, acme/widget#Release/V5'); + context.markDirtyNativeQueue('probe_ttl', '5m'); + const staged = JSON.parse(JSON.stringify(context._configState.dirty['auto-merge'].native_merge_queue)); + assert.deepEqual(staged, { + repos: ['HiveCommons/Hive', 'acme/widget'], + bases: ['hivecommons/hive#v5', 'acme/widget#Release/V5'], probe_ttl: '5m', + }); + assert.equal(context._configState.data.auto_merge.native_merge_queue, undefined); +}); + +test('native queue enable and disable stage owner policy without dropping scope', () => { + const context = settings(); + const classes = new Set(); + const attributes = {}; + const element = { + dataset: {}, + classList: { + contains: key => classes.has(key), + toggle(key) { if (classes.delete(key)) return false; classes.add(key); return true; }, + }, + setAttribute: (key, value) => { attributes[key] = value; }, + }; + context.markDirtyNativeQueue('bases', 'hivecommons/hive#v5'); + context.toggleConfigSwitch(element, 'native-queue', 'enabled'); + assert.equal(context._configState.dirty['auto-merge'].native_merge_queue.enabled, true); + assert.equal(attributes['aria-checked'], 'true'); + context.toggleConfigSwitch(element, 'native-queue', 'enabled'); + const staged = context._configState.dirty['auto-merge'].native_merge_queue; + assert.equal(staged.enabled, false); + assert.equal(staged.bases[0], 'hivecommons/hive#v5'); + assert.equal(attributes['aria-checked'], 'false'); + element.dataset.disabled = 'true'; + context.toggleConfigSwitch(element, 'native-queue', 'enabled'); + assert.equal(staged.enabled, false); +}); diff --git a/.github/workflows/pr-auto-update-test.yml b/.github/workflows/pr-auto-update-test.yml index d7db616760..737899a9bf 100644 --- a/.github/workflows/pr-auto-update-test.yml +++ b/.github/workflows/pr-auto-update-test.yml @@ -6,7 +6,9 @@ on: - '.github/scripts/pr-auto-update.sh' - '.github/scripts/test_pr-auto-update.sh' - '.github/workflows/pr-auto-update*.yml' - - '.github/scripts/native-queue-policy*.cjs' + - '.github/scripts/native-queue-*.cjs' + - 'src/pkg/dashboard/static-src/js/config-helpers.js' + - 'src/pkg/dashboard/static-src/js/config-features.js' - '.github/scripts/test-native-queue-workflows.py' - '.github/workflows/native-queue-policy.yml' - '.github/workflows/v2-ci.yml' @@ -19,7 +21,9 @@ on: - '.github/scripts/pr-auto-update.sh' - '.github/scripts/test_pr-auto-update.sh' - '.github/workflows/pr-auto-update*.yml' - - '.github/scripts/native-queue-policy*.cjs' + - '.github/scripts/native-queue-*.cjs' + - 'src/pkg/dashboard/static-src/js/config-helpers.js' + - 'src/pkg/dashboard/static-src/js/config-features.js' - '.github/scripts/test-native-queue-workflows.py' - '.github/workflows/native-queue-policy.yml' - '.github/workflows/v2-ci.yml' @@ -46,7 +50,7 @@ jobs: with: node-version: '22' - name: Exercise native queue policy with mocked APIs - run: node --test .github/scripts/native-queue-policy.test.cjs + run: node --test .github/scripts/native-queue-policy.test.cjs .github/scripts/native-queue-settings.test.cjs - name: Ensure YAML parser for workflow contracts run: | python3 -c 'import yaml' 2>/dev/null && exit 0 diff --git a/changelog.d/added-native-queue-ci-integration.md b/changelog.d/added-native-queue-ci-integration.md index 05f381eef9..6a2c6e1569 100644 --- a/changelog.d/added-native-queue-ci-integration.md +++ b/changelog.d/added-native-queue-ci-integration.md @@ -1 +1 @@ -- Add native merge-group CI and an owned PR-evidence gate, opt-in external freshness-writer suppression, and native queue configuration visibility with a conservative pilot runbook. +- Add native merge-group CI and an owned PR-evidence gate, opt-in external freshness-writer suppression, and default-off owner Settings controls with validated repository/base scope and a conservative pilot runbook. diff --git a/src/cmd/hive/main_sweeps.go b/src/cmd/hive/main_sweeps.go index ab95b8e83e..dc4516166c 100644 --- a/src/cmd/hive/main_sweeps.go +++ b/src/cmd/hive/main_sweeps.go @@ -855,7 +855,7 @@ func runAutoMergeSweepIfDue(ctx context.Context, ghClient *github.Client, cfg *c opts.TrustedBotAuthors = func() map[string]bool { return cfg.AutoMerge.TrustedBotAuthorSet() } opts.NativeMergeQueue = func() automerge.NativeMergeQueuePolicy { q := cfg.AutoMerge.NativeMergeQueue - return automerge.NativeMergeQueuePolicy{Enabled: q.Enabled, Repos: q.RepoSet(), SkipCurrentBaseGate: q.SkipCurrentBaseGate, ProbeTTL: q.EffectiveProbeTTL()} + return automerge.NativeMergeQueuePolicy{Enabled: q.Enabled, Repos: q.RepoSet(), Bases: q.BaseSet(), SkipCurrentBaseGate: q.SkipCurrentBaseGate, ProbeTTL: q.EffectiveProbeTTL()} } } audit := func(event automerge.AutoMergeSweepEvent) { diff --git a/src/docs/native-merge-queue.md b/src/docs/native-merge-queue.md index 4dd34bc461..097bd5f233 100644 --- a/src/docs/native-merge-queue.md +++ b/src/docs/native-merge-queue.md @@ -34,6 +34,7 @@ auto_merge: native_merge_queue: enabled: true # default false repos: [hivecommons/hive] # owner/repo allow-list; empty = every watched repo + bases: [hivecommons/hive#v5] # exact repo#base pairs; branch case is significant skip_current_base_gate: false # default false — see "Current-base gate" below probe_ttl: 30m # default 30m — see "API cost" below ``` @@ -42,9 +43,27 @@ auto_merge: | --- | --- | --- | | `auto_merge.native_merge_queue.enabled` | `false` | Turns the native-queue hand-off on. | | `auto_merge.native_merge_queue.repos` | unset (every watched repo once enabled) | `owner/repo` allow-list, matched case-insensitively. Repos outside it keep the pre-queue behaviour. | +| `auto_merge.native_merge_queue.bases` | unset (all queue bases in opted-in repos) | Additional exact `owner/repo#base` allow-list. Branch names are case-sensitive. Unlisted bases never enqueue or bypass current-base refresh. | | `auto_merge.native_merge_queue.skip_current_base_gate` | `false` | Lets a queue-enabled base bypass the `auto_merge.require_current_base` gate and the `behind` update-branch. Off keeps both gates in force on queue bases. | | `auto_merge.native_merge_queue.probe_ttl` | `30m` | How long one base branch's `isMergeQueueEnabled` answer is reused before it is re-read. | +Owners can configure the same policy at **Settings → Features → Auto-Merge → +Native GitHub merge queue**, then click **Save**. The enable switch and +“Queue owns freshness” switch are both **OFF by default**. Repositories, +exact repository/base pairs, and the queue-detection TTL are editable there. +Settings refuses enabling without both explicit scope lists, rejects malformed +or wildcard scopes, mismatched repositories and negative/invalid durations, +and preserves omitted fields on partial updates. `0` TTL uses the 30-minute +default. Existing YAML configurations retain their original unscoped semantics +when the optional lists are absent; the Settings enable path deliberately +requires explicit scope. + +Saving changes the Hive policy only: it does **not** create a GitHub queue, +change branch protection, set the external freshness variable, deploy code or +attest that prerequisites are satisfied. Follow the pilot rollout below first. +Disabling does not drain existing GitHub queue entries: drain or withdraw them +before rollback. Trust/review/hold/CI/soak and attribution gates remain intact. + ## How it works Automerge sweeps detect a PR's target queue with GraphQL @@ -254,14 +273,15 @@ enablement is performed by this code. An owner must do the following, in order: native_merge_queue: enabled: true repos: [hivecommons/hive] + bases: [hivecommons/hive#v5] skip_current_base_gate: true probe_ttl: 30m ``` Hive probes actual queues per base; only v5 has a queue in this pilot. - Other bases keep direct merge and coordinated refresh. The absence of a - base allow-list in Hive means the operator must **not** enable a v6 - queue until its separate rollout is ready. Allow for probe-cache expiry + Other bases keep direct merge and coordinated refresh because they are + outside the explicit base allow-list. Do **not** enable a v6 queue until + its separate rollout is ready. Allow for probe-cache expiry (or a controlled owner restart) before diagnosing stale queue detection. 7. Enqueue one signed, reviewed PR through the App. Record its expected head, enqueuer, synthetic SHA, all seven group checks, merge method, resulting diff --git a/src/pkg/config/automerge_native_merge_queue_test.go b/src/pkg/config/automerge_native_merge_queue_test.go index f51faf9f33..35e3da18b8 100644 --- a/src/pkg/config/automerge_native_merge_queue_test.go +++ b/src/pkg/config/automerge_native_merge_queue_test.go @@ -7,6 +7,20 @@ import ( "gopkg.in/yaml.v3" ) +func TestNativeQueueBaseSetPreservesBranchIdentity(t *testing.T) { + if (NativeMergeQueueAutoMergeConfig{}).BaseSet() != nil { + t.Fatal("unset bases must preserve legacy YAML semantics") + } + q := NativeMergeQueueAutoMergeConfig{Bases: []string{" Acme/Widget#Release/V5 ", "malformed"}} + bases := q.BaseSet() + if !bases["acme/widget#Release/V5"] || bases["acme/widget#release/v5"] || len(bases) != 1 { + t.Fatalf("base scopes: %+v", bases) + } + if (NativeMergeQueueAutoMergeConfig{Bases: []string{"invalid"}}).BaseSet() == nil { + t.Fatal("invalid explicit scope must not become an unrestricted policy") + } +} + func TestNativeMergeQueueAutoMergeConfigIsOptInPerRepo(t *testing.T) { tests := []struct { name string diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index 395e65afd5..adeb1c5f01 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -8355,6 +8355,10 @@ type NativeMergeQueueAutoMergeConfig struct { // Repos restricts the hand-off to these repositories (owner/repo, // case-insensitive). Empty means every watched repository once Enabled. Repos []string `yaml:"repos,omitempty" json:"repos,omitempty"` + // Bases further restricts hand-off to exact owner/repo#base pairs. + // Repository names are case-insensitive; branch names are case-sensitive. + // Empty preserves the original all-queue-bases behaviour for YAML users. + Bases []string `yaml:"bases,omitempty" json:"bases,omitempty"` // SkipCurrentBaseGate lets a queue-enabled base bypass the // auto_merge.require_current_base gate and the behind update-branch, // because the merge group re-tests the merged result and a new head @@ -8377,6 +8381,21 @@ func (n NativeMergeQueueAutoMergeConfig) RepoSet() map[string]bool { return repoListSet(n.Repos) } +// BaseSet preserves branch case while normalizing repository identity. +func (n NativeMergeQueueAutoMergeConfig) BaseSet() map[string]bool { + if len(n.Bases) == 0 { + return nil + } + set := make(map[string]bool, len(n.Bases)) + for _, scope := range n.Bases { + repo, base, ok := strings.Cut(strings.TrimSpace(scope), "#") + if ok && repo != "" && base != "" { + set[strings.ToLower(repo)+"#"+base] = true + } + } + return set +} + // EnabledFor reports whether repo (owner/repo, matched case-insensitively) // may hand PRs to a native merge queue: Enabled and either no allow-list or // listed in it. diff --git a/src/pkg/dashboard/api_config_automerge.go b/src/pkg/dashboard/api_config_automerge.go index 3c0d3f9365..d810f551d2 100644 --- a/src/pkg/dashboard/api_config_automerge.go +++ b/src/pkg/dashboard/api_config_automerge.go @@ -1,7 +1,9 @@ package dashboard import ( + "fmt" "net/http" + "regexp" "sort" "strings" "time" @@ -141,12 +143,13 @@ func (s *Server) handleAutoMergePut(w http.ResponseWriter, r *http.Request) { return } var body struct { - SelfAuthored *bool `json:"self_authored"` - MaxMerges *int `json:"max_merges"` - MinHeadAge *string `json:"min_head_age"` - RequiredChecks []string `json:"required_checks"` - AllowUnprotectedBase []string `json:"allow_unprotected_base"` - NoCIOK []string `json:"no_ci_ok"` + NativeMergeQueue *nativeQueueSettingsPatch `json:"native_merge_queue"` + SelfAuthored *bool `json:"self_authored"` + MaxMerges *int `json:"max_merges"` + MinHeadAge *string `json:"min_head_age"` + RequiredChecks []string `json:"required_checks"` + AllowUnprotectedBase []string `json:"allow_unprotected_base"` + NoCIOK []string `json:"no_ci_ok"` // TrustedBotAuthors is the FULL desired list; an empty (non-nil) list // disables the trusted-bot lane, absent leaves it untouched. TrustedBotAuthors []string `json:"trusted_bot_authors"` @@ -183,6 +186,11 @@ func (s *Server) handleAutoMergePut(w http.ResponseWriter, r *http.Request) { } // --- validate before mutating anything --- + nativeQueue, err := updateNativeQueueSettings(s.deps.Config.AutoMerge.NativeMergeQueue, body.NativeMergeQueue) + if err != nil { + jsonError(w, err.Error(), http.StatusBadRequest) + return + } if body.MaxMerges != nil && *body.MaxMerges < 0 { jsonError(w, "max_merges must be 0 (default) or greater", http.StatusBadRequest) return @@ -261,6 +269,10 @@ func (s *Server) handleAutoMergePut(w http.ResponseWriter, r *http.Request) { // --- apply --- cfg := s.deps.Config + previousAutoMerge := cfg.AutoMerge + if body.NativeMergeQueue != nil { + cfg.AutoMerge.NativeMergeQueue = nativeQueue + } if body.SelfAuthored != nil { v := *body.SelfAuthored cfg.AutoMerge.SelfAuthored = &v @@ -357,6 +369,12 @@ func (s *Server) handleAutoMergePut(w http.ResponseWriter, r *http.Request) { if err := s.saveConfig(); err != nil { s.logger.Error("failed to persist config after auto-merge update", "error", err) + if body.NativeMergeQueue != nil { + cfg.AutoMerge = previousAutoMerge + syncAutoMergePolicyToGitHubClient(cfg, s.deps.GHClient) + jsonError(w, "failed to persist native queue settings", http.StatusInternalServerError) + return + } } s.auditFromRequest(r, "config_auto_merge", auditDetail("section", "auto_merge"), "") @@ -425,6 +443,7 @@ func autoMergeSectionResponse(cfg *config.Config) map[string]interface{} { "native_merge_queue": map[string]interface{}{ "enabled": am.NativeMergeQueue.Enabled, "repos": emptyIfNilStrings(am.NativeMergeQueue.Repos), + "bases": emptyIfNilStrings(am.NativeMergeQueue.Bases), "skip_current_base_gate": am.NativeMergeQueue.SkipCurrentBaseGate, "probe_ttl": am.NativeMergeQueue.EffectiveProbeTTL().String(), }, @@ -453,6 +472,80 @@ func autoMergeSectionResponse(cfg *config.Config) map[string]interface{} { } } +type nativeQueueSettingsPatch struct { + Enabled *bool `json:"enabled"` + Repos []string `json:"repos"` + Bases []string `json:"bases"` + SkipCurrentBaseGate *bool `json:"skip_current_base_gate"` + ProbeTTL *string `json:"probe_ttl"` +} + +var nativeQueueRepoPattern = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-]*/[a-zA-Z0-9_.-]+$`) +var nativeQueueBasePattern = regexp.MustCompile(`^[a-zA-Z0-9_][a-zA-Z0-9_./-]*$`) + +func updateNativeQueueSettings(current config.NativeMergeQueueAutoMergeConfig, patch *nativeQueueSettingsPatch) (config.NativeMergeQueueAutoMergeConfig, error) { + if patch == nil { + return current, nil + } + next := current + if patch.Enabled != nil { + next.Enabled = *patch.Enabled + } + if patch.SkipCurrentBaseGate != nil { + next.SkipCurrentBaseGate = *patch.SkipCurrentBaseGate + } + if patch.ProbeTTL != nil { + ttl, err := time.ParseDuration(strings.TrimSpace(*patch.ProbeTTL)) + if err != nil || ttl < 0 { + return current, fmt.Errorf("native_merge_queue.probe_ttl must be a non-negative duration (0 uses 30m)") + } + next.ProbeTTL = ttl + } + if patch.Repos != nil { + for _, repo := range patch.Repos { + repo = strings.TrimSpace(repo) + if !nativeQueueRepoPattern.MatchString(repo) || strings.HasSuffix(repo, "/.") || strings.HasSuffix(repo, "/..") { + return current, fmt.Errorf("native_merge_queue.repos must contain exact owner/repo names") + } + } + next.Repos = normalizeAutoMergeRepoList(patch.Repos) + } + if patch.Bases != nil { + next.Bases = make([]string, 0, len(patch.Bases)) + seen := map[string]bool{} + for _, scope := range patch.Bases { + repo, base, ok := strings.Cut(strings.TrimSpace(scope), "#") + if !ok || !nativeQueueRepoPattern.MatchString(repo) || !nativeQueueBasePattern.MatchString(base) || + strings.Contains(base, "..") || strings.Contains(base, "//") || strings.HasSuffix(base, "/") || strings.HasSuffix(base, ".") { + return current, fmt.Errorf("native_merge_queue.bases must contain exact owner/repo#base pairs (no wildcards)") + } + for _, part := range strings.Split(base, "/") { + if strings.HasPrefix(part, ".") || strings.HasSuffix(part, ".lock") { + return current, fmt.Errorf("native_merge_queue.bases contains an invalid branch name") + } + } + key := strings.ToLower(repo) + "#" + base + if !seen[key] { + next.Bases = append(next.Bases, key) + seen[key] = true + } + } + } + // Disabling always remains possible, including legacy unscoped YAML. + if next.Enabled { + if len(next.Repos) == 0 || len(next.Bases) == 0 { + return current, fmt.Errorf("enabling native merge queue in Settings requires explicit repositories and owner/repo#base pairs") + } + for _, scope := range next.Bases { + repo, _, _ := strings.Cut(scope, "#") + if !next.RepoSet()[strings.ToLower(repo)] { + return current, fmt.Errorf("native_merge_queue.bases repository must also appear in repos") + } + } + } + return next, nil +} + func syncAutoMergePolicyToGitHubClient(cfg *config.Config, ghClient *ghpkg.Client) { if cfg == nil || ghClient == nil { return diff --git a/src/pkg/dashboard/native_queue_settings_mutation_test.go b/src/pkg/dashboard/native_queue_settings_mutation_test.go new file mode 100644 index 0000000000..6048d60d48 --- /dev/null +++ b/src/pkg/dashboard/native_queue_settings_mutation_test.go @@ -0,0 +1,75 @@ +package dashboard + +import ( + "net/http" + "net/http/httptest" + "reflect" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" +) + +func TestNativeQueueSettingsUpdatesAndValidation(t *testing.T) { + s := covApiServer(t) + put := func(patch map[string]any, status int) { + t.Helper() + rec := doPut(s, "/api/config/auto-merge", map[string]any{"native_merge_queue": patch}) + if rec.Code != status { + t.Fatalf("PUT: %d want %d: %s", rec.Code, status, rec.Body.String()) + } + } + put(map[string]any{ + "enabled": true, "repos": []string{"HiveCommons/Hive"}, + "bases": []string{"HiveCommons/Hive#v5", "hivecommons/hive#v5"}, + "probe_ttl": "5m", "skip_current_base_gate": true, + }, http.StatusOK) + q := s.deps.Config.AutoMerge.NativeMergeQueue + if !q.Enabled || !q.SkipCurrentBaseGate || q.ProbeTTL != 5*time.Minute || + !reflect.DeepEqual(q.Bases, []string{"hivecommons/hive#v5"}) { + t.Fatalf("saved queue: %+v", q) + } + put(map[string]any{"probe_ttl": "0"}, http.StatusOK) + if got := s.deps.Config.AutoMerge.NativeMergeQueue; !got.Enabled || !got.SkipCurrentBaseGate || got.EffectiveProbeTTL() != config.DefaultNativeMergeQueueProbeTTL || !reflect.DeepEqual(got.Bases, q.Bases) { + t.Fatalf("partial update lost settings: %+v", got) + } + for _, invalid := range []map[string]any{ + {"repos": []string{}}, {"bases": []string{}}, {"repos": []string{"*"}}, + {"bases": []string{"hivecommons/hive#*"}}, {"bases": []string{"hivecommons/other#v5"}}, + {"bases": []string{"hivecommons/hive#../v5"}}, {"bases": []string{"hivecommons/hive#v5.lock"}}, + {"probe_ttl": "-1m"}, {"probe_ttl": "invalid"}, {"bases": []string{"v5"}}, + } { + before := s.deps.Config.AutoMerge.NativeMergeQueue + put(invalid, http.StatusBadRequest) + if !reflect.DeepEqual(before, s.deps.Config.AutoMerge.NativeMergeQueue) { + t.Fatalf("invalid update mutated config: %+v", invalid) + } + } + put(map[string]any{"enabled": false}, http.StatusOK) + if s.deps.Config.AutoMerge.NativeMergeQueue.Enabled { + t.Fatal("disable failed") + } + s.deps.Config.AutoMerge.NativeMergeQueue = config.NativeMergeQueueAutoMergeConfig{} + put(map[string]any{"enabled": true}, http.StatusBadRequest) +} + +func TestNativeQueueSettingsOwnerOnlyAndPersistenceFailure(t *testing.T) { + s := covApiServer(t) + req := httptest.NewRequest(http.MethodPut, "/api/config/auto-merge", strings.NewReader(`{"native_merge_queue":{"enabled":true}}`)) + req.Header.Set("X-Hive-Role", config.RoleReadWrite) + rec := httptest.NewRecorder() + s.handleAutoMergePut(rec, req) + if rec.Code != http.StatusForbidden || s.deps.Config.AutoMerge.NativeMergeQueue.Enabled { + t.Fatalf("non-owner update: %d", rec.Code) + } + // Fail the save guard before any file writes. + s.deps.Config.SourcePath = "unwritten-native-queue-settings.yaml" + s.deps.Config.Project.Org = "" + rec = doPut(s, "/api/config/auto-merge", map[string]any{"native_merge_queue": map[string]any{ + "enabled": true, "repos": []string{"hivecommons/hive"}, "bases": []string{"hivecommons/hive#v5"}, + }}) + if rec.Code != http.StatusInternalServerError || s.deps.Config.AutoMerge.NativeMergeQueue.Enabled { + t.Fatalf("unpersisted queue change was accepted: %d: %s", rec.Code, rec.Body.String()) + } +} diff --git a/src/pkg/dashboard/native_queue_settings_test.go b/src/pkg/dashboard/native_queue_settings_test.go index 756347fc3b..96d61ba3e3 100644 --- a/src/pkg/dashboard/native_queue_settings_test.go +++ b/src/pkg/dashboard/native_queue_settings_test.go @@ -17,6 +17,7 @@ func TestAutoMergeResponseNativeQueueConfiguration(t *testing.T) { if rec.Code != http.StatusOK { t.Fatalf("auto-merge PUT: %d: %s", rec.Code, rec.Body.String()) } + var body struct { Queue struct { Enabled bool `json:"enabled"` diff --git a/src/pkg/dashboard/static-src/js/config-features.js b/src/pkg/dashboard/static-src/js/config-features.js index b768af1085..f540cecfa8 100644 --- a/src/pkg/dashboard/static-src/js/config-features.js +++ b/src/pkg/dashboard/static-src/js/config-features.js @@ -478,14 +478,30 @@ Merge only on current base ${yamlHint('auto_merge.require_current_base_default')} ${settingHelpMark('operator-reference', 'app-self-merge-sweep-auto_merge', 'Merge only on current base', `OFF by default. Before auto-merging in any lane, require the PR head to contain the current base tip; a green head tested on an older base is updated with GitHub update-branch and merges once CI is green on the new head. Costs one compare call per merge candidate. Per-repo overrides live on the repo card.`)}

- + +
+
+ Enable native GitHub merge queue (default OFF) ${settingHelpMark('native-merge-queue', 'pilot-rollout', 'Enable native GitHub merge queue', `Operator opt-in only after the GitHub prerequisites below. Save applies the Hive hand-off policy; it does not create queues or change branch protection. Off preserves conventional direct merge on branches without a required queue; a queue-required branch remains parked, never bypassed.`)} +
+ + + + +
+
+ Queue owns freshness (default OFF) ${settingHelpMark('native-merge-queue', 'current-base-gate', 'Queue owns freshness', `Explicitly bypasses current-base and behind refresh only for opted-in repo/base pairs with an actual GitHub queue. Leave off until merge-group CI is proven and HIVE_NATIVE_QUEUE_FRESHNESS suppresses the external branch updater for the same pairs. Other branches retain coordinated refresh.`)} +
+ +

Configured: ${am.native_merge_queue && am.native_merge_queue.enabled ? 'enabled' : 'disabled (default)'}. Repositories: ${esc(((am.native_merge_queue || {}).repos || []).join(', ') || 'all watched repositories once enabled')}. + Bases: ${esc(((am.native_merge_queue || {}).bases || []).join(', ') || 'all queue bases (legacy YAML only)')}. Queue owns freshness: ${am.native_merge_queue && am.native_merge_queue.skip_current_base_gate ? 'explicitly opted in' : 'no (default)'}. Probe TTL: ${esc((am.native_merge_queue || {}).probe_ttl || '30m0s')}.

-

Configure these keys in hive.yaml only after the +

Owner-only: stage these controls and click Save only after the checks and branch-rule rollout. - Enabled here does not mean deployed or enabled in GitHub. Direct merge with coordinated refresh remains available; this is not Hive's visual train. + Prerequisites: App installation authentication, withdrawal guards, trusted-base policy proof, equivalent required-check migration, MERGE method and a bounded pilot group. + Enabled here does not mean deployed or enabled in GitHub. Turning it off does not disable GitHub's queue or withdraw existing entries; drain those before rollback. Direct merge with coordinated refresh remains available; this is not Hive's visual train. Integration-aware multi-agent orchestration is planned, not a selectable implementation.

diff --git a/src/pkg/dashboard/static-src/js/config-helpers.js b/src/pkg/dashboard/static-src/js/config-helpers.js index 407f9531c6..395ae8cfaa 100644 --- a/src/pkg/dashboard/static-src/js/config-helpers.js +++ b/src/pkg/dashboard/static-src/js/config-helpers.js @@ -7,10 +7,21 @@ function toggleConfigSwitch(el, section, key) { if (!el || el.classList.contains('disabled') || el.dataset.disabled === 'true') return; const isOn = el.classList.toggle('on'); + if (section === 'native-queue') { + el.setAttribute('aria-checked', String(isOn)); + markDirtyNativeQueue(key, isOn); + return; + } markDirty(section, key, isOn); if (section === 'review' && (key === 'fan_out' || key === 'combined_perspectives')) refreshReviewerAgentSummary(); } + function markDirtyNativeQueue(key, value) { + if (key === 'repos' || key === 'bases') value = String(value).split(',').map(s => s.trim()).filter(Boolean); + const staged = ((_configState.dirty || {})['auto-merge'] || {}).native_merge_queue || {}; + markDirty('auto-merge', 'native_merge_queue', Object.assign({}, staged, { [key]: value })); + } + // Review label gate (Settings → Features → Review Gate → "Only review // labelled PRs"): the toggle shows/hides the label input; the saved value // is review.require_labels, where an empty list means off. diff --git a/src/pkg/dashboard/static-src/js/linear-repos-save.js b/src/pkg/dashboard/static-src/js/linear-repos-save.js index 8aea52a3d3..8f6b4071bd 100644 --- a/src/pkg/dashboard/static-src/js/linear-repos-save.js +++ b/src/pkg/dashboard/static-src/js/linear-repos-save.js @@ -757,6 +757,7 @@ body: JSON.stringify(values) }); if (!amRes.ok) throw new Error(await saveErrorMessage(amRes)); + _configState.data.auto_merge = await amRes.json().catch(() => _configState.data.auto_merge); } else if (_configState.type === 'governor' && section === 'sla') { // sla is a TOP-LEVEL config block (Delivery SLA targets); it // saves through its own owner-only /api/config/sla endpoint. diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 5a17a308ab..bdf8456507 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -58197,14 +58197,30 @@

${esc(s.title)}

Merge only on current base ${yamlHint('auto_merge.require_current_base_default')} ${settingHelpMark('operator-reference', 'app-self-merge-sweep-auto_merge', 'Merge only on current base', `OFF by default. Before auto-merging in any lane, require the PR head to contain the current base tip; a green head tested on an older base is updated with GitHub update-branch and merges once CI is green on the new head. Costs one compare call per merge candidate. Per-repo overrides live on the repo card.`)}
- + +
+
+ Enable native GitHub merge queue (default OFF) ${settingHelpMark('native-merge-queue', 'pilot-rollout', 'Enable native GitHub merge queue', `Operator opt-in only after the GitHub prerequisites below. Save applies the Hive hand-off policy; it does not create queues or change branch protection. Off preserves conventional direct merge on branches without a required queue; a queue-required branch remains parked, never bypassed.`)} +
+ + + + +
+
+ Queue owns freshness (default OFF) ${settingHelpMark('native-merge-queue', 'current-base-gate', 'Queue owns freshness', `Explicitly bypasses current-base and behind refresh only for opted-in repo/base pairs with an actual GitHub queue. Leave off until merge-group CI is proven and HIVE_NATIVE_QUEUE_FRESHNESS suppresses the external branch updater for the same pairs. Other branches retain coordinated refresh.`)} +
+ +

Configured: ${am.native_merge_queue && am.native_merge_queue.enabled ? 'enabled' : 'disabled (default)'}. Repositories: ${esc(((am.native_merge_queue || {}).repos || []).join(', ') || 'all watched repositories once enabled')}. + Bases: ${esc(((am.native_merge_queue || {}).bases || []).join(', ') || 'all queue bases (legacy YAML only)')}. Queue owns freshness: ${am.native_merge_queue && am.native_merge_queue.skip_current_base_gate ? 'explicitly opted in' : 'no (default)'}. Probe TTL: ${esc((am.native_merge_queue || {}).probe_ttl || '30m0s')}.

-

Configure these keys in hive.yaml only after the +

Owner-only: stage these controls and click Save only after the checks and branch-rule rollout. - Enabled here does not mean deployed or enabled in GitHub. Direct merge with coordinated refresh remains available; this is not Hive's visual train. + Prerequisites: App installation authentication, withdrawal guards, trusted-base policy proof, equivalent required-check migration, MERGE method and a bounded pilot group. + Enabled here does not mean deployed or enabled in GitHub. Turning it off does not disable GitHub's queue or withdraw existing entries; drain those before rollback. Direct merge with coordinated refresh remains available; this is not Hive's visual train. Integration-aware multi-agent orchestration is planned, not a selectable implementation.

@@ -60355,10 +60371,21 @@

${esc(s.title)}

function toggleConfigSwitch(el, section, key) { if (!el || el.classList.contains('disabled') || el.dataset.disabled === 'true') return; const isOn = el.classList.toggle('on'); + if (section === 'native-queue') { + el.setAttribute('aria-checked', String(isOn)); + markDirtyNativeQueue(key, isOn); + return; + } markDirty(section, key, isOn); if (section === 'review' && (key === 'fan_out' || key === 'combined_perspectives')) refreshReviewerAgentSummary(); } + function markDirtyNativeQueue(key, value) { + if (key === 'repos' || key === 'bases') value = String(value).split(',').map(s => s.trim()).filter(Boolean); + const staged = ((_configState.dirty || {})['auto-merge'] || {}).native_merge_queue || {}; + markDirty('auto-merge', 'native_merge_queue', Object.assign({}, staged, { [key]: value })); + } + // Review label gate (Settings → Features → Review Gate → "Only review // labelled PRs"): the toggle shows/hides the label input; the saved value // is review.require_labels, where an empty list means off. @@ -61808,6 +61835,7 @@

${esc(s.title)}

body: JSON.stringify(values) }); if (!amRes.ok) throw new Error(await saveErrorMessage(amRes)); + _configState.data.auto_merge = await amRes.json().catch(() => _configState.data.auto_merge); } else if (_configState.type === 'governor' && section === 'sla') { // sla is a TOP-LEVEL config block (Delivery SLA targets); it // saves through its own owner-only /api/config/sla endpoint. diff --git a/src/pkg/github/automerge/automerge_native_queue.go b/src/pkg/github/automerge/automerge_native_queue.go index a762e9bbcf..adf2961e62 100644 --- a/src/pkg/github/automerge/automerge_native_queue.go +++ b/src/pkg/github/automerge/automerge_native_queue.go @@ -45,6 +45,8 @@ type NativeMergeQueuePolicy struct { // Repos is the lower-cased owner/repo allow-list; empty means every // watched repository once Enabled. Repos map[string]bool + // Bases is an optional exact repo#base allow-list, preserving branch case. + Bases map[string]bool // SkipCurrentBaseGate lets a queue-enabled base bypass the // require_current_base gate and the behind update-branch. Off keeps // both gates in force exactly as on any other base. @@ -71,6 +73,10 @@ func (p NativeMergeQueuePolicy) probeTTL() time.Duration { return p.ProbeTTL } +func (p NativeMergeQueuePolicy) baseAllowed(repo, base string) bool { + return p.repoAllowed(repo) && (p.Bases == nil || p.Bases[strings.ToLower(strings.TrimSpace(repo))+"#"+base]) +} + // nativeQueueProbe is one cached isMergeQueueEnabled answer for a base. type nativeQueueProbe struct { enabled bool @@ -164,7 +170,7 @@ func nativeQueueWithdrawReason(reason string) bool { // behaviour. func (c *Engine) nativeQueueEnabled(ctx context.Context, repo string, pr *gh.PullRequest) bool { t := c.nativeQueue(repo) - if t == nil || pr.GetNodeID() == "" { + if t == nil || pr.GetNodeID() == "" || !c.nativeQueuePolicy().baseAllowed(repo, pr.GetBase().GetRef()) { return false } key := nativeQueueProbeKey(repo, pr) @@ -223,7 +229,7 @@ func (c *Engine) nativeQueue(repo string) nativeQueueTransport { // queued PR is not a merged PR: no merged audit, issue closure or merge event. func (c *Engine) tryNativeQueue(ctx context.Context, pr *gh.PullRequest, claim effects.Claim) (string, error) { t := c.nativeQueue(claim.Repo) - if t == nil || pr.GetNodeID() == "" { + if t == nil || pr.GetNodeID() == "" || !c.nativeQueuePolicy().baseAllowed(claim.Repo, pr.GetBase().GetRef()) { return "", nil } key := nativeQueueProbeKey(claim.Repo, pr) diff --git a/src/pkg/github/automerge/automerge_native_queue_test.go b/src/pkg/github/automerge/automerge_native_queue_test.go index 2a7cf38156..292ccdb1da 100644 --- a/src/pkg/github/automerge/automerge_native_queue_test.go +++ b/src/pkg/github/automerge/automerge_native_queue_test.go @@ -546,6 +546,7 @@ func TestNativeQueueIsOptInPerRepo(t *testing.T) { case "listed-repo": enableNativeQueue(c, NativeMergeQueuePolicy{Enabled: true, Repos: map[string]bool{"acme/widget": true}}) } + reason, err := c.tryNativeQueue(context.Background(), pr, claim) c.reconcileNativeQueueGate(context.Background(), stageLaneSelf, "acme", "widget", pr, "held") enabled := c.nativeQueueEnabled(context.Background(), "acme/widget", pr) @@ -562,6 +563,28 @@ func TestNativeQueueIsOptInPerRepo(t *testing.T) { } } +func TestNativeQueueBaseScopeControlsEnqueueAndFreshness(t *testing.T) { + for _, base := range []string{"v5", "v6", "V5"} { + t.Run(base, func(t *testing.T) { + c, f, pr, claim := nativeQueueEngine() + pr.Base = &gh.PullRequestBranch{Ref: gh.Ptr(base)} + enableNativeQueue(c, NativeMergeQueuePolicy{ + Enabled: true, Repos: map[string]bool{"acme/widget": true}, + Bases: map[string]bool{"acme/widget#v5": true}, SkipCurrentBaseGate: true, + }) + reason, err := c.tryNativeQueue(context.Background(), pr, claim) + freshness := c.nativeQueueSkipsCurrentBase(context.Background(), claim.Repo, pr) + if base == "v5" { + if err != nil || reason == "" || f.enqueues != 1 || !freshness { + t.Fatalf("pilot base not admitted: %q %v enqueues=%d freshness=%v", reason, err, f.enqueues, freshness) + } + } else if err != nil || reason != "" || f.enqueues != 0 || freshness { + t.Fatalf("unlisted base admitted: %q %v enqueues=%d freshness=%v", reason, err, f.enqueues, freshness) + } + }) + } +} + type countingNativeQueueFake struct { *nativeQueueFake reads *int From cd26d28f320107d77c4cd69e8efb27384e5e8cb2 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 21:05:32 -0400 Subject: [PATCH 08/14] =?UTF-8?q?=E2=9C=A8=20Visualize=20native=20merge=20?= =?UTF-8?q?queue=20observations=20in=20Activity=20Tracker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/scripts/native-queue-tracker.test.cjs | 110 ++++++ .github/workflows/pr-auto-update-test.yml | 4 +- .../added-native-queue-ci-integration.md | 2 +- src/cmd/hive/main_eval_cycle.go | 7 + src/docs/native-merge-queue.md | 52 +++ src/pkg/dashboard/api_github_webhook.go | 1 + src/pkg/dashboard/server.go | 1 + src/pkg/dashboard/stage_tracker.go | 12 +- src/pkg/dashboard/stage_tracker_build.go | 1 + .../dashboard/stage_tracker_native_queue.go | 321 +++++++++++++++++ .../stage_tracker_native_queue_test.go | 121 +++++++ .../static-src/css/tracker-native-queue.css | 8 + .../dashboard/static-src/html/tracker.html | 1 + .../static-src/js/tracker-filter-render.js | 2 + .../static-src/js/tracker-native-queue.js | 81 +++++ src/pkg/dashboard/static-src/manifest.txt | 2 + src/pkg/dashboard/static/index.html | 92 +++++ src/pkg/forgequeue/observation.go | 66 ++++ src/pkg/github/native_queue_observation.go | 325 ++++++++++++++++++ .../github/native_queue_observation_test.go | 131 +++++++ 20 files changed, 1333 insertions(+), 7 deletions(-) create mode 100644 .github/scripts/native-queue-tracker.test.cjs create mode 100644 src/pkg/dashboard/stage_tracker_native_queue.go create mode 100644 src/pkg/dashboard/stage_tracker_native_queue_test.go create mode 100644 src/pkg/dashboard/static-src/css/tracker-native-queue.css create mode 100644 src/pkg/dashboard/static-src/js/tracker-native-queue.js create mode 100644 src/pkg/forgequeue/observation.go create mode 100644 src/pkg/github/native_queue_observation.go create mode 100644 src/pkg/github/native_queue_observation_test.go diff --git a/.github/scripts/native-queue-tracker.test.cjs b/.github/scripts/native-queue-tracker.test.cjs new file mode 100644 index 0000000000..61b9690812 --- /dev/null +++ b/.github/scripts/native-queue-tracker.test.cjs @@ -0,0 +1,110 @@ +'use strict'; +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); + +const now = Date.parse('2026-10-30T12:10:00Z'); +const context = { URL, esc: value => String(value).replace(/[&<>"']/g, c => ({ + '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', +})[c]) }; +vm.createContext(context); +vm.runInContext(fs.readFileSync(path.join(__dirname, + '../../src/pkg/dashboard/static-src/js/tracker-native-queue.js'), 'utf8'), context); +const row = { kind: 'pr', repo: 'o/r', number: 7, head: 'member-head', base_ref: 'v5' }; +const queue = () => ({ + provider: 'github-native', repo: 'o/r', base: 'v5', state: 'observed', complete: true, + observed_at: '2026-10-30T12:09:00Z', fresh_for_s: 360, + entries: [{ id: 'entry', position: 3, pr: 7, head: 'member-head', state: 'AWAITING_CHECKS', enqueued_at: '2026-10-30T12:00:00Z' }], + candidates: [], outcomes: [], +}); +const render = (q, items = [row], page = items, repo = '') => + context.stageTrackerNativeQueueHtml([q], items, page, now, repo); + +test('real queue position, state and provider age never invent pipeline progress', () => { + const q = queue(); + const before = JSON.stringify([q, row]); + const html = render(q); + assert.match(html, /value="3"/); + assert.match(html, /AWAITING_CHECKS/); + assert.match(html, /queued 10m/); + assert.match(html, /on this page/); + assert.match(html, /Enqueue is not testing or merge completion/); + assert.doesNotMatch(html, /data-ham-key|[0-9]+%|ETA [0-9]/); + assert.equal(JSON.stringify([q, row]), before); +}); + +test('unknown, stale, unavailable and partial snapshots cannot claim empty current success', () => { + const q = queue(); + q.entries = []; + q.complete = false; + q.stale = true; + q.state = 'unavailable'; + const html = render(q); + assert.match(html, /STALE/); + assert.match(html, /coverage incomplete/); + assert.match(html, /does not prove an empty queue/); + assert.match(render({ ...queue(), observed_at: '2026-10-30T10:00:00Z' }), /STALE/); +}); + +test('unknown member mapping never trusts a FIFO member list or PR-head green', () => { + const q = queue(); + q.entries = []; + q.candidates = [{ sha: 'synthetic-only', membership: 'unknown', members: [{ pr: 999, head: 'unproved' }], ci: 'unknown', checks: [] }]; + const html = render(q); + assert.match(html, /Member mapping unknown/); + assert.match(html, /synthetic-only/); + assert.doesNotMatch(html, /#999|unproved/); + assert.match(html, /never copied from PR heads/); +}); + +test('parallel candidate cards retain exact members and exact candidate CI drilldown', () => { + const q = queue(); + q.candidates = ['candidate-one', 'candidate-two'].map((sha, i) => ({ + sha, base_sha: 'base-sha', tree: 'tree-' + i, membership: 'proven', + members: [{ pr: 7, head: row.head }], ci: i ? 'failed' : 'pending', checks_known: true, + checks: [{ name: 'test-' + i, status: i ? 'completed' : 'in_progress', conclusion: i ? 'failure' : '', url: 'https://github.com/o/r/actions/runs/' + i }], + })); + const html = render(q, [row], []); + assert.equal((html.match(/
/g) || []).length, 2); + assert.match(html, /Candidate required CI: pending/); + assert.match(html, /Candidate required CI: failed/); + assert.match(html, /outside current page\/filters/); + assert.match(html, /https:\/\/github.com\/o\/r\/actions\/runs\/1/); + assert.match(render(q, [{ ...row, head: 'new-head' }]), /outside tracker snapshot or head changed/); +}); + +test('repo filters, unknown age, bounded outcomes and safe links remain explicit', () => { + const q = queue(); + assert.equal(render(q, [], [], 'other/repo'), ''); + assert.equal(context.stageTrackerNativeAge('invalid', now), 'age unknown'); + q.outcomes = [ + { kind: 'entry-removed', pr: 7, head: 'old', source: 'snapshot-difference', observed_at: q.observed_at }, + { kind: 'merged', pr: 8, merge_sha: 'actual-merge', source: 'signed-merged-webhook', observed_at: q.observed_at }, + ]; + const html = render(q); + assert.match(html, /entry-removed/); + assert.match(html, /actual-merge/); + assert.match(html, /Removal\/destroyed is not proof/); + assert.match(html, /gaps after restart/); + assert.equal(context.stageTrackerNativeLink('javascript:invalid', 'check'), 'check'); +}); + +test('DOM synchronization only updates its own rail and preserves linked pipeline trees', () => { + const root = { hidden: true }; + const requested = []; + context.document = { getElementById: id => { requested.push(id); return root; } }; + context.setIfChanged = (element, html) => { assert.equal(element, root); root.html = html; }; + const linked = { kind: 'issue', repo: 'o/r', number: 42, linked_prs: [{ ...row }] }; + const data = { integration_queues: [queue()], items: [linked] }; + const page = [{ item: linked }]; + const before = JSON.stringify([data, page]); + context.stageTrackerNativeQueueSync(data, page, now, 'O/R'); + assert.equal(root.hidden, false); + assert.match(root.html, /on this page/); + assert.deepEqual(requested, ['activity-monitor-native-queue']); + assert.equal(JSON.stringify([data, page]), before); + context.stageTrackerNativeQueueSync({}, [], now, ''); + assert.equal(root.hidden, true); +}); diff --git a/.github/workflows/pr-auto-update-test.yml b/.github/workflows/pr-auto-update-test.yml index 737899a9bf..acf6e3c6ab 100644 --- a/.github/workflows/pr-auto-update-test.yml +++ b/.github/workflows/pr-auto-update-test.yml @@ -9,6 +9,7 @@ on: - '.github/scripts/native-queue-*.cjs' - 'src/pkg/dashboard/static-src/js/config-helpers.js' - 'src/pkg/dashboard/static-src/js/config-features.js' + - 'src/pkg/dashboard/static-src/js/tracker-native-queue.js' - '.github/scripts/test-native-queue-workflows.py' - '.github/workflows/native-queue-policy.yml' - '.github/workflows/v2-ci.yml' @@ -24,6 +25,7 @@ on: - '.github/scripts/native-queue-*.cjs' - 'src/pkg/dashboard/static-src/js/config-helpers.js' - 'src/pkg/dashboard/static-src/js/config-features.js' + - 'src/pkg/dashboard/static-src/js/tracker-native-queue.js' - '.github/scripts/test-native-queue-workflows.py' - '.github/workflows/native-queue-policy.yml' - '.github/workflows/v2-ci.yml' @@ -50,7 +52,7 @@ jobs: with: node-version: '22' - name: Exercise native queue policy with mocked APIs - run: node --test .github/scripts/native-queue-policy.test.cjs .github/scripts/native-queue-settings.test.cjs + run: node --test .github/scripts/native-queue-policy.test.cjs .github/scripts/native-queue-settings.test.cjs .github/scripts/native-queue-tracker.test.cjs - name: Ensure YAML parser for workflow contracts run: | python3 -c 'import yaml' 2>/dev/null && exit 0 diff --git a/changelog.d/added-native-queue-ci-integration.md b/changelog.d/added-native-queue-ci-integration.md index 6a2c6e1569..f7e8569048 100644 --- a/changelog.d/added-native-queue-ci-integration.md +++ b/changelog.d/added-native-queue-ci-integration.md @@ -1 +1 @@ -- Add native merge-group CI and an owned PR-evidence gate, opt-in external freshness-writer suppression, and default-off owner Settings controls with validated repository/base scope and a conservative pilot runbook. +- Add native merge-group CI and an owned PR-evidence gate, opt-in external freshness-writer suppression, default-off scoped owner Settings controls, and a distinct Activity Tracker rail backed by bounded provider-neutral observations of actual GitHub queue entries, exact candidate CI, proven-or-unknown members and lifecycle receipts. diff --git a/src/cmd/hive/main_eval_cycle.go b/src/cmd/hive/main_eval_cycle.go index 90474d6a7e..557b640da0 100644 --- a/src/cmd/hive/main_eval_cycle.go +++ b/src/cmd/hive/main_eval_cycle.go @@ -939,6 +939,13 @@ func runEvalCycle( // policy, dashboard status, PR/review dispatch, escalation, and every path // not explicitly enrolled. kickActionable := applyConvergenceKickAdmission(cfg, dashSrv, actionable, notifier, logger) + if cfg.AutoMerge.NativeMergeQueue.Enabled { + go func() { + if err := dashSrv.ReconcileNativeQueues(ctx); err != nil { + logger.Warn("native queue observations incomplete", "error", err) + } + }() + } if err := dashSrv.ReconcileIntegration(ctx); err != nil { logger.Warn("integration observations incomplete", "error", err) } diff --git a/src/docs/native-merge-queue.md b/src/docs/native-merge-queue.md index 097bd5f233..0b6dbf75a5 100644 --- a/src/docs/native-merge-queue.md +++ b/src/docs/native-merge-queue.md @@ -64,6 +64,58 @@ attest that prerequisites are satisfied. Follow the pilot rollout below first. Disabling does not drain existing GitHub queue entries: drain or withdraw them before rollback. Trust/review/hold/CI/soak and attribution gates remain intact. +## Activity Tracker: observed operation, not a second merge engine + +When enabled, **Activity Tracker → Forge-owned merge queues → GitHub merge +queue** is a separate region beside the preparation rail, outside actual +pipeline rows. It displays provider-observed entry positions, exact PR heads, +provider states and enqueue ages. Readiness/preparation, native admission, +candidate testing and an actual merged receipt are different states. +Linked issue/PR trees are not reparented or duplicated into pipeline rows; +references say whether that exact repository/PR/head/base is on the page, +outside its filters/page, or absent/changed. Repository filtering applies to +the native rail; its references are not silently dropped by row pagination. + +Candidate cards identify actual `merge_group` synthetic refs and SHAs from +authenticated events or Actions runs. **Membership is unknown** unless a signed +event base, the live queue chain, every exact member head's ancestry and a final +unchanged synthetic-ref read all agree. FIFO positions and PR numbers embedded +in ref names are never membership proof. Several observed candidates can appear +in parallel. The CI drilldown reads only the candidate SHA, including required +check names, status, conclusion, producer binding and available job links; it +never substitutes green PR-head checks. Classic protection and applicable rules +must both be readable before required policy is known. Missing/pending/skipped +checks or unreadable policy are never portrayed as passing. + +The provider-neutral `forgequeue.Observation` contract is read-only and carries +no admission or merge authority. The GitHub adapter feeds an in-memory cache +from the existing governor cycle, at most once per three minutes, rotating +across two scopes per pass with one 45-second background budget. Each scope +reads at most 100 entries and 100 workflow runs; at most four recent candidate +cards and eight member ancestry checks per card are observed. Larger/incomplete +cohorts explicitly report partial coverage rather than implied completeness. +There are no per-render or per-PR observation pollers; OFF performs no +observation API reads. Evidence older than six minutes is explicitly stale; +failed refreshes retain older evidence with unavailable/stale diagnostics. +More than two configured scopes can therefore be stale while rotation catches +up. Observations need App installation read access to queues, Actions, +checks/statuses, contents and branch policy (including Administration read for +classic protection). Verify those permissions explicitly; enqueue permissions +alone do not establish this visibility. Unavailable authentication +or permissions are reported, not silently substituted with configured checks. + +Authenticated `merge_group` deliveries retain candidate identities and +`destroyed` receipts. Complete consecutive entry snapshots can establish an entry's +removal, **not its reason**. Only an authenticated merged-PR delivery for a +previously observed exact queued/member head records a merged receipt and its +actual merge SHA. Failed required CI is shown on that candidate; moved/expired +refs do not prove failure, rebuild or merge. No rebuild reason, percentage or ETA +is invented. The last 32 lifecycle receipts and 16 event hints are memory-bounded, +not an exhaustive durable audit: missed deliveries and restart gaps remain +explicit. Configure delivery of `merge_group` and `pull_request` events to the +existing authenticated webhook endpoint for full event evidence; discovery +without a signed group base intentionally leaves member mapping unknown. + ## How it works Automerge sweeps detect a PR's target queue with GraphQL diff --git a/src/pkg/dashboard/api_github_webhook.go b/src/pkg/dashboard/api_github_webhook.go index 2ed1d49a8f..f6ab79c8b1 100644 --- a/src/pkg/dashboard/api_github_webhook.go +++ b/src/pkg/dashboard/api_github_webhook.go @@ -105,6 +105,7 @@ func (s *Server) handleGitHubWebhook(w http.ResponseWriter, r *http.Request) { jsonResponse(w, map[string]any{"status": "ignored", "reason": "unknown repository", "event": event}) return } + s.observeNativeQueueEvent(event, body, receivedAt) if err := s.observeIntegrationWebhook(event, r.Header.Get("X-GitHub-Delivery"), body, receivedAt); err != nil { s.webhookLogger().Error("integration observation not durable", "event", event, "error", err) } diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index c3d791e3d5..443387f15b 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -100,6 +100,7 @@ var proxyProofRequired = true const staleDropStarvationThreshold = 5 type Server struct { + nativeQueueTracker nativeQueueTrackerRuntime integration integrationRuntime webhookNoSecretOnce sync.Once // warn once per process about a missing webhook secret (#13666) diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 24a902dc2c..9a081e481a 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -10,6 +10,7 @@ import ( "time" "github.com/hivecommons/hive/pkg/dashboard/collect" + "github.com/hivecommons/hive/pkg/forgequeue" "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/stageengine" "github.com/hivecommons/hive/pkg/stagelabels" @@ -40,11 +41,12 @@ type StageTrackerResponse struct { // on every request served from memory until the TTL lapses. Source string `json:"source"` // CacheTTLSeconds is the effective dashboard.stage_tracker.cache_ttl_s. - CacheTTLSeconds int64 `json:"cache_ttl_s"` - HiveID string `json:"hive_id,omitempty"` - Stages []StageTrackerStage `json:"stages"` - Items []StageTrackerItem `json:"items"` - BasePreparation []StageTrackerPreparationQueue `json:"base_preparation,omitempty"` + CacheTTLSeconds int64 `json:"cache_ttl_s"` + HiveID string `json:"hive_id,omitempty"` + Stages []StageTrackerStage `json:"stages"` + Items []StageTrackerItem `json:"items"` + BasePreparation []StageTrackerPreparationQueue `json:"base_preparation,omitempty"` + IntegrationQueues []forgequeue.Observation `json:"integration_queues,omitempty"` // OpenIssues and OpenPRs count Items by kind. Items is the canonical // open-items set (open_items.go), so these equal the Overview tile's // total open issues and PRs; the SPA prints them in the section header diff --git a/src/pkg/dashboard/stage_tracker_build.go b/src/pkg/dashboard/stage_tracker_build.go index 53a5ae1811..b6f17f244f 100644 --- a/src/pkg/dashboard/stage_tracker_build.go +++ b/src/pkg/dashboard/stage_tracker_build.go @@ -492,6 +492,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto s.applyRebaseMergeFollowThrough(resp.Items, now) resp.NeedsHuman, resp.OnHold = stageTrackerHumanCounts(resp.Items) resp.WaitingOnHuman = stageTrackerWaitingOnHuman(resp.Items) + resp.IntegrationQueues = s.stageTrackerNativeQueues(now) preparationState := s.stageTrackerPRStateResolver(nil, resp.Merged24h) resp.BasePreparation = s.stageTrackerPreparation(resp.Items, now, func(repo string, number int) string { for _, merged := range resp.Merged24h { diff --git a/src/pkg/dashboard/stage_tracker_native_queue.go b/src/pkg/dashboard/stage_tracker_native_queue.go new file mode 100644 index 0000000000..325951008a --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_native_queue.go @@ -0,0 +1,321 @@ +package dashboard + +import ( + "context" + "encoding/json" + "fmt" + "sort" + "strings" + "sync" + "time" + + "github.com/hivecommons/hive/pkg/forgequeue" +) + +const ( + nativeQueueObservationInterval = 3 * time.Minute + nativeQueueObservationTimeout = 45 * time.Second + nativeQueueObservationScopes = 2 + nativeQueueObservationHistory = 32 + nativeQueueObservationHints = 16 +) + +type nativeQueueHint struct { + repo, base string + at time.Time + candidate forgequeue.Candidate +} + +type nativeQueueTrackerRuntime struct { + mu sync.Mutex + lastAttempt time.Time + inFlight bool + scopeOffset int + observations map[string]forgequeue.Observation + hints map[string]nativeQueueHint +} + +func nativeQueueScopeKey(repo, base string) string { return strings.ToLower(repo) + "#" + base } + +func (s *Server) nativeQueueScopeAllowed(repo, base string) bool { + if s == nil || s.deps == nil || s.deps.Config == nil { + return false + } + q := s.deps.Config.AutoMerge.NativeMergeQueue + bases := q.BaseSet() + return q.EnabledFor(repo) && (bases == nil || bases[nativeQueueScopeKey(repo, base)]) +} + +// ReconcileNativeQueues reuses the governor's background cycle, never a render +// or per-PR poller. Off means no native observation network calls. +func (s *Server) ReconcileNativeQueues(ctx context.Context) error { + if s == nil || s.deps == nil || s.deps.Config == nil || !s.deps.Config.AutoMerge.NativeMergeQueue.Enabled { + return nil + } + runtime := &s.nativeQueueTracker + runtime.mu.Lock() + now := time.Now() + if runtime.inFlight || now.Sub(runtime.lastAttempt) < nativeQueueObservationInterval { + runtime.mu.Unlock() + return nil + } + runtime.lastAttempt, runtime.inFlight = now, true + scopes := make(map[string][2]string) + for _, scope := range s.deps.Config.AutoMerge.NativeMergeQueue.Bases { + repo, base, valid := strings.Cut(scope, "#") + if valid && s.nativeQueueScopeAllowed(repo, base) { + scopes[nativeQueueScopeKey(repo, base)] = [2]string{repo, base} + } + } + for id, hint := range runtime.hints { + if now.Sub(hint.at) >= 2*time.Hour { + delete(runtime.hints, id) + continue + } + if s.nativeQueueScopeAllowed(hint.repo, hint.base) { + scopes[nativeQueueScopeKey(hint.repo, hint.base)] = [2]string{hint.repo, hint.base} + } + } + keys := make([]string, 0, len(scopes)) + for key := range scopes { + keys = append(keys, key) + } + sort.Strings(keys) + start := runtime.scopeOffset + if len(keys) > 0 { + start %= len(keys) + runtime.scopeOffset = (start + nativeQueueObservationScopes) % len(keys) + } + runtime.mu.Unlock() + defer func() { + runtime.mu.Lock() + runtime.inFlight = false + runtime.mu.Unlock() + }() + ctx, cancel := context.WithTimeout(ctx, nativeQueueObservationTimeout) + defer cancel() + if s.deps.GHClient == nil || !s.deps.GHClient.NativeMergeQueueAvailable() { + runtime.mu.Lock() + if runtime.observations == nil { + runtime.observations = make(map[string]forgequeue.Observation) + } + for key, scope := range scopes { + observation := runtime.observations[key] + observation.Provider, observation.Repo, observation.Base = "github-native", scope[0], scope[1] + observation.State, observation.Stale = "unavailable", true + observation.Reason = "GitHub App installation authentication is unavailable; queue evidence cannot be refreshed." + runtime.observations[key] = observation + } + runtime.mu.Unlock() + return fmt.Errorf("native queue observation requires GitHub App installation authentication") + } + for offset := 0; offset < len(keys) && offset < nativeQueueObservationScopes; offset++ { + key := keys[(start+offset)%len(keys)] + scope := scopes[key] + runtime.mu.Lock() + orderedHints := []nativeQueueHint{} + for _, hint := range runtime.hints { + if nativeQueueScopeKey(hint.repo, hint.base) == key && now.Sub(hint.at) < 2*time.Hour { + orderedHints = append(orderedHints, hint) + } + } + sort.Slice(orderedHints, func(i, j int) bool { return orderedHints[i].at.After(orderedHints[j].at) }) + hints := make([]forgequeue.Candidate, 0, len(orderedHints)) + for _, hint := range orderedHints { + hints = append(hints, hint.candidate) + } + runtime.mu.Unlock() + observation, err := s.deps.GHClient.ReadNativeQueueObservation(ctx, scope[0], scope[1], hints) + runtime.mu.Lock() + if runtime.observations == nil { + runtime.observations = make(map[string]forgequeue.Observation) + } + prior, exists := runtime.observations[key] + if err != nil { + if exists { + observation = prior + } + observation.Provider, observation.Repo, observation.Base = "github-native", scope[0], scope[1] + observation.State, observation.Stale = "unavailable", true + observation.Reason = "Refresh unavailable; retained observations are not current queue evidence." + } else if exists { + observation = nativeQueueObservationDelta(prior, observation, now) + } + runtime.observations[key] = observation + runtime.mu.Unlock() + } + return nil +} + +func nativeQueueObservationDelta(prior, next forgequeue.Observation, now time.Time) forgequeue.Observation { + next.Outcomes = append([]forgequeue.Outcome{}, prior.Outcomes...) + if !prior.EntriesComplete || !next.EntriesComplete { + return next + } + for _, entry := range prior.Entries { + found := false + for _, current := range next.Entries { + found = found || entry.ID == current.ID + } + if !found { + next.Outcomes = appendNativeQueueOutcome(next.Outcomes, forgequeue.Outcome{ + Kind: "entry-removed", PR: entry.PR, Head: entry.Head, ObservedAt: now, Source: "complete-queue-snapshot-difference", + }) + } + } + return next +} + +func appendNativeQueueOutcome(out []forgequeue.Outcome, next forgequeue.Outcome) []forgequeue.Outcome { + for _, prior := range out { + if prior.Kind == next.Kind && prior.PR == next.PR && prior.Head == next.Head && + prior.CandidateSHA == next.CandidateSHA && prior.MergeSHA == next.MergeSHA { + return out + } + } + out = append(out, next) + if len(out) > nativeQueueObservationHistory { + out = out[len(out)-nativeQueueObservationHistory:] + } + return out +} + +// Called only after the existing authenticated webhook path verifies the +// delivery and repository. No API read or merge side effect occurs here. +func (s *Server) observeNativeQueueEvent(event string, body []byte, at time.Time) { + if s == nil || s.deps == nil || s.deps.Config == nil || !s.deps.Config.AutoMerge.NativeMergeQueue.Enabled { + return + } + var payload integrationWebhookPayload + if json.Unmarshal(body, &payload) != nil { + return + } + repo := payload.Repository.FullName + base := strings.TrimPrefix(payload.MergeGroup.BaseRef, "refs/heads/") + if payload.PullRequest != nil { + base = payload.PullRequest.GetBase().GetRef() + } + if !s.nativeQueueScopeAllowed(repo, base) { + return + } + runtime := &s.nativeQueueTracker + runtime.mu.Lock() + defer runtime.mu.Unlock() + if runtime.observations == nil { + runtime.observations = make(map[string]forgequeue.Observation) + } + key := nativeQueueScopeKey(repo, base) + observation := runtime.observations[key] + observation.Provider, observation.Repo, observation.Base = "github-native", repo, base + if observation.State == "" { + observation.State, observation.Reason = "unknown", "Waiting for a bounded authoritative queue snapshot." + } + group := payload.MergeGroup + if event == "merge_group" && group.HeadSHA != "" { + if runtime.hints == nil { + runtime.hints = make(map[string]nativeQueueHint) + } + hintKey := key + "/" + group.HeadSHA + switch payload.Action { + case "checks_requested": + if len(runtime.hints) >= nativeQueueObservationHints { + oldest := "" + for id, hint := range runtime.hints { + if oldest == "" || hint.at.Before(runtime.hints[oldest].at) { + oldest = id + } + } + delete(runtime.hints, oldest) + } + runtime.hints[hintKey] = nativeQueueHint{repo: repo, base: base, at: at, + candidate: forgequeue.Candidate{SHA: group.HeadSHA, Ref: group.HeadRef, BaseSHA: group.BaseSHA}} + case "destroyed": + delete(runtime.hints, hintKey) + observation.Outcomes = appendNativeQueueOutcome(observation.Outcomes, forgequeue.Outcome{ + Kind: "candidate-destroyed", CandidateSHA: group.HeadSHA, ObservedAt: at, Source: "signed-merge-group-webhook", + }) + for i := range observation.Candidates { + if observation.Candidates[i].SHA == group.HeadSHA { + observation.Candidates[i].CI = "destroyed" + } + } + } + } + if event == "pull_request" && payload.PullRequest != nil && payload.PullRequest.GetMerged() { + pr := payload.PullRequest + observedMember := false + for _, entry := range observation.Entries { + observedMember = observedMember || entry.PR == pr.GetNumber() && entry.Head == pr.GetHead().GetSHA() + } + for _, candidate := range observation.Candidates { + if candidate.Membership == "proven" { + for _, member := range candidate.Members { + observedMember = observedMember || member.PR == pr.GetNumber() && member.Head == pr.GetHead().GetSHA() + } + } + } + if observedMember && pr.GetMergeCommitSHA() != "" { + observation.Outcomes = appendNativeQueueOutcome(observation.Outcomes, forgequeue.Outcome{ + Kind: "merged", PR: pr.GetNumber(), Head: pr.GetHead().GetSHA(), MergeSHA: pr.GetMergeCommitSHA(), + ObservedAt: at, Source: "signed-pull-request-merged-webhook", + }) + } + } + runtime.observations[key] = observation +} + +// Cached projection only; it never consults GitHub from a tracker request. +func (s *Server) stageTrackerNativeQueues(now time.Time) []forgequeue.Observation { + if s == nil || s.deps == nil || s.deps.Config == nil || !s.deps.Config.AutoMerge.NativeMergeQueue.Enabled { + return nil + } + runtime := &s.nativeQueueTracker + runtime.mu.Lock() + defer runtime.mu.Unlock() + result := []forgequeue.Observation{} + for _, original := range runtime.observations { + if !s.nativeQueueScopeAllowed(original.Repo, original.Base) { + continue + } + // Copy nested slices: event writes must not mutate an encoded response. + observation := original + observation.Entries = append([]forgequeue.Entry{}, original.Entries...) + for i := range observation.Entries { + if original.Entries[i].EnqueuedAt != nil { + at := *original.Entries[i].EnqueuedAt + observation.Entries[i].EnqueuedAt = &at + } + } + observation.Outcomes = append([]forgequeue.Outcome{}, original.Outcomes...) + observation.Candidates = append([]forgequeue.Candidate{}, original.Candidates...) + for i := range observation.Candidates { + observation.Candidates[i].Members = append([]forgequeue.Member{}, original.Candidates[i].Members...) + observation.Candidates[i].Checks = append([]forgequeue.Check{}, original.Candidates[i].Checks...) + } + observation.Stale = observation.Stale || observation.ObservedAt.IsZero() || now.Sub(observation.ObservedAt) > 2*nativeQueueObservationInterval + observation.FreshForS = int64((2 * nativeQueueObservationInterval).Seconds()) + result = append(result, observation) + } + for _, scope := range s.deps.Config.AutoMerge.NativeMergeQueue.Bases { + repo, base, valid := strings.Cut(scope, "#") + if !valid || !s.nativeQueueScopeAllowed(repo, base) { + continue + } + exists := false + for _, observation := range result { + exists = exists || nativeQueueScopeKey(repo, base) == nativeQueueScopeKey(observation.Repo, observation.Base) + } + if !exists { + result = append(result, forgequeue.Observation{Provider: "github-native", Repo: repo, Base: base, State: "unknown", Stale: true, + Reason: "No authoritative snapshot for this scope yet; bounded background reconciliation rotates across scopes."}) + } + } + if len(result) == 0 { + result = append(result, forgequeue.Observation{Provider: "github-native", State: "unknown", Stale: true, + Reason: "No authoritative queue snapshot yet. Select exact repo/base scopes in Settings; authenticated events and background reconciliation supply observations."}) + } + sort.Slice(result, func(i, j int) bool { + return nativeQueueScopeKey(result[i].Repo, result[i].Base) < nativeQueueScopeKey(result[j].Repo, result[j].Base) + }) + return result +} diff --git a/src/pkg/dashboard/stage_tracker_native_queue_test.go b/src/pkg/dashboard/stage_tracker_native_queue_test.go new file mode 100644 index 0000000000..69a59e23ad --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_native_queue_test.go @@ -0,0 +1,121 @@ +package dashboard + +import ( + "context" + "encoding/json" + "reflect" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/forgequeue" +) + +func TestNativeQueueTrackerOffScopeStaleAndCopy(t *testing.T) { + s := covApiServer(t) + now := time.Now() + s.nativeQueueTracker.observations = map[string]forgequeue.Observation{ + "o/r#v5": {Provider: "github-native", Repo: "o/r", Base: "v5", State: "observed", Complete: true, + ObservedAt: now.Add(-time.Hour), Candidates: []forgequeue.Candidate{{SHA: "candidate", Membership: "proven", Members: []forgequeue.Member{{PR: 7, Head: "head"}}, Checks: []forgequeue.Check{{Name: "test"}}}}}, + "o/r#v6": {Repo: "o/r", Base: "v6"}, + } + if s.stageTrackerNativeQueues(now) != nil || s.ReconcileNativeQueues(context.Background()) != nil || !s.nativeQueueTracker.lastAttempt.IsZero() { + t.Fatal("default-off native observations have side effects") + } + s.deps.Config.AutoMerge.NativeMergeQueue = config.NativeMergeQueueAutoMergeConfig{Enabled: true, Repos: []string{"o/r"}, Bases: []string{"o/r#v5"}} + got := s.stageTrackerNativeQueues(now) + if len(got) != 1 || !got[0].Stale || got[0].Base != "v5" || got[0].FreshForS == 0 { + t.Fatalf("scope/staleness lost: %+v", got) + } + got[0].Candidates[0].Members[0].Head = "mutated" + got[0].Candidates[0].Checks[0].Name = "mutated" + if original := s.stageTrackerNativeQueues(now)[0]; original.Candidates[0].Members[0].Head != "head" || original.Candidates[0].Checks[0].Name != "test" { + t.Fatal("render mutated observation cache") + } + s.deps.Config.AutoMerge.NativeMergeQueue.Bases = []string{"o/r#other"} + got = s.stageTrackerNativeQueues(now) + if len(got) != 1 || got[0].State != "unknown" || got[0].Base != "other" || len(got[0].Candidates) != 0 { + t.Fatalf("missing scope fabricated empty success: %+v", got) + } + if err := s.ReconcileNativeQueues(context.Background()); err == nil { + t.Fatal("missing installation authentication accepted") + } + got = s.stageTrackerNativeQueues(now) + if len(got) != 1 || got[0].State != "unavailable" || !strings.Contains(got[0].Reason, "authentication") { + t.Fatalf("authentication diagnostic unavailable: %+v", got) + } + if err := s.ReconcileNativeQueues(context.Background()); err != nil { + t.Fatal("bounded retry interval not respected") + } +} + +func TestNativeQueueLifecycleNeverMergesAtEnqueue(t *testing.T) { + s := covApiServer(t) + s.deps.Config.AutoMerge.NativeMergeQueue = config.NativeMergeQueueAutoMergeConfig{Enabled: true, Repos: []string{"o/r"}, Bases: []string{"o/r#v5"}} + now := time.Now() + s.nativeQueueTracker.observations = map[string]forgequeue.Observation{"o/r#v5": { + Provider: "github-native", Repo: "o/r", Base: "v5", State: "observed", Complete: true, ObservedAt: now, + Entries: []forgequeue.Entry{{ID: "entry", PR: 7, Head: "head", Position: 1}}, + }} + deliver := func(action string) { + t.Helper() + body, err := json.Marshal(map[string]any{ + "action": action, "repository": map[string]any{"full_name": "o/r"}, + "merge_group": map[string]any{"base_ref": "refs/heads/v5", "base_sha": strings.Repeat("a", 40), + "head_ref": "refs/heads/gh-readonly-queue/v5/pr-7", "head_sha": strings.Repeat("b", 40)}, + }) + if err != nil { + t.Fatal(err) + } + s.observeNativeQueueEvent("merge_group", body, now) + } + deliver("checks_requested") + if got := s.stageTrackerNativeQueues(now); len(got[0].Outcomes) != 0 || len(s.nativeQueueTracker.hints) != 1 { + t.Fatal("group creation fabricated merged outcome") + } + deliver("destroyed") + deliver("destroyed") + if got := s.stageTrackerNativeQueues(now); len(got[0].Outcomes) != 1 || got[0].Outcomes[0].Kind != "candidate-destroyed" || len(s.nativeQueueTracker.hints) != 0 { + t.Fatalf("destroyed delivery not idempotent: %+v", got) + } + for _, head := range []string{"other", "head"} { + body := []byte(`{"action":"closed","repository":{"full_name":"o/r"},"pull_request":{"number":7,"merged":true,"merge_commit_sha":"merge","head":{"sha":"` + head + `"},"base":{"ref":"v5"}}}`) + s.observeNativeQueueEvent("pull_request", body, now) + } + got := s.stageTrackerNativeQueues(now) + if len(got[0].Outcomes) != 2 || got[0].Outcomes[1].Kind != "merged" || got[0].Outcomes[1].MergeSHA != "merge" { + t.Fatalf("exact merged receipt missing: %+v", got) + } + // No pipeline rows or merge ledger entries are rewritten by observations. + if !reflect.DeepEqual(got[0].Entries, []forgequeue.Entry{{ID: "entry", PR: 7, Head: "head", Position: 1}}) { + t.Fatal("outcome observation rewrote the queue into a pipeline") + } +} + +func TestNativeQueueOutcomeHistoryBounded(t *testing.T) { + var outcomes []forgequeue.Outcome + for pr := 1; pr <= nativeQueueObservationHistory+1; pr++ { + outcomes = appendNativeQueueOutcome(outcomes, forgequeue.Outcome{Kind: "entry-removed", PR: pr}) + } + if len(outcomes) != nativeQueueObservationHistory || outcomes[0].PR != 2 { + t.Fatal("unbounded native lifecycle history") + } +} + +func TestNativeQueueRemovalRequiresCompleteSnapshots(t *testing.T) { + prior := forgequeue.Observation{EntriesComplete: true, Entries: []forgequeue.Entry{{ID: "entry", PR: 7, Head: "head"}}} + for _, complete := range []bool{false, true} { + next := nativeQueueObservationDelta(prior, forgequeue.Observation{EntriesComplete: complete}, time.Now()) + if (len(next.Outcomes) == 1) != complete { + t.Fatalf("partial snapshot claimed removal: %+v", next) + } + if complete && (next.Outcomes[0].Kind != "entry-removed" || next.Outcomes[0].MergeSHA != "") { + t.Fatal("removal fabricated a merge receipt") + } + } + prior.EntriesComplete = false + if got := nativeQueueObservationDelta(prior, forgequeue.Observation{EntriesComplete: true}, time.Now()); len(got.Outcomes) != 0 { + t.Fatal("incomplete prior snapshot claimed removal") + } +} diff --git a/src/pkg/dashboard/static-src/css/tracker-native-queue.css b/src/pkg/dashboard/static-src/css/tracker-native-queue.css new file mode 100644 index 0000000000..ba9a7dd57f --- /dev/null +++ b/src/pkg/dashboard/static-src/css/tracker-native-queue.css @@ -0,0 +1,8 @@ + .nq-rail { margin: 12px 0; padding: 12px; border: 1px solid var(--border-color); border-radius: 8px; overflow-wrap: anywhere; } + .nq-rail h3, .nq-rail h4, .nq-rail h5 { margin: 8px 0; } + .nq-muted { color: var(--text-secondary); font-size: var(--fs-sm); } + .nq-scope { margin-top: 12px; border-top: 1px solid var(--border-color); } + .nq-candidates { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; } + .nq-candidate { padding: 10px; border: 1px solid var(--border-color); border-radius: 6px; min-width: 0; } + .nq-entries, .nq-candidate ul { padding-left: 24px; } + .nq-rail li { margin: 6px 0; } diff --git a/src/pkg/dashboard/static-src/html/tracker.html b/src/pkg/dashboard/static-src/html/tracker.html index f09f6243de..1c9c43ddb4 100644 --- a/src/pkg/dashboard/static-src/html/tracker.html +++ b/src/pkg/dashboard/static-src/html/tracker.html @@ -43,6 +43,7 @@

Hive activity moni

+
Loading the tracker…
diff --git a/src/pkg/dashboard/static-src/js/tracker-filter-render.js b/src/pkg/dashboard/static-src/js/tracker-filter-render.js index 9d1984c55b..7c4f7e65a5 100644 --- a/src/pkg/dashboard/static-src/js/tracker-filter-render.js +++ b/src/pkg/dashboard/static-src/js/tracker-filter-render.js @@ -62,6 +62,7 @@ // Rows under a "Merging" hold the payload already dropped ride along (#15245). const d = typeof stageTrackerMergingHoldView === 'function' ? stageTrackerMergingHoldView(_stageTracker, _stageTrackerMergingHold, nowMs) : _stageTracker; if (!d || d.status === 'initializing' || !Array.isArray(d.items)) { + if (typeof stageTrackerNativeQueueSync === 'function') stageTrackerNativeQueueSync(null, [], nowMs, ''); stageTrackerSidebarCountsUnknown(); setIfChanged(el, '
Waiting for the first scan…
'); return; @@ -90,6 +91,7 @@ ? stageTrackerGroupPage(stageTrackerGroups(ordered, { primary: stageTrackerPrimaryRepo(), collapsed: _stageTrackerCollapsed, stages }), f) : stageTrackerPage(ordered, f); if (page.page !== f.page) f.page = page.page; + if (typeof stageTrackerNativeQueueSync === 'function') stageTrackerNativeQueueSync(d, page.rows, nowMs, f.repo); // Attention is counted over the filtered set, nested PRs included. const filteredAll = d.items.filter(it => stageTrackerMatches(it, f, ctx)); const attention = filteredAll.filter(stageTrackerNeedsAttention).length; diff --git a/src/pkg/dashboard/static-src/js/tracker-native-queue.js b/src/pkg/dashboard/static-src/js/tracker-native-queue.js new file mode 100644 index 0000000000..beb880f680 --- /dev/null +++ b/src/pkg/dashboard/static-src/js/tracker-native-queue.js @@ -0,0 +1,81 @@ + // Forge-owned queues are observations, not seats in Hive's preparation + // train and not pipeline rows. This module never moves or mutates items. + const NATIVE_QUEUE_SECOND_MS = 1000; + const NATIVE_QUEUE_MINUTE_S = 60; + function stageTrackerNativeAge(value, nowMs) { + const at = Date.parse(value || ''); + if (!Number.isFinite(at) || at > nowMs) return 'age unknown'; + return Math.floor((nowMs - at) / (NATIVE_QUEUE_SECOND_MS * NATIVE_QUEUE_MINUTE_S)) + 'm'; + } + + function stageTrackerNativeLink(url, label) { + try { + const parsed = new URL(url); + if (parsed.protocol === 'https:') return `${esc(label)}`; + } catch (_) {} + return esc(label); + } + + function stageTrackerNativeIdentities(items) { + const result = []; + (items || []).forEach(item => { + if (!item) return; + if (item.kind === 'pr') result.push(item); + (item.linked_prs || []).forEach(pr => result.push(Object.assign({ repo: item.repo }, pr))); + }); + return result; + } + + function stageTrackerNativeMember(member, observation, all, page) { + const same = item => String(item.repo || '').toLowerCase() === String(observation.repo || '').toLowerCase() + && Number(item.number) === Number(member.pr) && item.head === member.head && item.base_ref === observation.base; + const where = page.some(same) ? 'on this page' : all.some(same) ? 'outside current page/filters' : 'outside tracker snapshot or head changed'; + const repo = String(observation.repo || ''); + const url = /^[-\w.]+\/[-\w.]+$/.test(repo) ? `https://github.com/${repo}/pull/${member.pr}` : ''; + return `${stageTrackerNativeLink(url, '#' + member.pr)} ${esc(String(member.head || '').slice(0, 12) || 'head unknown')} ${esc(where)}`; + } + + function stageTrackerNativeQueueHtml(observations, items, pageItems, nowMs, repoFilter) { + const all = stageTrackerNativeIdentities(items), page = stageTrackerNativeIdentities(pageItems); + const queues = (observations || []).filter(q => !repoFilter || !q.repo || q.repo.toLowerCase() === repoFilter.toLowerCase()); + if (!queues.length) return ''; + return '

Forge-owned merge queues

Hive admits and repairs; the forge validates and merges. Separate from preparation/readiness and the actual pipeline rows. No ETA is inferred.

' + + queues.map(q => { + const observed = Date.parse(q.observed_at || ''); + const stale = q.stale || !Number.isFinite(observed) || !q.fresh_for_s || nowMs - observed > q.fresh_for_s * NATIVE_QUEUE_SECOND_MS; + const entries = Array.isArray(q.entries) ? q.entries : []; + const candidates = Array.isArray(q.candidates) ? q.candidates : []; + const outcomes = Array.isArray(q.outcomes) ? q.outcomes : []; + const label = q.provider === 'github-native' ? 'GitHub merge queue' : String(q.provider || 'Unknown provider'); + return `

${esc(label)} · ${esc(q.repo || 'scope unknown')} ${esc(q.base || '')}

+

${esc(q.state || 'unknown')} · ${stale ? 'STALE / unavailable as current evidence' : 'observed ' + esc(stageTrackerNativeAge(q.observed_at, nowMs)) + ' ago'} · ${q.complete ? 'bounded snapshot complete' : 'coverage incomplete / unknown'}. + ${esc(q.reason || '')} Queue references remain visible across row filters; repo filter applies here.

+
    ${entries.map(entry => `
  1. ${stageTrackerNativeMember(entry, q, all, page)} · ${esc(entry.state || 'state unknown')} · queued ${esc(stageTrackerNativeAge(entry.enqueued_at, nowMs))}
  2. `).join('')}
+ ${!entries.length ? '

' + (q.complete && !stale ? 'No entries observed in this snapshot.' : 'Entry order unavailable; this does not prove an empty queue.') + '

' : ''} +
${candidates.map(candidate => { + const proven = candidate.membership === 'proven' && Array.isArray(candidate.members) && candidate.members.length > 0; + return `
Validation candidate ${esc(String(candidate.sha || '').slice(0, 12) || 'SHA unknown')}
+

${esc(candidate.ref || 'ref unknown')}
Base ${esc(candidate.base_sha || 'unknown')} · tree ${esc(candidate.tree || 'unknown')}

+

${proven ? 'Exact member heads proven at snapshot time by event base, live chain and ancestry' : 'Member mapping unknown — never inferred from FIFO'}

+ ${proven ? '
    ' + candidate.members.map(member => '
  • ' + stageTrackerNativeMember(member, q, all, page) + '
  • ').join('') + '
' : ''} +

${esc(candidate.reason || '')}

+
Candidate required CI: ${esc(candidate.ci || 'unknown')}${candidate.checks_known ? '' : ' (required policy unavailable)'} +

Checks belong to synthetic SHA ${esc(candidate.sha || 'unknown')}, never copied from PR heads. Passing checks alone is not a merged receipt.

+
    ${(candidate.checks || []).map(check => `
  • ${stageTrackerNativeLink(check.url, check.name)} · ${esc(check.status || 'unknown')} ${esc(check.conclusion || '')}${check.app_id ? ' · App ' + Number(check.app_id) : ''}
  • `).join('')}
+ ${!(candidate.checks || []).length ? '

No required check evidence available.

' : ''} +
`; + }).join('')}
+ ${!candidates.length ? '

No validation candidate observed. Enqueue is not testing or merge completion.

' : ''} + ${outcomes.length ? '
Observed lifecycle receipts
    ' + outcomes.map(outcome => `
  • ${esc(outcome.kind)} ${outcome.pr ? '#' + Number(outcome.pr) : ''} ${esc(outcome.candidate_sha || outcome.merge_sha || outcome.head || '')} · ${esc(stageTrackerNativeAge(outcome.observed_at, nowMs))} ago · ${esc(outcome.source)}
  • `).join('') + '

Removal/destroyed is not proof of failure, rebuild reason or merge. Only an observed merged receipt means merged. History is bounded and may have gaps after restart.

' : ''} +
`; + }).join(''); + } + + function stageTrackerNativeQueueSync(data, pageRows, nowMs, repoFilter) { + const root = document.getElementById('activity-monitor-native-queue'); + if (!root) return; + const rows = (pageRows || []).map(row => row.item || row).filter(Boolean); + const html = stageTrackerNativeQueueHtml((data || {}).integration_queues || [], (data || {}).items || [], rows, nowMs, repoFilter); + root.hidden = !html; + setIfChanged(root, html); + } diff --git a/src/pkg/dashboard/static-src/manifest.txt b/src/pkg/dashboard/static-src/manifest.txt index 2221f5336f..cf67a65d4b 100644 --- a/src/pkg/dashboard/static-src/manifest.txt +++ b/src/pkg/dashboard/static-src/manifest.txt @@ -7,6 +7,7 @@ css/agent-cards.css css/auth.css css/agent-state.css css/tracker.css +css/tracker-native-queue.css css/agent-fields.css css/governor.css css/advisory-lifecycle.css @@ -76,6 +77,7 @@ js/tracker-motion.js js/tracker-filter.js js/tracker-filter-state.js js/nav-count-delta.js +js/tracker-native-queue.js js/tracker-filter-render.js js/tracker-filter-fetch.js js/tracker-actions.js diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index bdf8456507..7668884532 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -2163,6 +2163,14 @@ .sts-sample { padding: var(--sp-3) var(--sp-2) 0; } .sts-sample .ham-row { padding: var(--sp-2); } .sts-sample .ham-cols { padding-top: 0; } + .nq-rail { margin: 12px 0; padding: 12px; border: 1px solid var(--border-color); border-radius: 8px; overflow-wrap: anywhere; } + .nq-rail h3, .nq-rail h4, .nq-rail h5 { margin: 8px 0; } + .nq-muted { color: var(--text-secondary); font-size: var(--fs-sm); } + .nq-scope { margin-top: 12px; border-top: 1px solid var(--border-color); } + .nq-candidates { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; } + .nq-candidate { padding: 10px; border: 1px solid var(--border-color); border-radius: 6px; min-width: 0; } + .nq-entries, .nq-candidate ul { padding-left: 24px; } + .nq-rail li { margin: 6px 0; } .agent-blockers { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-1) var(--sp-3); font-size: var(--fs-xs); margin-top: var(--sp-2); color: var(--muted); } .agent-blockers .ab-key { opacity: 0.65; margin-right: 3px; } .agent-blockers .ab-seg { white-space: nowrap; } @@ -7803,6 +7811,7 @@

Hive activity moni +
Loading the tracker…
@@ -19356,6 +19365,87 @@

All labels

navCountDelta(document.getElementById(id), null); } } + // Forge-owned queues are observations, not seats in Hive's preparation + // train and not pipeline rows. This module never moves or mutates items. + const NATIVE_QUEUE_SECOND_MS = 1000; + const NATIVE_QUEUE_MINUTE_S = 60; + function stageTrackerNativeAge(value, nowMs) { + const at = Date.parse(value || ''); + if (!Number.isFinite(at) || at > nowMs) return 'age unknown'; + return Math.floor((nowMs - at) / (NATIVE_QUEUE_SECOND_MS * NATIVE_QUEUE_MINUTE_S)) + 'm'; + } + + function stageTrackerNativeLink(url, label) { + try { + const parsed = new URL(url); + if (parsed.protocol === 'https:') return `${esc(label)}`; + } catch (_) {} + return esc(label); + } + + function stageTrackerNativeIdentities(items) { + const result = []; + (items || []).forEach(item => { + if (!item) return; + if (item.kind === 'pr') result.push(item); + (item.linked_prs || []).forEach(pr => result.push(Object.assign({ repo: item.repo }, pr))); + }); + return result; + } + + function stageTrackerNativeMember(member, observation, all, page) { + const same = item => String(item.repo || '').toLowerCase() === String(observation.repo || '').toLowerCase() + && Number(item.number) === Number(member.pr) && item.head === member.head && item.base_ref === observation.base; + const where = page.some(same) ? 'on this page' : all.some(same) ? 'outside current page/filters' : 'outside tracker snapshot or head changed'; + const repo = String(observation.repo || ''); + const url = /^[-\w.]+\/[-\w.]+$/.test(repo) ? `https://github.com/${repo}/pull/${member.pr}` : ''; + return `${stageTrackerNativeLink(url, '#' + member.pr)} ${esc(String(member.head || '').slice(0, 12) || 'head unknown')} ${esc(where)}`; + } + + function stageTrackerNativeQueueHtml(observations, items, pageItems, nowMs, repoFilter) { + const all = stageTrackerNativeIdentities(items), page = stageTrackerNativeIdentities(pageItems); + const queues = (observations || []).filter(q => !repoFilter || !q.repo || q.repo.toLowerCase() === repoFilter.toLowerCase()); + if (!queues.length) return ''; + return '

Forge-owned merge queues

Hive admits and repairs; the forge validates and merges. Separate from preparation/readiness and the actual pipeline rows. No ETA is inferred.

' + + queues.map(q => { + const observed = Date.parse(q.observed_at || ''); + const stale = q.stale || !Number.isFinite(observed) || !q.fresh_for_s || nowMs - observed > q.fresh_for_s * NATIVE_QUEUE_SECOND_MS; + const entries = Array.isArray(q.entries) ? q.entries : []; + const candidates = Array.isArray(q.candidates) ? q.candidates : []; + const outcomes = Array.isArray(q.outcomes) ? q.outcomes : []; + const label = q.provider === 'github-native' ? 'GitHub merge queue' : String(q.provider || 'Unknown provider'); + return `

${esc(label)} · ${esc(q.repo || 'scope unknown')} ${esc(q.base || '')}

+

${esc(q.state || 'unknown')} · ${stale ? 'STALE / unavailable as current evidence' : 'observed ' + esc(stageTrackerNativeAge(q.observed_at, nowMs)) + ' ago'} · ${q.complete ? 'bounded snapshot complete' : 'coverage incomplete / unknown'}. + ${esc(q.reason || '')} Queue references remain visible across row filters; repo filter applies here.

+
    ${entries.map(entry => `
  1. ${stageTrackerNativeMember(entry, q, all, page)} · ${esc(entry.state || 'state unknown')} · queued ${esc(stageTrackerNativeAge(entry.enqueued_at, nowMs))}
  2. `).join('')}
+ ${!entries.length ? '

' + (q.complete && !stale ? 'No entries observed in this snapshot.' : 'Entry order unavailable; this does not prove an empty queue.') + '

' : ''} +
${candidates.map(candidate => { + const proven = candidate.membership === 'proven' && Array.isArray(candidate.members) && candidate.members.length > 0; + return `
Validation candidate ${esc(String(candidate.sha || '').slice(0, 12) || 'SHA unknown')}
+

${esc(candidate.ref || 'ref unknown')}
Base ${esc(candidate.base_sha || 'unknown')} · tree ${esc(candidate.tree || 'unknown')}

+

${proven ? 'Exact member heads proven at snapshot time by event base, live chain and ancestry' : 'Member mapping unknown — never inferred from FIFO'}

+ ${proven ? '
    ' + candidate.members.map(member => '
  • ' + stageTrackerNativeMember(member, q, all, page) + '
  • ').join('') + '
' : ''} +

${esc(candidate.reason || '')}

+
Candidate required CI: ${esc(candidate.ci || 'unknown')}${candidate.checks_known ? '' : ' (required policy unavailable)'} +

Checks belong to synthetic SHA ${esc(candidate.sha || 'unknown')}, never copied from PR heads. Passing checks alone is not a merged receipt.

+
    ${(candidate.checks || []).map(check => `
  • ${stageTrackerNativeLink(check.url, check.name)} · ${esc(check.status || 'unknown')} ${esc(check.conclusion || '')}${check.app_id ? ' · App ' + Number(check.app_id) : ''}
  • `).join('')}
+ ${!(candidate.checks || []).length ? '

No required check evidence available.

' : ''} +
`; + }).join('')}
+ ${!candidates.length ? '

No validation candidate observed. Enqueue is not testing or merge completion.

' : ''} + ${outcomes.length ? '
Observed lifecycle receipts
    ' + outcomes.map(outcome => `
  • ${esc(outcome.kind)} ${outcome.pr ? '#' + Number(outcome.pr) : ''} ${esc(outcome.candidate_sha || outcome.merge_sha || outcome.head || '')} · ${esc(stageTrackerNativeAge(outcome.observed_at, nowMs))} ago · ${esc(outcome.source)}
  • `).join('') + '

Removal/destroyed is not proof of failure, rebuild reason or merge. Only an observed merged receipt means merged. History is bounded and may have gaps after restart.

' : ''} +
`; + }).join(''); + } + + function stageTrackerNativeQueueSync(data, pageRows, nowMs, repoFilter) { + const root = document.getElementById('activity-monitor-native-queue'); + if (!root) return; + const rows = (pageRows || []).map(row => row.item || row).filter(Boolean); + const html = stageTrackerNativeQueueHtml((data || {}).integration_queues || [], (data || {}).items || [], rows, nowMs, repoFilter); + root.hidden = !html; + setIfChanged(root, html); + } function stageTrackerPagerHtml(page) { if (page.pages <= 1) return ''; return ``; @@ -19420,6 +19510,7 @@

All labels

// Rows under a "Merging" hold the payload already dropped ride along (#15245). const d = typeof stageTrackerMergingHoldView === 'function' ? stageTrackerMergingHoldView(_stageTracker, _stageTrackerMergingHold, nowMs) : _stageTracker; if (!d || d.status === 'initializing' || !Array.isArray(d.items)) { + if (typeof stageTrackerNativeQueueSync === 'function') stageTrackerNativeQueueSync(null, [], nowMs, ''); stageTrackerSidebarCountsUnknown(); setIfChanged(el, '
Waiting for the first scan…
'); return; @@ -19448,6 +19539,7 @@

All labels

? stageTrackerGroupPage(stageTrackerGroups(ordered, { primary: stageTrackerPrimaryRepo(), collapsed: _stageTrackerCollapsed, stages }), f) : stageTrackerPage(ordered, f); if (page.page !== f.page) f.page = page.page; + if (typeof stageTrackerNativeQueueSync === 'function') stageTrackerNativeQueueSync(d, page.rows, nowMs, f.repo); // Attention is counted over the filtered set, nested PRs included. const filteredAll = d.items.filter(it => stageTrackerMatches(it, f, ctx)); const attention = filteredAll.filter(stageTrackerNeedsAttention).length; diff --git a/src/pkg/forgequeue/observation.go b/src/pkg/forgequeue/observation.go new file mode 100644 index 0000000000..f2b2da8429 --- /dev/null +++ b/src/pkg/forgequeue/observation.go @@ -0,0 +1,66 @@ +// Package forgequeue describes observed forge-owned integration queues. +// Observations confer no admission or merge authority. +package forgequeue + +import "time" + +type Entry struct { + ID string `json:"id"` + PR int `json:"pr"` + Head string `json:"head"` + Position int `json:"position"` + State string `json:"state"` + EnqueuedAt *time.Time `json:"enqueued_at,omitempty"` +} + +type Member struct { + PR int `json:"pr"` + Head string `json:"head"` +} + +type Check struct { + Name string `json:"name"` + Status string `json:"status"` + Conclusion string `json:"conclusion,omitempty"` + URL string `json:"url,omitempty"` + AppID int64 `json:"app_id,omitempty"` +} + +type Candidate struct { + Ref string `json:"ref"` + SHA string `json:"sha"` + BaseSHA string `json:"base_sha,omitempty"` + Tree string `json:"tree,omitempty"` + Membership string `json:"membership"` + Members []Member `json:"members"` + CI string `json:"ci"` + Checks []Check `json:"checks"` + ChecksKnown bool `json:"checks_known"` + Reason string `json:"reason,omitempty"` +} + +type Outcome struct { + Kind string `json:"kind"` + PR int `json:"pr,omitempty"` + Head string `json:"head,omitempty"` + CandidateSHA string `json:"candidate_sha,omitempty"` + MergeSHA string `json:"merge_sha,omitempty"` + ObservedAt time.Time `json:"observed_at"` + Source string `json:"source"` +} + +type Observation struct { + Provider string `json:"provider"` + Repo string `json:"repo"` + Base string `json:"base"` + State string `json:"state"` + Complete bool `json:"complete"` + EntriesComplete bool `json:"entries_complete"` + ObservedAt time.Time `json:"observed_at"` + Stale bool `json:"stale"` + FreshForS int64 `json:"fresh_for_s"` + Reason string `json:"reason,omitempty"` + Entries []Entry `json:"entries"` + Candidates []Candidate `json:"candidates"` + Outcomes []Outcome `json:"outcomes"` +} diff --git a/src/pkg/github/native_queue_observation.go b/src/pkg/github/native_queue_observation.go new file mode 100644 index 0000000000..62d021c7ed --- /dev/null +++ b/src/pkg/github/native_queue_observation.go @@ -0,0 +1,325 @@ +package github + +import ( + "context" + "fmt" + "net/url" + "sort" + "strings" + "time" + + gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/forgequeue" +) + +const ( + nativeObservationPageSize = 100 + nativeObservationMaxGroups = 4 + nativeObservationMaxMembers = 8 +) + +// ReadNativeQueueObservation is bounded, read-only and never grants merge +// authority. Only signed merge_group event identities supply a group's base; +// workflow runs can discover candidate SHAs but cannot prove membership. +func (c *Client) ReadNativeQueueObservation(ctx context.Context, repo, base string, hints []forgequeue.Candidate) (forgequeue.Observation, error) { + out := forgequeue.Observation{Provider: "github-native", Repo: repo, Base: base, + State: "unavailable", ObservedAt: time.Now(), Entries: []forgequeue.Entry{}, + Candidates: []forgequeue.Candidate{}, Outcomes: []forgequeue.Outcome{}} + parts := strings.Split(repo, "/") + if len(parts) != 2 || base == "" { + return out, fmt.Errorf("native queue scope unavailable") + } + var data struct { + Repository *struct { + MergeQueue *struct { + Entries struct { + PageInfo struct{ HasNextPage bool } + Nodes []struct { + ID string + Position int + State string + EnqueuedAt time.Time + PullRequest struct { + Number int + HeadRefOID string + BaseRefName string + } + } + } + } + } + } + if err := c.graphQL(ctx, `query($owner:String!,$name:String!,$base:String!,$limit:Int!) { + repository(owner:$owner,name:$name) { mergeQueue(branch:$base) { + entries(first:$limit) { pageInfo { hasNextPage } nodes { + id position state enqueuedAt pullRequest { number headRefOid baseRefName } + } } } } }`, map[string]any{"owner": parts[0], "name": parts[1], "base": base, "limit": nativeObservationPageSize}, &data); err != nil { + return out, err + } + if data.Repository == nil { + return out, fmt.Errorf("native queue repository evidence unavailable") + } + if data.Repository.MergeQueue == nil { + out.State, out.Complete = "not-enabled", true + out.EntriesComplete = true + return out, nil + } + out.State, out.Complete = "observed", !data.Repository.MergeQueue.Entries.PageInfo.HasNextPage + out.EntriesComplete = out.Complete + if !out.Complete { + out.Reason = "Queue exceeds bounded page; order and membership coverage are partial." + } + seenIDs, seenPRs := map[string]bool{}, map[int]bool{} + for _, entry := range data.Repository.MergeQueue.Entries.Nodes { + if entry.ID == "" || entry.Position < 1 || entry.PullRequest.Number < 1 || !integrationOID(entry.PullRequest.HeadRefOID) || + entry.PullRequest.BaseRefName != base || seenIDs[entry.ID] || seenPRs[entry.PullRequest.Number] { + out.Complete = false + out.EntriesComplete = false + out.Reason = "Queue contains incomplete entries." + continue + } + seenIDs[entry.ID], seenPRs[entry.PullRequest.Number] = true, true + e := forgequeue.Entry{ID: entry.ID, Position: entry.Position, PR: entry.PullRequest.Number, + Head: entry.PullRequest.HeadRefOID, State: entry.State} + if !entry.EnqueuedAt.IsZero() { + at := entry.EnqueuedAt + e.EnqueuedAt = &at + } + out.Entries = append(out.Entries, e) + } + sort.Slice(out.Entries, func(i, j int) bool { return out.Entries[i].Position < out.Entries[j].Position }) + for index, entry := range out.Entries { + if entry.Position != index+1 { + out.Complete = false + out.EntriesComplete = false + out.Reason = "Queue positions contain gaps; snapshot coverage is partial." + } + } + // Candidate identity comes from actual merge_group runs/events, never FIFO + // seats or the PR number encoded in a synthetic ref. + candidates := make(map[string]forgequeue.Candidate) + order := []string{} + hintBySHA := make(map[string]forgequeue.Candidate) + for _, hint := range hints { + if integrationOID(hint.SHA) && strings.HasPrefix(hint.Ref, "refs/heads/gh-readonly-queue/"+base+"/") { + hintBySHA[hint.SHA] = hint + } + } + runs, response, runErr := c.client.Actions.ListRepositoryWorkflowRuns(ctx, parts[0], parts[1], &gh.ListWorkflowRunsOptions{ + Event: "merge_group", ListOptions: gh.ListOptions{PerPage: nativeObservationPageSize}, + }) + if runErr != nil || runs == nil { + out.Complete = false + out.Reason = "Candidate workflow discovery unavailable; signed-event candidates may still be observed." + } else { + if response != nil && response.NextPage != 0 { + out.Complete = false + out.Reason = "Candidate workflow listing exceeds bounded page." + } + for _, run := range runs.WorkflowRuns { + if run.GetEvent() != "merge_group" || !integrationOID(run.GetHeadSHA()) || + !strings.HasPrefix(run.GetHeadBranch(), "gh-readonly-queue/"+base+"/") { + continue + } + if _, exists := candidates[run.GetHeadSHA()]; exists { + continue + } + if len(candidates) >= nativeObservationMaxGroups { + out.Complete = false + out.Reason = "Candidate cohort exceeds the bounded observation budget." + break + } + candidates[run.GetHeadSHA()] = forgequeue.Candidate{SHA: run.GetHeadSHA(), Ref: "refs/heads/" + run.GetHeadBranch()} + if hint, exists := hintBySHA[run.GetHeadSHA()]; exists { + candidates[run.GetHeadSHA()] = hint + } + order = append(order, run.GetHeadSHA()) + } + } + for _, hint := range hints { + if _, valid := hintBySHA[hint.SHA]; !valid { + continue + } + if _, exists := candidates[hint.SHA]; exists { + continue + } + if len(candidates) >= nativeObservationMaxGroups { + out.Complete = false + out.Reason = "Candidate cohort exceeds the bounded observation budget." + break + } + candidates[hint.SHA] = hint + order = append(order, hint.SHA) + } + required, requiredKnown := c.nativeObservationRequired(ctx, parts[0], parts[1], base) + for _, key := range order { + candidate := candidates[key] + candidate.Membership, candidate.Members = "unknown", []forgequeue.Member{} + candidate.CI, candidate.Checks = "unknown", []forgequeue.Check{} + // Expired refs are not proof of failure, rebuild or merge. + ref, _, refErr := c.client.Git.GetRef(ctx, parts[0], parts[1], strings.TrimPrefix(candidate.Ref, "refs/")) + if refErr != nil || ref.GetObject().GetSHA() != candidate.SHA { + candidate.Reason = "Synthetic ref unavailable or changed; lifecycle outcome unknown." + out.Candidates = append(out.Candidates, candidate) + continue + } + if integrationOID(candidate.BaseSHA) { + group, groupErr := c.ReadNativeIntegrationGroup(ctx, repo, base, candidate.BaseSHA, candidate.Ref, candidate.SHA) + if groupErr == nil && len(group.Members) <= nativeObservationMaxMembers && len(group.Members) > 0 { + proven := true + for _, member := range group.Members { + // Queue-chain facts alone are insufficient: prove every exact + // member head is in this synthetic candidate. + comparison, _, err := c.client.Repositories.CompareCommits(ctx, parts[0], parts[1], member.Head, candidate.SHA, nil) + matches := false + for _, entry := range out.Entries { + matches = matches || entry.ID == member.Entry && entry.PR == member.PR && entry.Head == member.Head + } + if err != nil || comparison.GetMergeBaseCommit().GetSHA() != member.Head || + (comparison.GetStatus() != "ahead" && comparison.GetStatus() != "identical") || !matches { + proven = false + break + } + } + finalRef, _, err := c.client.Git.GetRef(ctx, parts[0], parts[1], strings.TrimPrefix(candidate.Ref, "refs/")) + if err != nil || finalRef.GetObject().GetSHA() != candidate.SHA { + proven = false + } + if proven { + candidate.Membership, candidate.Tree = "proven", group.Tree + for _, member := range group.Members { + candidate.Members = append(candidate.Members, forgequeue.Member{PR: member.PR, Head: member.Head}) + } + } + } + } + if candidate.Membership != "proven" { + candidate.Reason = "Exact membership unavailable: needs signed group base, live queue chain, member ancestry and unchanged synthetic ref." + } + candidate.Checks, candidate.CI, candidate.ChecksKnown = c.nativeObservationChecks(ctx, parts[0], parts[1], candidate.SHA, required, requiredKnown) + out.Candidates = append(out.Candidates, candidate) + } + return out, nil +} + +// Both classic protection and applicable rules must be readable. No configured +// fallback is presented as GitHub's actual required-check policy. +func (c *Client) nativeObservationRequired(ctx context.Context, owner, repo, base string) (map[string]int64, bool) { + required := map[string]int64{} + classic, _, err := c.client.Repositories.GetRequiredStatusChecks(ctx, owner, repo, base) + known := err == nil + if classic != nil { + if classic.Contexts != nil { + for _, name := range *classic.Contexts { + required[name] = 0 + } + } + if classic.Checks != nil { + for _, check := range *classic.Checks { + required[check.GetContext()] = check.GetAppID() + } + } + } + request, err := c.client.NewRequest("GET", fmt.Sprintf("repos/%s/%s/rules/branches/%s", owner, repo, url.PathEscape(base)), nil) + if err != nil { + return required, false + } + var rules []struct { + Type string `json:"type"` + Parameters struct { + Checks []struct { + Context string `json:"context"` + IntegrationID int64 `json:"integration_id"` + } `json:"required_status_checks"` + } `json:"parameters"` + } + if _, err := c.client.Do(ctx, request, &rules); err != nil { + return required, false + } + for _, rule := range rules { + if rule.Type == "required_status_checks" { + for _, check := range rule.Parameters.Checks { + if prior, exists := required[check.Context]; exists && prior != 0 && check.IntegrationID != 0 && prior != check.IntegrationID { + known = false + } + if check.IntegrationID != 0 || required[check.Context] == 0 { + required[check.Context] = check.IntegrationID + } + } + } + } + return required, known +} + +func (c *Client) nativeObservationChecks(ctx context.Context, owner, repo, sha string, required map[string]int64, known bool) ([]forgequeue.Check, string, bool) { + checks := []forgequeue.Check{} + if len(required) == 0 { + return checks, "unknown", known + } + runs, response, err := c.client.Checks.ListCheckRunsForRef(ctx, owner, repo, sha, &gh.ListCheckRunsOptions{ + Filter: gh.Ptr("latest"), ListOptions: gh.ListOptions{PerPage: nativeObservationPageSize}, + }) + if err != nil || runs == nil || response != nil && response.NextPage != 0 { + return checks, "unavailable", false + } + statuses := &gh.CombinedStatus{} + for _, app := range required { + if app == 0 { + var statusResponse *gh.Response + statuses, statusResponse, err = c.client.Repositories.GetCombinedStatus(ctx, owner, repo, sha, &gh.ListOptions{PerPage: nativeObservationPageSize}) + if err != nil || statuses == nil || statusResponse != nil && statusResponse.NextPage != 0 { + return checks, "unavailable", false + } + break + } + } + names := make([]string, 0, len(required)) + for name := range required { + names = append(names, name) + } + sort.Strings(names) + state := "passed" + if !known || len(names) == 0 { + state = "unknown" + } + for _, name := range names { + check := forgequeue.Check{Name: name, Status: "missing"} + var latest *gh.CheckRun + for _, run := range runs.CheckRuns { + if run.GetName() == name && run.GetHeadSHA() == sha && (required[name] == 0 || run.GetApp().GetID() == required[name]) && + (latest == nil || run.GetID() > latest.GetID()) { + latest = run + } + } + if latest != nil { + check.Status, check.Conclusion, check.URL, check.AppID = latest.GetStatus(), latest.GetConclusion(), latest.GetHTMLURL(), latest.GetApp().GetID() + } else if required[name] == 0 { + var latestStatus *gh.RepoStatus + for _, status := range statuses.Statuses { + if status.GetContext() == name && (latestStatus == nil || status.GetID() > latestStatus.GetID()) { + latestStatus = status + } + } + if latestStatus != nil { + check.Status, check.Conclusion, check.URL = "completed", latestStatus.GetState(), latestStatus.GetTargetURL() + } + } + switch { + case check.Conclusion == "failure" || check.Conclusion == "error" || check.Conclusion == "timed_out" || check.Conclusion == "cancelled": + state = "failed" + case check.Status == "completed" && check.Conclusion != "success": + if state != "failed" { + state = "blocked" + } + case check.Status != "completed" || check.Conclusion != "success": + if state != "failed" && state != "blocked" { + state = "pending" + } + } + checks = append(checks, check) + } + if !known && state != "failed" { + state = "unknown" + } + return checks, state, known +} diff --git a/src/pkg/github/native_queue_observation_test.go b/src/pkg/github/native_queue_observation_test.go new file mode 100644 index 0000000000..babad8ebb0 --- /dev/null +++ b/src/pkg/github/native_queue_observation_test.go @@ -0,0 +1,131 @@ +package github + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/forgequeue" +) + +func TestNativeQueueObservationExactCandidateEvidence(t *testing.T) { + for _, mode := range []string{"proven", "no-event", "wrong-check-head", "foreign-app", "missing-check", "pending", "failed", "skipped", "policy-unavailable", "truncated", "bad-ancestry", "moved-ref", "queue-error", "no-queue"} { + t.Run(mode, func(t *testing.T) { + base, candidate, member, tree := strings.Repeat("a", 40), strings.Repeat("b", 40), strings.Repeat("c", 40), strings.Repeat("d", 40) + api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + switch { + case r.URL.Path == "/graphql": + if mode == "queue-error" { + w.WriteHeader(http.StatusBadGateway) + return + } + if mode == "no-queue" { + _, _ = w.Write([]byte(`{"data":{"repository":{"mergeQueue":null}}}`)) + return + } + _, _ = fmt.Fprintf(w, `{"data":{"repository":{"mergeQueue":{"entries":{"pageInfo":{"hasNextPage":%t},"nodes":[{"id":"entry-7","position":1,"state":"AWAITING_CHECKS","enqueuedAt":"2026-10-30T12:00:00Z","baseCommit":{"oid":%q},"headCommit":{"oid":%q},"pullRequest":{"number":7,"headRefOid":%q,"baseRefName":"v5"}}]}}}}}`, mode == "truncated", base, candidate, member) + case strings.HasSuffix(r.URL.Path, "/actions/runs"): + _, _ = fmt.Fprintf(w, `{"workflow_runs":[{"id":10,"event":"merge_group","head_sha":%q,"head_branch":"gh-readonly-queue/v5/pr-7"}]}`, candidate) + case strings.HasSuffix(r.URL.Path, "/required_status_checks"): + if mode == "policy-unavailable" { + w.WriteHeader(http.StatusForbidden) + return + } + _, _ = w.Write([]byte(`{"contexts":["test"],"checks":[{"context":"test","app_id":15368}]}`)) + case strings.Contains(r.URL.Path, "/rules/branches/"): + _, _ = w.Write([]byte(`[]`)) + case strings.Contains(r.URL.Path, "/git/ref/"): + sha := candidate + if mode == "moved-ref" { + sha = tree + } + _, _ = fmt.Fprintf(w, `{"object":{"sha":%q}}`, sha) + case strings.Contains(r.URL.Path, "/git/commits/"): + _, _ = fmt.Fprintf(w, `{"sha":%q,"tree":{"sha":%q}}`, candidate, tree) + case strings.Contains(r.URL.Path, "/compare/"): + ancestor := member + if mode == "bad-ancestry" { + ancestor = base + } + _, _ = fmt.Fprintf(w, `{"status":"ahead","merge_base_commit":{"sha":%q}}`, ancestor) + case strings.HasSuffix(r.URL.Path, "/check-runs"): + if !strings.Contains(r.URL.Path, candidate) { + t.Errorf("CI queried on a PR head, not candidate: %s", r.URL) + } + if mode == "missing-check" { + _, _ = w.Write([]byte(`{"check_runs":[]}`)) + return + } + checkHead, status, conclusion, app := candidate, "completed", "success", 15368 + switch mode { + case "wrong-check-head": + checkHead = member + case "foreign-app": + app = 42 + case "pending": + status, conclusion = "in_progress", "" + case "failed": + conclusion = "failure" + case "skipped": + conclusion = "skipped" + } + _, _ = fmt.Fprintf(w, `{"check_runs":[{"id":40,"name":"test","head_sha":%q,"status":%q,"conclusion":%q,"app":{"id":%d},"html_url":"https://github.com/o/r/actions/runs/10/job/40"}]}`, checkHead, status, conclusion, app) + case strings.HasSuffix(r.URL.Path, "/status"): + _, _ = w.Write([]byte(`{"statuses":[]}`)) + default: + t.Errorf("unexpected request %s", r.URL) + w.WriteHeader(http.StatusNotFound) + } + })) + defer api.Close() + client := NewClient("token", "o", []string{"r"}, nil, api.URL) + hints := []forgequeue.Candidate{{SHA: candidate, Ref: "refs/heads/gh-readonly-queue/v5/pr-7", BaseSHA: base}} + if mode == "no-event" { + hints = nil + } + got, err := client.ReadNativeQueueObservation(context.Background(), "o/r", "v5", hints) + if mode == "queue-error" { + if err == nil || got.State != "unavailable" { + t.Fatal("queue read failure treated as success") + } + return + } + if err != nil { + t.Fatal(err) + } + if mode == "no-queue" { + if got.State != "not-enabled" || !got.Complete || len(got.Candidates) != 0 { + t.Fatalf("disabled queue: %+v", got) + } + return + } + if len(got.Entries) != 1 || got.Entries[0].EnqueuedAt == nil || got.Entries[0].State != "AWAITING_CHECKS" || len(got.Candidates) != 1 { + t.Fatalf("queue observations: %+v", got) + } + group := got.Candidates[0] + proven := mode != "no-event" && mode != "truncated" && mode != "bad-ancestry" && mode != "moved-ref" + if (group.Membership == "proven") != proven || proven && (len(group.Members) != 1 || group.Members[0].Head != member || group.Tree != tree) || + !proven && len(group.Members) != 0 { + t.Fatalf("unproved member mapping: %+v", group) + } + wantCI := "passed" + switch mode { + case "wrong-check-head", "foreign-app", "missing-check", "pending": + wantCI = "pending" + case "failed": + wantCI = "failed" + case "skipped": + wantCI = "blocked" + case "policy-unavailable", "moved-ref": + wantCI = "unknown" + } + if group.CI != wantCI || mode == "truncated" && got.Complete { + t.Fatalf("candidate evidence: %+v", group) + } + }) + } +} From fb43c93e0c39c870683c23ef71024f9825391c71 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 21:07:09 -0400 Subject: [PATCH 09/14] =?UTF-8?q?=F0=9F=90=9B=20Reference=20native=20base?= =?UTF-8?q?=20scope=20in=20owner=20Settings=20YAML=20help?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- src/pkg/dashboard/static-src/js/config-features.js | 2 +- src/pkg/dashboard/static/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkg/dashboard/static-src/js/config-features.js b/src/pkg/dashboard/static-src/js/config-features.js index f540cecfa8..72238591ed 100644 --- a/src/pkg/dashboard/static-src/js/config-features.js +++ b/src/pkg/dashboard/static-src/js/config-features.js @@ -485,7 +485,7 @@ - +
diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 7668884532..f29dc16d49 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -58296,7 +58296,7 @@

${esc(s.title)}

- +
From a226e8e02b7c6e6d40e7309fa5f5c2f514da8156 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 21:07:43 -0400 Subject: [PATCH 10/14] =?UTF-8?q?=F0=9F=A7=AA=20Cover=20full=20native=20ca?= =?UTF-8?q?ndidate=20membership=20and=20partial=20entry=20evidence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .../github/native_queue_observation_test.go | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/pkg/github/native_queue_observation_test.go b/src/pkg/github/native_queue_observation_test.go index babad8ebb0..236ce570f8 100644 --- a/src/pkg/github/native_queue_observation_test.go +++ b/src/pkg/github/native_queue_observation_test.go @@ -12,7 +12,7 @@ import ( ) func TestNativeQueueObservationExactCandidateEvidence(t *testing.T) { - for _, mode := range []string{"proven", "no-event", "wrong-check-head", "foreign-app", "missing-check", "pending", "failed", "skipped", "policy-unavailable", "truncated", "bad-ancestry", "moved-ref", "queue-error", "no-queue"} { + for _, mode := range []string{"proven", "two-members", "second-member-absent", "position-gap", "no-event", "wrong-check-head", "foreign-app", "missing-check", "pending", "failed", "skipped", "policy-unavailable", "truncated", "bad-ancestry", "moved-ref", "queue-error", "no-queue"} { t.Run(mode, func(t *testing.T) { base, candidate, member, tree := strings.Repeat("a", 40), strings.Repeat("b", 40), strings.Repeat("c", 40), strings.Repeat("d", 40) api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -27,7 +27,15 @@ func TestNativeQueueObservationExactCandidateEvidence(t *testing.T) { _, _ = w.Write([]byte(`{"data":{"repository":{"mergeQueue":null}}}`)) return } - _, _ = fmt.Fprintf(w, `{"data":{"repository":{"mergeQueue":{"entries":{"pageInfo":{"hasNextPage":%t},"nodes":[{"id":"entry-7","position":1,"state":"AWAITING_CHECKS","enqueuedAt":"2026-10-30T12:00:00Z","baseCommit":{"oid":%q},"headCommit":{"oid":%q},"pullRequest":{"number":7,"headRefOid":%q,"baseRefName":"v5"}}]}}}}}`, mode == "truncated", base, candidate, member) + position, firstCandidate, extra := 1, candidate, "" + if mode == "position-gap" { + position = 2 + } + if mode == "two-members" || mode == "second-member-absent" { + firstCandidate = tree + extra = fmt.Sprintf(`,{"id":"entry-8","position":2,"state":"AWAITING_CHECKS","baseCommit":{"oid":%q},"headCommit":{"oid":%q},"pullRequest":{"number":8,"headRefOid":%q,"baseRefName":"v5"}}`, tree, candidate, strings.Repeat("e", 40)) + } + _, _ = fmt.Fprintf(w, `{"data":{"repository":{"mergeQueue":{"entries":{"pageInfo":{"hasNextPage":%t},"nodes":[{"id":"entry-7","position":%d,"state":"AWAITING_CHECKS","enqueuedAt":"2026-10-30T12:00:00Z","baseCommit":{"oid":%q},"headCommit":{"oid":%q},"pullRequest":{"number":7,"headRefOid":%q,"baseRefName":"v5"}}%s]}}}}}`, mode == "truncated", position, base, firstCandidate, member, extra) case strings.HasSuffix(r.URL.Path, "/actions/runs"): _, _ = fmt.Fprintf(w, `{"workflow_runs":[{"id":10,"event":"merge_group","head_sha":%q,"head_branch":"gh-readonly-queue/v5/pr-7"}]}`, candidate) case strings.HasSuffix(r.URL.Path, "/required_status_checks"): @@ -48,6 +56,12 @@ func TestNativeQueueObservationExactCandidateEvidence(t *testing.T) { _, _ = fmt.Fprintf(w, `{"sha":%q,"tree":{"sha":%q}}`, candidate, tree) case strings.Contains(r.URL.Path, "/compare/"): ancestor := member + if strings.Contains(r.URL.Path, strings.Repeat("e", 40)) { + ancestor = strings.Repeat("e", 40) + if mode == "second-member-absent" { + ancestor = base + } + } if mode == "bad-ancestry" { ancestor = base } @@ -103,12 +117,16 @@ func TestNativeQueueObservationExactCandidateEvidence(t *testing.T) { } return } - if len(got.Entries) != 1 || got.Entries[0].EnqueuedAt == nil || got.Entries[0].State != "AWAITING_CHECKS" || len(got.Candidates) != 1 { + memberCount := 1 + if mode == "two-members" || mode == "second-member-absent" { + memberCount = 2 + } + if len(got.Entries) != memberCount || got.Entries[0].EnqueuedAt == nil || got.Entries[0].State != "AWAITING_CHECKS" || len(got.Candidates) != 1 { t.Fatalf("queue observations: %+v", got) } group := got.Candidates[0] - proven := mode != "no-event" && mode != "truncated" && mode != "bad-ancestry" && mode != "moved-ref" - if (group.Membership == "proven") != proven || proven && (len(group.Members) != 1 || group.Members[0].Head != member || group.Tree != tree) || + proven := mode != "no-event" && mode != "truncated" && mode != "bad-ancestry" && mode != "moved-ref" && mode != "position-gap" && mode != "second-member-absent" + if (group.Membership == "proven") != proven || proven && (len(group.Members) != memberCount || group.Members[0].Head != member || group.Tree != tree) || !proven && len(group.Members) != 0 { t.Fatalf("unproved member mapping: %+v", group) } @@ -123,7 +141,7 @@ func TestNativeQueueObservationExactCandidateEvidence(t *testing.T) { case "policy-unavailable", "moved-ref": wantCI = "unknown" } - if group.CI != wantCI || mode == "truncated" && got.Complete { + if group.CI != wantCI || (mode == "truncated" || mode == "position-gap") && (got.Complete || got.EntriesComplete) { t.Fatalf("candidate evidence: %+v", group) } }) From e8aa512b6efa189c0c147c9f99aa221f6bdb7abc Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 21:09:46 -0400 Subject: [PATCH 11/14] =?UTF-8?q?=F0=9F=90=9B=20Use=20required-check=20con?= =?UTF-8?q?text=20field=20supported=20by=20GitHub=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- src/pkg/github/native_queue_observation.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pkg/github/native_queue_observation.go b/src/pkg/github/native_queue_observation.go index 62d021c7ed..9e0c3efdc3 100644 --- a/src/pkg/github/native_queue_observation.go +++ b/src/pkg/github/native_queue_observation.go @@ -216,7 +216,11 @@ func (c *Client) nativeObservationRequired(ctx context.Context, owner, repo, bas } if classic.Checks != nil { for _, check := range *classic.Checks { - required[check.GetContext()] = check.GetAppID() + if check == nil || strings.TrimSpace(check.Context) == "" { + known = false + continue + } + required[check.Context] = check.GetAppID() } } } From 87e9076a8c1a8f4b326d891a3e985ea98b743427 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 21:12:18 -0400 Subject: [PATCH 12/14] =?UTF-8?q?=F0=9F=93=96=20Regenerate=20API=20citatio?= =?UTF-8?q?ns=20after=20native=20tracker=20server=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- src/docs/api-reference/auth.md | 6 ++--- src/docs/api-reference/dashboard-misc.md | 2 +- .../api-reference/health-status-events.md | 22 +++++++++---------- src/docs/api-reference/snapshots-and-style.md | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/docs/api-reference/auth.md b/src/docs/api-reference/auth.md index 6606c7d703..07a4ff83de 100644 --- a/src/docs/api-reference/auth.md +++ b/src/docs/api-reference/auth.md @@ -24,6 +24,6 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `GET` | `/api/openrouter/models` | Dashboard auth/session | Open Router Models | `pkg/dashboard/openrouter.go:47` | | `GET` | `/api/openrouter/credit` | Dashboard auth/session | Open Router Credit | `pkg/dashboard/openrouter.go:48` | | `GET` | `/openrouter/callback` | Public | Open Router Callback | `pkg/dashboard/openrouter.go:49` | -| `POST` | `/api/github-app/recheck` | Dashboard auth/session | GitHub App Recheck | `pkg/dashboard/server.go:1650` | -| `POST` | `/api/github-app/install-clicked` | Dashboard auth/session | GitHub App Install Clicked | `pkg/dashboard/server.go:1651` | -| `GET` | `/gh-setup` | Public | GitHub App Setup Callback | `pkg/dashboard/server.go:1652` | +| `POST` | `/api/github-app/recheck` | Dashboard auth/session | GitHub App Recheck | `pkg/dashboard/server.go:1651` | +| `POST` | `/api/github-app/install-clicked` | Dashboard auth/session | GitHub App Install Clicked | `pkg/dashboard/server.go:1652` | +| `GET` | `/gh-setup` | Public | GitHub App Setup Callback | `pkg/dashboard/server.go:1653` | diff --git a/src/docs/api-reference/dashboard-misc.md b/src/docs/api-reference/dashboard-misc.md index 26aac1af9e..9414ab843c 100644 --- a/src/docs/api-reference/dashboard-misc.md +++ b/src/docs/api-reference/dashboard-misc.md @@ -64,4 +64,4 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `POST` | `/api/hives/{id}/heartbeat` | Dashboard auth/session | Hives Heartbeat | `pkg/dashboard/api_contribute.go:337` | | `DELETE` | `/api/hives/{id}` | Owner only | Hives Delete | `pkg/dashboard/api_contribute.go:338` | | `POST` | `/api/hives/onboard` | Dashboard auth/session | Hives Onboard | `pkg/dashboard/api_contribute.go:339` | -| `GET` | `/sso` | Public | SSO | `pkg/dashboard/server.go:1657` | +| `GET` | `/sso` | Public | SSO | `pkg/dashboard/server.go:1658` | diff --git a/src/docs/api-reference/health-status-events.md b/src/docs/api-reference/health-status-events.md index a3bc5e453f..719c42552c 100644 --- a/src/docs/api-reference/health-status-events.md +++ b/src/docs/api-reference/health-status-events.md @@ -24,17 +24,17 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `GET` | `/api/version` | Dashboard auth/session | Build/version metadata; includes `upgradeMarker` (`target`, `current`, `attempts`, `maxAttempts`, `failed`, `requestedAt`, `lastError`) while a self-upgrade is in flight or has failed ([#6765](https://github.com/hivecommons/hive/issues/6765)), the hub-delivered `upgradePolicy` (`hub_managed`, `spoke_managed`, `schedule`, `schedule_hour`, `schedule_timezone`, `schedule_weekday`, `paused`, `branch`, `channel`, `target_sha`, `target_resolved`, `armed_target`, and `next_update_at` — the hub's RFC3339 ETA for the next promotion into the `stable` channel, omitted when unknown ([#10256](https://github.com/hivecommons/hive/issues/10256))) when available, and an `autoUpdate` object (`enabled`, `state` — one of `disabled`/`up_to_date`/`behind`/`retrying`/`failed`/`unknown` — `healthy`, `period`, `targetBranch`, `targetCommit`, `currentCommit`, `commitsBehind`, `lastAttemptAt`, `lastError`, `detail`, and `nextUpdateAt` — the hub's RFC3339 ETA for the next update, omitted when unknown, disabled or paused ([#10257](https://github.com/hivecommons/hive/issues/10257))) that never reports a failed or unknown update as healthy ([#6962](https://github.com/hivecommons/hive/issues/6962), [#6963](https://github.com/hivecommons/hive/issues/6963)). Also `startedAt` (RFC3339 process start — changes on every pod roll even when the build does not, so the dashboard can say "Restarted" vs "Upgraded") and, until the first status is published, `startupPhase`/`startupPhaseLabel` (the boot phase a fresh pod is in) ([#15788](https://github.com/hivecommons/hive/issues/15788)) | `pkg/dashboard/api.go:44` | | `GET` | `/api/version/release-notes` | Dashboard auth/session | Changelog gap between two revisions: `?from=&to=` returns `{from:{sha,version?}, to:{sha,ref,version?}, sections:[{version,date,categories:{added,changed,fixed,security,deprecated}}], unreleased?, truncated, source, error?}` — the `CHANGELOG.md` release sections present at `to` and absent at `from`, newest first, plus (when `to` is not a release tag) the `changelog.d/` fragments new at `to` under an `Unreleased (in this build)` section. Fetch failures return `source: "unavailable"` with `error` rather than an error status; results are cached per (from, to) for an hour ([#11065](https://github.com/hivecommons/hive/issues/11065)) | `pkg/dashboard/api.go:45` | | `POST` | `/api/release-channel` | Owner only | Hosted spoke self-service release-channel selector; relays `stable`/`candidate`/`edge` to the hub's existing switch-branch endpoint with the spoke dashboard-token proof, and reports the requested channel as pending until the Deployment image lands | `pkg/dashboard/api.go:67` | -| `GET` | `/api/health` | Public | Basic health probe | `pkg/dashboard/server.go:1630` | -| `GET` | `/api/health/deep` | Public | Deep health probe | `pkg/dashboard/server.go:1631` | -| `GET` | `/api/livez` | Public | Kubernetes liveness probe | `pkg/dashboard/server.go:1632` | -| `GET` | `/metrics` | Registered only when `HIVE_METRICS_ENABLED`; requires `Authorization: ****** (403 if the token is unset) | Prometheus metrics | `pkg/dashboard/server.go:1638` | -| `GET` | `/api/status` | Dashboard auth/session | Dashboard aggregate status; `labelPresets[]` (`{key,label,description,labels[],states[]}`) lists the built-in label-filter presets for the Projects cards, led by `needs-human` whose `labels[]` are the effective hard-suppress labels plus `needs-signal`, the hold labels, `stage/071-needs-author` and the reporter-trust awaiting label (#12172); accepts `?fields=a,b` for top-level selection and `?omit=repos` to drop heavy sections, and honors `Accept-Encoding: gzip`; `agents[]` includes busy-pane visibility fields (`kicksUndeliverable`, `busySince`, `lastTranscriptActivity`, `condition`, `conditionMessage`) when a Working pane cannot accept kicks; a working agent also carries `agents[].run` — the live per-run line (#14576): `{since, elapsedS, costUSD, tokens, priced, tests, filesChanged}`, the estimated spend/tokens since the kick was delivered (`lastKickAt`, falling back to `busySince`) (delta of the token collector's per-agent cumulative figure; `priced:false` when the agent has none yet), the last visible test-runner result (`pass`/`fail`/empty) and the last `N files changed` git summary (`-1` when none) parsed from the captured pane; top-level `fleetRun` `{running, hourUSD, hourPriced, dayUSD, weekUSD, monthUSD, windowsPriced}` is the governor strip's rotating `running N · $X this hour / today / this week / this month` figure (#15614) — the hour is the rise since the top of the clock hour, the wider windows are the daily cost ledger summed from 00:00 UTC today, Monday 00:00 UTC (ISO week) and the 1st 00:00 UTC plus the rise since the ledger's last snapshot, `windowsPriced:false` when there is no ledger yet; `sla` (fleet) and `repos[].sla` (per repo) carry the Delivery SLA block derived from the lifecycle timeline with no extra GitHub calls: `windows.{7d,30d}.{open_to_triage,triage_to_start,start_to_pr,pr_to_merge,open_to_merge}` as `{p50_h,p95_h,n}` (hours, nearest-rank), `history[]` of up to 30 daily buckets `{day,start_to_pr_p50,pr_to_merge_p50,open_to_merge_p50,n_started,n_pr,n_merged}` persisted under `/data/sla-history.json`, `stale_in_progress[]` (`{number,repo,started_at,age_h,agent}` — issues carrying `hive/in-progress` longer than the agent claim TTL with no linked PR), `stale_count`, `merged_7d`, `claim_ttl_s` and, on the fleet block, the effective `targets` (`start_to_pr_h`, `pr_to_merge_h`, `open_to_merge_h`); `staleSince` and `repos[].countsStale` / `countsStaleSince` mark totals served from last-good figures — the previous enumeration (#13382) or the ForgeState cache's last-good counts (#13376); `ci_failure_signals` `{count, last, kicks, unmatched}` is the webhook CI-failure signal store — distinct red (repo, head, check) signals retained, the most recent one `{repo, number, head_sha, check, conclusion, details_url, agent, at}`, webhook-triggered kicks/nudges since boot, and failure deliveries whose head matched no open PR; `hotspots` `{count, actionable, filed}` is the merge-hotspot advisor's one-line summary (files at/above the thresholds, those with a split recommendation, those with a modularize issue filed), absent when the advisor is not wired — details on `GET /api/hotspots`; `writeback.dedupe` `{enabled, dedupe_same_item, dedupe_burst, rate_capped, hourly_cap, burst_items, burst_window_s, same_item_ttl_s}` is the write-back gate's content layer — the effective `writeback.dedupe.*` settings and the last-hour counts of writes held as `duplicate`, `burst` and `rate-capped` (each also listed under `GET /api/writeback/suppressed`) | `pkg/dashboard/server.go:1643` | -| `GET` | `/api/status/summary` | Dashboard auth/session | Compact agent/governor/budget status summary for pollers; honors `Accept-Encoding: gzip` | `pkg/dashboard/server.go:1644` | -| `GET` | `/api/overview/issues.csv` | Dashboard auth/session | Cached Overview issue-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1645` | -| `GET` | `/api/overview/issues.json` | Dashboard auth/session | Cached Overview issue-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1646` | -| `GET` | `/api/overview/prs.csv` | Dashboard auth/session | Cached Overview PR-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1647` | -| `GET` | `/api/overview/prs.json` | Dashboard auth/session | Cached Overview PR-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1648` | -| `GET` | `/api/events` | Dashboard auth/session | Server-sent event stream | `pkg/dashboard/server.go:1649` | +| `GET` | `/api/health` | Public | Basic health probe | `pkg/dashboard/server.go:1631` | +| `GET` | `/api/health/deep` | Public | Deep health probe | `pkg/dashboard/server.go:1632` | +| `GET` | `/api/livez` | Public | Kubernetes liveness probe | `pkg/dashboard/server.go:1633` | +| `GET` | `/metrics` | Registered only when `HIVE_METRICS_ENABLED`; requires `Authorization: ****** (403 if the token is unset) | Prometheus metrics | `pkg/dashboard/server.go:1639` | +| `GET` | `/api/status` | Dashboard auth/session | Dashboard aggregate status; `labelPresets[]` (`{key,label,description,labels[],states[]}`) lists the built-in label-filter presets for the Projects cards, led by `needs-human` whose `labels[]` are the effective hard-suppress labels plus `needs-signal`, the hold labels, `stage/071-needs-author` and the reporter-trust awaiting label (#12172); accepts `?fields=a,b` for top-level selection and `?omit=repos` to drop heavy sections, and honors `Accept-Encoding: gzip`; `agents[]` includes busy-pane visibility fields (`kicksUndeliverable`, `busySince`, `lastTranscriptActivity`, `condition`, `conditionMessage`) when a Working pane cannot accept kicks; a working agent also carries `agents[].run` — the live per-run line (#14576): `{since, elapsedS, costUSD, tokens, priced, tests, filesChanged}`, the estimated spend/tokens since the kick was delivered (`lastKickAt`, falling back to `busySince`) (delta of the token collector's per-agent cumulative figure; `priced:false` when the agent has none yet), the last visible test-runner result (`pass`/`fail`/empty) and the last `N files changed` git summary (`-1` when none) parsed from the captured pane; top-level `fleetRun` `{running, hourUSD, hourPriced, dayUSD, weekUSD, monthUSD, windowsPriced}` is the governor strip's rotating `running N · $X this hour / today / this week / this month` figure (#15614) — the hour is the rise since the top of the clock hour, the wider windows are the daily cost ledger summed from 00:00 UTC today, Monday 00:00 UTC (ISO week) and the 1st 00:00 UTC plus the rise since the ledger's last snapshot, `windowsPriced:false` when there is no ledger yet; `sla` (fleet) and `repos[].sla` (per repo) carry the Delivery SLA block derived from the lifecycle timeline with no extra GitHub calls: `windows.{7d,30d}.{open_to_triage,triage_to_start,start_to_pr,pr_to_merge,open_to_merge}` as `{p50_h,p95_h,n}` (hours, nearest-rank), `history[]` of up to 30 daily buckets `{day,start_to_pr_p50,pr_to_merge_p50,open_to_merge_p50,n_started,n_pr,n_merged}` persisted under `/data/sla-history.json`, `stale_in_progress[]` (`{number,repo,started_at,age_h,agent}` — issues carrying `hive/in-progress` longer than the agent claim TTL with no linked PR), `stale_count`, `merged_7d`, `claim_ttl_s` and, on the fleet block, the effective `targets` (`start_to_pr_h`, `pr_to_merge_h`, `open_to_merge_h`); `staleSince` and `repos[].countsStale` / `countsStaleSince` mark totals served from last-good figures — the previous enumeration (#13382) or the ForgeState cache's last-good counts (#13376); `ci_failure_signals` `{count, last, kicks, unmatched}` is the webhook CI-failure signal store — distinct red (repo, head, check) signals retained, the most recent one `{repo, number, head_sha, check, conclusion, details_url, agent, at}`, webhook-triggered kicks/nudges since boot, and failure deliveries whose head matched no open PR; `hotspots` `{count, actionable, filed}` is the merge-hotspot advisor's one-line summary (files at/above the thresholds, those with a split recommendation, those with a modularize issue filed), absent when the advisor is not wired — details on `GET /api/hotspots`; `writeback.dedupe` `{enabled, dedupe_same_item, dedupe_burst, rate_capped, hourly_cap, burst_items, burst_window_s, same_item_ttl_s}` is the write-back gate's content layer — the effective `writeback.dedupe.*` settings and the last-hour counts of writes held as `duplicate`, `burst` and `rate-capped` (each also listed under `GET /api/writeback/suppressed`) | `pkg/dashboard/server.go:1644` | +| `GET` | `/api/status/summary` | Dashboard auth/session | Compact agent/governor/budget status summary for pollers; honors `Accept-Encoding: gzip` | `pkg/dashboard/server.go:1645` | +| `GET` | `/api/overview/issues.csv` | Dashboard auth/session | Cached Overview issue-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1646` | +| `GET` | `/api/overview/issues.json` | Dashboard auth/session | Cached Overview issue-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1647` | +| `GET` | `/api/overview/prs.csv` | Dashboard auth/session | Cached Overview PR-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1648` | +| `GET` | `/api/overview/prs.json` | Dashboard auth/session | Cached Overview PR-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1649` | +| `GET` | `/api/events` | Dashboard auth/session | Server-sent event stream | `pkg/dashboard/server.go:1650` | | `GET` | `/api/swarm` | Dashboard auth/session | Current swarm status: display name, duration, active repo, expiry, persisted prep metrics when available, and idle-unlock fields. | `pkg/dashboard/swarm.go:310` | | `POST` | `/api/swarm` | Owner only | Start a 24h repo swarm for a configured repo, returning 409 when another swarm is active and 423 when a previous swarm keeps the next swarm locked until enough agents are idle unless body `{"repo":"owner/name","force":true}` is used; saves the active record before repo prep, persists prep metrics, and announces the start to Discord when configured. | `pkg/dashboard/swarm.go:311` | | `DELETE` | `/api/swarm` | Owner only | End the active swarm, score issues closed and PRs merged in the window, append it to history, and announce the result to Discord when configured. | `pkg/dashboard/swarm.go:312` | diff --git a/src/docs/api-reference/snapshots-and-style.md b/src/docs/api-reference/snapshots-and-style.md index 6d098cdf84..94bdae639f 100644 --- a/src/docs/api-reference/snapshots-and-style.md +++ b/src/docs/api-reference/snapshots-and-style.md @@ -6,7 +6,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | Method | Path | Auth | Purpose | Source | |---|---|---|---|---| | `GET` | `/api/style` | Public | Sanitized custom dashboard CSS | `pkg/dashboard/api.go:46` | -| `GET` | `/branding/custom.css` | Dashboard auth/session | Operator branding stylesheet override, read per request (see [branding](../branding.md)) | `pkg/dashboard/server.go:1710` | +| `GET` | `/branding/custom.css` | Dashboard auth/session | Operator branding stylesheet override, read per request (see [branding](../branding.md)) | `pkg/dashboard/server.go:1711` | | `GET` | `/api/snapshot/frame-ancestors` | Public | Snapshot framing allowlist | `pkg/dashboard/api.go:80` | | `GET` | `/api/snapshot` | Public | Snapshot data | `pkg/dashboard/api.go:81` | | `GET` | `/snapshot` | Public | Public read-only snapshot page | `pkg/dashboard/api.go:82` | From 92620167595131bf8a28357c9f50966eb74ef4cc Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 21:13:02 -0400 Subject: [PATCH 13/14] =?UTF-8?q?=F0=9F=90=9B=20Bound=20native=20observati?= =?UTF-8?q?on=20cache=20across=20scope=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- src/docs/native-merge-queue.md | 3 ++- .../dashboard/stage_tracker_native_queue.go | 26 ++++++++++++++++--- .../stage_tracker_native_queue_test.go | 14 ++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/docs/native-merge-queue.md b/src/docs/native-merge-queue.md index 0b6dbf75a5..00f5a0c284 100644 --- a/src/docs/native-merge-queue.md +++ b/src/docs/native-merge-queue.md @@ -111,7 +111,8 @@ previously observed exact queued/member head records a merged receipt and its actual merge SHA. Failed required CI is shown on that candidate; moved/expired refs do not prove failure, rebuild or merge. No rebuild reason, percentage or ETA is invented. The last 32 lifecycle receipts and 16 event hints are memory-bounded, -not an exhaustive durable audit: missed deliveries and restart gaps remain +not an exhaustive durable audit. At most 32 scope snapshots are retained; +evicted or not-yet-observed configured scopes report unknown. Missed deliveries and restart gaps remain explicit. Configure delivery of `merge_group` and `pull_request` events to the existing authenticated webhook endpoint for full event evidence; discovery without a signed group base intentionally leaves member mapping unknown. diff --git a/src/pkg/dashboard/stage_tracker_native_queue.go b/src/pkg/dashboard/stage_tracker_native_queue.go index 325951008a..df16f25868 100644 --- a/src/pkg/dashboard/stage_tracker_native_queue.go +++ b/src/pkg/dashboard/stage_tracker_native_queue.go @@ -18,6 +18,7 @@ const ( nativeQueueObservationScopes = 2 nativeQueueObservationHistory = 32 nativeQueueObservationHints = 16 + nativeQueueObservationCache = 32 ) type nativeQueueHint struct { @@ -104,7 +105,7 @@ func (s *Server) ReconcileNativeQueues(ctx context.Context) error { observation.Provider, observation.Repo, observation.Base = "github-native", scope[0], scope[1] observation.State, observation.Stale = "unavailable", true observation.Reason = "GitHub App installation authentication is unavailable; queue evidence cannot be refreshed." - runtime.observations[key] = observation + runtime.storeObservation(key, observation) } runtime.mu.Unlock() return fmt.Errorf("native queue observation requires GitHub App installation authentication") @@ -141,12 +142,29 @@ func (s *Server) ReconcileNativeQueues(ctx context.Context) error { } else if exists { observation = nativeQueueObservationDelta(prior, observation, now) } - runtime.observations[key] = observation + runtime.storeObservation(key, observation) runtime.mu.Unlock() } return nil } +// Caller holds mu; old scopes cannot accumulate across Settings changes. +func (runtime *nativeQueueTrackerRuntime) storeObservation(key string, observation forgequeue.Observation) { + if runtime.observations == nil { + runtime.observations = make(map[string]forgequeue.Observation) + } + if _, exists := runtime.observations[key]; !exists && len(runtime.observations) >= nativeQueueObservationCache { + oldest := "" + for scope, prior := range runtime.observations { + if oldest == "" || prior.ObservedAt.Before(runtime.observations[oldest].ObservedAt) { + oldest = scope + } + } + delete(runtime.observations, oldest) + } + runtime.observations[key] = observation +} + func nativeQueueObservationDelta(prior, next forgequeue.Observation, now time.Time) forgequeue.Observation { next.Outcomes = append([]forgequeue.Outcome{}, prior.Outcomes...) if !prior.EntriesComplete || !next.EntriesComplete { @@ -218,7 +236,7 @@ func (s *Server) observeNativeQueueEvent(event string, body []byte, at time.Time hintKey := key + "/" + group.HeadSHA switch payload.Action { case "checks_requested": - if len(runtime.hints) >= nativeQueueObservationHints { + if _, exists := runtime.hints[hintKey]; !exists && len(runtime.hints) >= nativeQueueObservationHints { oldest := "" for id, hint := range runtime.hints { if oldest == "" || hint.at.Before(runtime.hints[oldest].at) { @@ -261,7 +279,7 @@ func (s *Server) observeNativeQueueEvent(event string, body []byte, at time.Time }) } } - runtime.observations[key] = observation + runtime.storeObservation(key, observation) } // Cached projection only; it never consults GitHub from a tracker request. diff --git a/src/pkg/dashboard/stage_tracker_native_queue_test.go b/src/pkg/dashboard/stage_tracker_native_queue_test.go index 69a59e23ad..5531846867 100644 --- a/src/pkg/dashboard/stage_tracker_native_queue_test.go +++ b/src/pkg/dashboard/stage_tracker_native_queue_test.go @@ -119,3 +119,17 @@ func TestNativeQueueRemovalRequiresCompleteSnapshots(t *testing.T) { t.Fatal("incomplete prior snapshot claimed removal") } } + +func TestNativeQueueSnapshotCacheBoundedAcrossScopeChanges(t *testing.T) { + var runtime nativeQueueTrackerRuntime + for i := 0; i <= nativeQueueObservationCache; i++ { + key := time.Unix(int64(i), 0).String() + runtime.storeObservation(key, forgequeue.Observation{ObservedAt: time.Unix(int64(i), 0)}) + } + if len(runtime.observations) != nativeQueueObservationCache { + t.Fatal("scope changes created an unbounded snapshot cache") + } + if _, exists := runtime.observations[time.Unix(0, 0).String()]; exists { + t.Fatal("oldest observation not evicted") + } +} From 44e12bd82832676563c5fb52bbc9dcdee2933a24 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Fri, 30 Oct 2026 21:21:22 -0400 Subject: [PATCH 14/14] =?UTF-8?q?=F0=9F=90=9B=20Reuse=20ForgeState=20queue?= =?UTF-8?q?=20observations=20and=20existing=20dashboard=20tokens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- src/docs/native-merge-queue.md | 2 +- src/pkg/dashboard/stage_tracker.go | 4 +- .../dashboard/stage_tracker_native_queue.go | 50 ++++++------- .../stage_tracker_native_queue_test.go | 24 +++---- .../static-src/css/tracker-native-queue.css | 14 ++-- src/pkg/dashboard/static/index.html | 14 ++-- .../dashboard/webstatic/style_ratchet_test.go | 4 +- src/pkg/forgequeue/observation.go | 66 ----------------- src/pkg/forgestate/queue_observation.go | 70 +++++++++++++++++++ src/pkg/github/native_queue_observation.go | 30 ++++---- .../github/native_queue_observation_test.go | 4 +- 11 files changed, 143 insertions(+), 139 deletions(-) delete mode 100644 src/pkg/forgequeue/observation.go create mode 100644 src/pkg/forgestate/queue_observation.go diff --git a/src/docs/native-merge-queue.md b/src/docs/native-merge-queue.md index 00f5a0c284..997376c477 100644 --- a/src/docs/native-merge-queue.md +++ b/src/docs/native-merge-queue.md @@ -87,7 +87,7 @@ never substitutes green PR-head checks. Classic protection and applicable rules must both be readable before required policy is known. Missing/pending/skipped checks or unreadable policy are never portrayed as passing. -The provider-neutral `forgequeue.Observation` contract is read-only and carries +The provider-neutral `forgestate.QueueObservation` contract is read-only and carries no admission or merge authority. The GitHub adapter feeds an in-memory cache from the existing governor cycle, at most once per three minutes, rotating across two scopes per pass with one 45-second background budget. Each scope diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 9a081e481a..ede8a28590 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -10,7 +10,7 @@ import ( "time" "github.com/hivecommons/hive/pkg/dashboard/collect" - "github.com/hivecommons/hive/pkg/forgequeue" + forgequeue "github.com/hivecommons/hive/pkg/forgestate" "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/stageengine" "github.com/hivecommons/hive/pkg/stagelabels" @@ -46,7 +46,7 @@ type StageTrackerResponse struct { Stages []StageTrackerStage `json:"stages"` Items []StageTrackerItem `json:"items"` BasePreparation []StageTrackerPreparationQueue `json:"base_preparation,omitempty"` - IntegrationQueues []forgequeue.Observation `json:"integration_queues,omitempty"` + IntegrationQueues []forgequeue.QueueObservation `json:"integration_queues,omitempty"` // OpenIssues and OpenPRs count Items by kind. Items is the canonical // open-items set (open_items.go), so these equal the Overview tile's // total open issues and PRs; the SPA prints them in the section header diff --git a/src/pkg/dashboard/stage_tracker_native_queue.go b/src/pkg/dashboard/stage_tracker_native_queue.go index df16f25868..6c430014cd 100644 --- a/src/pkg/dashboard/stage_tracker_native_queue.go +++ b/src/pkg/dashboard/stage_tracker_native_queue.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/hivecommons/hive/pkg/forgequeue" + forgequeue "github.com/hivecommons/hive/pkg/forgestate" ) const ( @@ -24,7 +24,7 @@ const ( type nativeQueueHint struct { repo, base string at time.Time - candidate forgequeue.Candidate + candidate forgequeue.QueueCandidate } type nativeQueueTrackerRuntime struct { @@ -32,7 +32,7 @@ type nativeQueueTrackerRuntime struct { lastAttempt time.Time inFlight bool scopeOffset int - observations map[string]forgequeue.Observation + observations map[string]forgequeue.QueueObservation hints map[string]nativeQueueHint } @@ -98,7 +98,7 @@ func (s *Server) ReconcileNativeQueues(ctx context.Context) error { if s.deps.GHClient == nil || !s.deps.GHClient.NativeMergeQueueAvailable() { runtime.mu.Lock() if runtime.observations == nil { - runtime.observations = make(map[string]forgequeue.Observation) + runtime.observations = make(map[string]forgequeue.QueueObservation) } for key, scope := range scopes { observation := runtime.observations[key] @@ -121,7 +121,7 @@ func (s *Server) ReconcileNativeQueues(ctx context.Context) error { } } sort.Slice(orderedHints, func(i, j int) bool { return orderedHints[i].at.After(orderedHints[j].at) }) - hints := make([]forgequeue.Candidate, 0, len(orderedHints)) + hints := make([]forgequeue.QueueCandidate, 0, len(orderedHints)) for _, hint := range orderedHints { hints = append(hints, hint.candidate) } @@ -129,7 +129,7 @@ func (s *Server) ReconcileNativeQueues(ctx context.Context) error { observation, err := s.deps.GHClient.ReadNativeQueueObservation(ctx, scope[0], scope[1], hints) runtime.mu.Lock() if runtime.observations == nil { - runtime.observations = make(map[string]forgequeue.Observation) + runtime.observations = make(map[string]forgequeue.QueueObservation) } prior, exists := runtime.observations[key] if err != nil { @@ -149,9 +149,9 @@ func (s *Server) ReconcileNativeQueues(ctx context.Context) error { } // Caller holds mu; old scopes cannot accumulate across Settings changes. -func (runtime *nativeQueueTrackerRuntime) storeObservation(key string, observation forgequeue.Observation) { +func (runtime *nativeQueueTrackerRuntime) storeObservation(key string, observation forgequeue.QueueObservation) { if runtime.observations == nil { - runtime.observations = make(map[string]forgequeue.Observation) + runtime.observations = make(map[string]forgequeue.QueueObservation) } if _, exists := runtime.observations[key]; !exists && len(runtime.observations) >= nativeQueueObservationCache { oldest := "" @@ -165,8 +165,8 @@ func (runtime *nativeQueueTrackerRuntime) storeObservation(key string, observati runtime.observations[key] = observation } -func nativeQueueObservationDelta(prior, next forgequeue.Observation, now time.Time) forgequeue.Observation { - next.Outcomes = append([]forgequeue.Outcome{}, prior.Outcomes...) +func nativeQueueObservationDelta(prior, next forgequeue.QueueObservation, now time.Time) forgequeue.QueueObservation { + next.Outcomes = append([]forgequeue.QueueOutcome{}, prior.Outcomes...) if !prior.EntriesComplete || !next.EntriesComplete { return next } @@ -176,7 +176,7 @@ func nativeQueueObservationDelta(prior, next forgequeue.Observation, now time.Ti found = found || entry.ID == current.ID } if !found { - next.Outcomes = appendNativeQueueOutcome(next.Outcomes, forgequeue.Outcome{ + next.Outcomes = appendNativeQueueOutcome(next.Outcomes, forgequeue.QueueOutcome{ Kind: "entry-removed", PR: entry.PR, Head: entry.Head, ObservedAt: now, Source: "complete-queue-snapshot-difference", }) } @@ -184,7 +184,7 @@ func nativeQueueObservationDelta(prior, next forgequeue.Observation, now time.Ti return next } -func appendNativeQueueOutcome(out []forgequeue.Outcome, next forgequeue.Outcome) []forgequeue.Outcome { +func appendNativeQueueOutcome(out []forgequeue.QueueOutcome, next forgequeue.QueueOutcome) []forgequeue.QueueOutcome { for _, prior := range out { if prior.Kind == next.Kind && prior.PR == next.PR && prior.Head == next.Head && prior.CandidateSHA == next.CandidateSHA && prior.MergeSHA == next.MergeSHA { @@ -220,7 +220,7 @@ func (s *Server) observeNativeQueueEvent(event string, body []byte, at time.Time runtime.mu.Lock() defer runtime.mu.Unlock() if runtime.observations == nil { - runtime.observations = make(map[string]forgequeue.Observation) + runtime.observations = make(map[string]forgequeue.QueueObservation) } key := nativeQueueScopeKey(repo, base) observation := runtime.observations[key] @@ -246,10 +246,10 @@ func (s *Server) observeNativeQueueEvent(event string, body []byte, at time.Time delete(runtime.hints, oldest) } runtime.hints[hintKey] = nativeQueueHint{repo: repo, base: base, at: at, - candidate: forgequeue.Candidate{SHA: group.HeadSHA, Ref: group.HeadRef, BaseSHA: group.BaseSHA}} + candidate: forgequeue.QueueCandidate{SHA: group.HeadSHA, Ref: group.HeadRef, BaseSHA: group.BaseSHA}} case "destroyed": delete(runtime.hints, hintKey) - observation.Outcomes = appendNativeQueueOutcome(observation.Outcomes, forgequeue.Outcome{ + observation.Outcomes = appendNativeQueueOutcome(observation.Outcomes, forgequeue.QueueOutcome{ Kind: "candidate-destroyed", CandidateSHA: group.HeadSHA, ObservedAt: at, Source: "signed-merge-group-webhook", }) for i := range observation.Candidates { @@ -273,7 +273,7 @@ func (s *Server) observeNativeQueueEvent(event string, body []byte, at time.Time } } if observedMember && pr.GetMergeCommitSHA() != "" { - observation.Outcomes = appendNativeQueueOutcome(observation.Outcomes, forgequeue.Outcome{ + observation.Outcomes = appendNativeQueueOutcome(observation.Outcomes, forgequeue.QueueOutcome{ Kind: "merged", PR: pr.GetNumber(), Head: pr.GetHead().GetSHA(), MergeSHA: pr.GetMergeCommitSHA(), ObservedAt: at, Source: "signed-pull-request-merged-webhook", }) @@ -283,32 +283,32 @@ func (s *Server) observeNativeQueueEvent(event string, body []byte, at time.Time } // Cached projection only; it never consults GitHub from a tracker request. -func (s *Server) stageTrackerNativeQueues(now time.Time) []forgequeue.Observation { +func (s *Server) stageTrackerNativeQueues(now time.Time) []forgequeue.QueueObservation { if s == nil || s.deps == nil || s.deps.Config == nil || !s.deps.Config.AutoMerge.NativeMergeQueue.Enabled { return nil } runtime := &s.nativeQueueTracker runtime.mu.Lock() defer runtime.mu.Unlock() - result := []forgequeue.Observation{} + result := []forgequeue.QueueObservation{} for _, original := range runtime.observations { if !s.nativeQueueScopeAllowed(original.Repo, original.Base) { continue } // Copy nested slices: event writes must not mutate an encoded response. observation := original - observation.Entries = append([]forgequeue.Entry{}, original.Entries...) + observation.Entries = append([]forgequeue.QueueEntry{}, original.Entries...) for i := range observation.Entries { if original.Entries[i].EnqueuedAt != nil { at := *original.Entries[i].EnqueuedAt observation.Entries[i].EnqueuedAt = &at } } - observation.Outcomes = append([]forgequeue.Outcome{}, original.Outcomes...) - observation.Candidates = append([]forgequeue.Candidate{}, original.Candidates...) + observation.Outcomes = append([]forgequeue.QueueOutcome{}, original.Outcomes...) + observation.Candidates = append([]forgequeue.QueueCandidate{}, original.Candidates...) for i := range observation.Candidates { - observation.Candidates[i].Members = append([]forgequeue.Member{}, original.Candidates[i].Members...) - observation.Candidates[i].Checks = append([]forgequeue.Check{}, original.Candidates[i].Checks...) + observation.Candidates[i].Members = append([]forgequeue.QueueMember{}, original.Candidates[i].Members...) + observation.Candidates[i].Checks = append([]forgequeue.QueueCheck{}, original.Candidates[i].Checks...) } observation.Stale = observation.Stale || observation.ObservedAt.IsZero() || now.Sub(observation.ObservedAt) > 2*nativeQueueObservationInterval observation.FreshForS = int64((2 * nativeQueueObservationInterval).Seconds()) @@ -324,12 +324,12 @@ func (s *Server) stageTrackerNativeQueues(now time.Time) []forgequeue.Observatio exists = exists || nativeQueueScopeKey(repo, base) == nativeQueueScopeKey(observation.Repo, observation.Base) } if !exists { - result = append(result, forgequeue.Observation{Provider: "github-native", Repo: repo, Base: base, State: "unknown", Stale: true, + result = append(result, forgequeue.QueueObservation{Provider: "github-native", Repo: repo, Base: base, State: "unknown", Stale: true, Reason: "No authoritative snapshot for this scope yet; bounded background reconciliation rotates across scopes."}) } } if len(result) == 0 { - result = append(result, forgequeue.Observation{Provider: "github-native", State: "unknown", Stale: true, + result = append(result, forgequeue.QueueObservation{Provider: "github-native", State: "unknown", Stale: true, Reason: "No authoritative queue snapshot yet. Select exact repo/base scopes in Settings; authenticated events and background reconciliation supply observations."}) } sort.Slice(result, func(i, j int) bool { diff --git a/src/pkg/dashboard/stage_tracker_native_queue_test.go b/src/pkg/dashboard/stage_tracker_native_queue_test.go index 5531846867..2a933173ac 100644 --- a/src/pkg/dashboard/stage_tracker_native_queue_test.go +++ b/src/pkg/dashboard/stage_tracker_native_queue_test.go @@ -9,15 +9,15 @@ import ( "time" "github.com/hivecommons/hive/pkg/config" - "github.com/hivecommons/hive/pkg/forgequeue" + forgequeue "github.com/hivecommons/hive/pkg/forgestate" ) func TestNativeQueueTrackerOffScopeStaleAndCopy(t *testing.T) { s := covApiServer(t) now := time.Now() - s.nativeQueueTracker.observations = map[string]forgequeue.Observation{ + s.nativeQueueTracker.observations = map[string]forgequeue.QueueObservation{ "o/r#v5": {Provider: "github-native", Repo: "o/r", Base: "v5", State: "observed", Complete: true, - ObservedAt: now.Add(-time.Hour), Candidates: []forgequeue.Candidate{{SHA: "candidate", Membership: "proven", Members: []forgequeue.Member{{PR: 7, Head: "head"}}, Checks: []forgequeue.Check{{Name: "test"}}}}}, + ObservedAt: now.Add(-time.Hour), Candidates: []forgequeue.QueueCandidate{{SHA: "candidate", Membership: "proven", Members: []forgequeue.QueueMember{{PR: 7, Head: "head"}}, Checks: []forgequeue.QueueCheck{{Name: "test"}}}}}, "o/r#v6": {Repo: "o/r", Base: "v6"}, } if s.stageTrackerNativeQueues(now) != nil || s.ReconcileNativeQueues(context.Background()) != nil || !s.nativeQueueTracker.lastAttempt.IsZero() { @@ -54,9 +54,9 @@ func TestNativeQueueLifecycleNeverMergesAtEnqueue(t *testing.T) { s := covApiServer(t) s.deps.Config.AutoMerge.NativeMergeQueue = config.NativeMergeQueueAutoMergeConfig{Enabled: true, Repos: []string{"o/r"}, Bases: []string{"o/r#v5"}} now := time.Now() - s.nativeQueueTracker.observations = map[string]forgequeue.Observation{"o/r#v5": { + s.nativeQueueTracker.observations = map[string]forgequeue.QueueObservation{"o/r#v5": { Provider: "github-native", Repo: "o/r", Base: "v5", State: "observed", Complete: true, ObservedAt: now, - Entries: []forgequeue.Entry{{ID: "entry", PR: 7, Head: "head", Position: 1}}, + Entries: []forgequeue.QueueEntry{{ID: "entry", PR: 7, Head: "head", Position: 1}}, }} deliver := func(action string) { t.Helper() @@ -88,15 +88,15 @@ func TestNativeQueueLifecycleNeverMergesAtEnqueue(t *testing.T) { t.Fatalf("exact merged receipt missing: %+v", got) } // No pipeline rows or merge ledger entries are rewritten by observations. - if !reflect.DeepEqual(got[0].Entries, []forgequeue.Entry{{ID: "entry", PR: 7, Head: "head", Position: 1}}) { + if !reflect.DeepEqual(got[0].Entries, []forgequeue.QueueEntry{{ID: "entry", PR: 7, Head: "head", Position: 1}}) { t.Fatal("outcome observation rewrote the queue into a pipeline") } } func TestNativeQueueOutcomeHistoryBounded(t *testing.T) { - var outcomes []forgequeue.Outcome + var outcomes []forgequeue.QueueOutcome for pr := 1; pr <= nativeQueueObservationHistory+1; pr++ { - outcomes = appendNativeQueueOutcome(outcomes, forgequeue.Outcome{Kind: "entry-removed", PR: pr}) + outcomes = appendNativeQueueOutcome(outcomes, forgequeue.QueueOutcome{Kind: "entry-removed", PR: pr}) } if len(outcomes) != nativeQueueObservationHistory || outcomes[0].PR != 2 { t.Fatal("unbounded native lifecycle history") @@ -104,9 +104,9 @@ func TestNativeQueueOutcomeHistoryBounded(t *testing.T) { } func TestNativeQueueRemovalRequiresCompleteSnapshots(t *testing.T) { - prior := forgequeue.Observation{EntriesComplete: true, Entries: []forgequeue.Entry{{ID: "entry", PR: 7, Head: "head"}}} + prior := forgequeue.QueueObservation{EntriesComplete: true, Entries: []forgequeue.QueueEntry{{ID: "entry", PR: 7, Head: "head"}}} for _, complete := range []bool{false, true} { - next := nativeQueueObservationDelta(prior, forgequeue.Observation{EntriesComplete: complete}, time.Now()) + next := nativeQueueObservationDelta(prior, forgequeue.QueueObservation{EntriesComplete: complete}, time.Now()) if (len(next.Outcomes) == 1) != complete { t.Fatalf("partial snapshot claimed removal: %+v", next) } @@ -115,7 +115,7 @@ func TestNativeQueueRemovalRequiresCompleteSnapshots(t *testing.T) { } } prior.EntriesComplete = false - if got := nativeQueueObservationDelta(prior, forgequeue.Observation{EntriesComplete: true}, time.Now()); len(got.Outcomes) != 0 { + if got := nativeQueueObservationDelta(prior, forgequeue.QueueObservation{EntriesComplete: true}, time.Now()); len(got.Outcomes) != 0 { t.Fatal("incomplete prior snapshot claimed removal") } } @@ -124,7 +124,7 @@ func TestNativeQueueSnapshotCacheBoundedAcrossScopeChanges(t *testing.T) { var runtime nativeQueueTrackerRuntime for i := 0; i <= nativeQueueObservationCache; i++ { key := time.Unix(int64(i), 0).String() - runtime.storeObservation(key, forgequeue.Observation{ObservedAt: time.Unix(int64(i), 0)}) + runtime.storeObservation(key, forgequeue.QueueObservation{ObservedAt: time.Unix(int64(i), 0)}) } if len(runtime.observations) != nativeQueueObservationCache { t.Fatal("scope changes created an unbounded snapshot cache") diff --git a/src/pkg/dashboard/static-src/css/tracker-native-queue.css b/src/pkg/dashboard/static-src/css/tracker-native-queue.css index ba9a7dd57f..7b6b49b966 100644 --- a/src/pkg/dashboard/static-src/css/tracker-native-queue.css +++ b/src/pkg/dashboard/static-src/css/tracker-native-queue.css @@ -1,8 +1,8 @@ - .nq-rail { margin: 12px 0; padding: 12px; border: 1px solid var(--border-color); border-radius: 8px; overflow-wrap: anywhere; } - .nq-rail h3, .nq-rail h4, .nq-rail h5 { margin: 8px 0; } + .nq-rail { margin: var(--sp-5) 0; padding: var(--sp-5); border: 1px solid var(--border-color); border-radius: var(--r); overflow-wrap: anywhere; } + .nq-rail h3, .nq-rail h4, .nq-rail h5 { margin: var(--sp-4) 0; } .nq-muted { color: var(--text-secondary); font-size: var(--fs-sm); } - .nq-scope { margin-top: 12px; border-top: 1px solid var(--border-color); } - .nq-candidates { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; } - .nq-candidate { padding: 10px; border: 1px solid var(--border-color); border-radius: 6px; min-width: 0; } - .nq-entries, .nq-candidate ul { padding-left: 24px; } - .nq-rail li { margin: 6px 0; } + .nq-scope { margin-top: var(--sp-5); border-top: 1px solid var(--border-color); } + .nq-candidates { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: var(--sp-5); } + .nq-candidate { padding: var(--sp-5); border: 1px solid var(--border-color); border-radius: var(--r-sm); min-width: 0; } + .nq-entries, .nq-candidate ul { padding-left: var(--sp-8); } + .nq-rail li { margin: var(--sp-3) 0; } diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index b159ece726..c927f4ce7c 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -2180,14 +2180,14 @@ .sts-sample { padding: var(--sp-3) var(--sp-2) 0; } .sts-sample .ham-row { padding: var(--sp-2); } .sts-sample .ham-cols { padding-top: 0; } - .nq-rail { margin: 12px 0; padding: 12px; border: 1px solid var(--border-color); border-radius: 8px; overflow-wrap: anywhere; } - .nq-rail h3, .nq-rail h4, .nq-rail h5 { margin: 8px 0; } + .nq-rail { margin: var(--sp-5) 0; padding: var(--sp-5); border: 1px solid var(--border-color); border-radius: var(--r); overflow-wrap: anywhere; } + .nq-rail h3, .nq-rail h4, .nq-rail h5 { margin: var(--sp-4) 0; } .nq-muted { color: var(--text-secondary); font-size: var(--fs-sm); } - .nq-scope { margin-top: 12px; border-top: 1px solid var(--border-color); } - .nq-candidates { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; } - .nq-candidate { padding: 10px; border: 1px solid var(--border-color); border-radius: 6px; min-width: 0; } - .nq-entries, .nq-candidate ul { padding-left: 24px; } - .nq-rail li { margin: 6px 0; } + .nq-scope { margin-top: var(--sp-5); border-top: 1px solid var(--border-color); } + .nq-candidates { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: var(--sp-5); } + .nq-candidate { padding: var(--sp-5); border: 1px solid var(--border-color); border-radius: var(--r-sm); min-width: 0; } + .nq-entries, .nq-candidate ul { padding-left: var(--sp-8); } + .nq-rail li { margin: var(--sp-3) 0; } .agent-blockers { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-1) var(--sp-3); font-size: var(--fs-xs); margin-top: var(--sp-2); color: var(--muted); } .agent-blockers .ab-key { opacity: 0.65; margin-right: 3px; } .agent-blockers .ab-seg { white-space: nowrap; } diff --git a/src/pkg/dashboard/webstatic/style_ratchet_test.go b/src/pkg/dashboard/webstatic/style_ratchet_test.go index 34a5b7ff10..82873c6618 100644 --- a/src/pkg/dashboard/webstatic/style_ratchet_test.go +++ b/src/pkg/dashboard/webstatic/style_ratchet_test.go @@ -26,9 +26,9 @@ type styleRatchetCounts struct { // removes raw styling — but they must not go UP. var styleRatchetBaselines = map[string]styleRatchetCounts{ "operator static/index.html": { - inlineStyles: 1425, + inlineStyles: 1415, rawColors: 135, - rawFontSizes: 601, + rawFontSizes: 591, rawPadding: 204, rawBorderRadii: 174}, "contributor landing": { diff --git a/src/pkg/forgequeue/observation.go b/src/pkg/forgequeue/observation.go deleted file mode 100644 index f2b2da8429..0000000000 --- a/src/pkg/forgequeue/observation.go +++ /dev/null @@ -1,66 +0,0 @@ -// Package forgequeue describes observed forge-owned integration queues. -// Observations confer no admission or merge authority. -package forgequeue - -import "time" - -type Entry struct { - ID string `json:"id"` - PR int `json:"pr"` - Head string `json:"head"` - Position int `json:"position"` - State string `json:"state"` - EnqueuedAt *time.Time `json:"enqueued_at,omitempty"` -} - -type Member struct { - PR int `json:"pr"` - Head string `json:"head"` -} - -type Check struct { - Name string `json:"name"` - Status string `json:"status"` - Conclusion string `json:"conclusion,omitempty"` - URL string `json:"url,omitempty"` - AppID int64 `json:"app_id,omitempty"` -} - -type Candidate struct { - Ref string `json:"ref"` - SHA string `json:"sha"` - BaseSHA string `json:"base_sha,omitempty"` - Tree string `json:"tree,omitempty"` - Membership string `json:"membership"` - Members []Member `json:"members"` - CI string `json:"ci"` - Checks []Check `json:"checks"` - ChecksKnown bool `json:"checks_known"` - Reason string `json:"reason,omitempty"` -} - -type Outcome struct { - Kind string `json:"kind"` - PR int `json:"pr,omitempty"` - Head string `json:"head,omitempty"` - CandidateSHA string `json:"candidate_sha,omitempty"` - MergeSHA string `json:"merge_sha,omitempty"` - ObservedAt time.Time `json:"observed_at"` - Source string `json:"source"` -} - -type Observation struct { - Provider string `json:"provider"` - Repo string `json:"repo"` - Base string `json:"base"` - State string `json:"state"` - Complete bool `json:"complete"` - EntriesComplete bool `json:"entries_complete"` - ObservedAt time.Time `json:"observed_at"` - Stale bool `json:"stale"` - FreshForS int64 `json:"fresh_for_s"` - Reason string `json:"reason,omitempty"` - Entries []Entry `json:"entries"` - Candidates []Candidate `json:"candidates"` - Outcomes []Outcome `json:"outcomes"` -} diff --git a/src/pkg/forgestate/queue_observation.go b/src/pkg/forgestate/queue_observation.go new file mode 100644 index 0000000000..76fbfc6c77 --- /dev/null +++ b/src/pkg/forgestate/queue_observation.go @@ -0,0 +1,70 @@ +package forgestate + +import "time" + +// QueueObservation and its value types describe forge-owned queues without +// granting admission or merge authority. +type QueueEntry struct { + ID string `json:"id"` + PR int `json:"pr"` + Head string `json:"head"` + Position int `json:"position"` + State string `json:"state"` + EnqueuedAt *time.Time `json:"enqueued_at,omitempty"` +} + +type QueueCheck struct { + Name string `json:"name"` + Status string `json:"status"` + Conclusion string `json:"conclusion,omitempty"` + URL string `json:"url,omitempty"` + AppID int64 `json:"app_id,omitempty"` +} + +type QueueMember struct { + PR int `json:"pr"` + Head string `json:"head"` + Entry string `json:"entry,omitempty"` + Position int `json:"position,omitempty"` + BaseCommit string `json:"base_commit,omitempty"` + HeadCommit string `json:"head_commit,omitempty"` +} + +type QueueCandidate struct { + Ref string `json:"ref"` + SHA string `json:"sha"` + BaseSHA string `json:"base_sha,omitempty"` + Tree string `json:"tree,omitempty"` + Membership string `json:"membership"` + Members []QueueMember `json:"members"` + CI string `json:"ci"` + Checks []QueueCheck `json:"checks"` + ChecksKnown bool `json:"checks_known"` + Reason string `json:"reason,omitempty"` +} + +type QueueOutcome struct { + Kind string `json:"kind"` + PR int `json:"pr,omitempty"` + Head string `json:"head,omitempty"` + CandidateSHA string `json:"candidate_sha,omitempty"` + MergeSHA string `json:"merge_sha,omitempty"` + ObservedAt time.Time `json:"observed_at"` + Source string `json:"source"` +} + +type QueueObservation struct { + Provider string `json:"provider"` + Repo string `json:"repo"` + Base string `json:"base"` + State string `json:"state"` + Complete bool `json:"complete"` + EntriesComplete bool `json:"entries_complete"` + ObservedAt time.Time `json:"observed_at"` + Stale bool `json:"stale"` + FreshForS int64 `json:"fresh_for_s"` + Reason string `json:"reason,omitempty"` + Entries []QueueEntry `json:"entries"` + Candidates []QueueCandidate `json:"candidates"` + Outcomes []QueueOutcome `json:"outcomes"` +} diff --git a/src/pkg/github/native_queue_observation.go b/src/pkg/github/native_queue_observation.go index 9e0c3efdc3..de41305529 100644 --- a/src/pkg/github/native_queue_observation.go +++ b/src/pkg/github/native_queue_observation.go @@ -9,7 +9,7 @@ import ( "time" gh "github.com/google/go-github/v72/github" - "github.com/hivecommons/hive/pkg/forgequeue" + forgequeue "github.com/hivecommons/hive/pkg/forgestate" ) const ( @@ -21,10 +21,10 @@ const ( // ReadNativeQueueObservation is bounded, read-only and never grants merge // authority. Only signed merge_group event identities supply a group's base; // workflow runs can discover candidate SHAs but cannot prove membership. -func (c *Client) ReadNativeQueueObservation(ctx context.Context, repo, base string, hints []forgequeue.Candidate) (forgequeue.Observation, error) { - out := forgequeue.Observation{Provider: "github-native", Repo: repo, Base: base, - State: "unavailable", ObservedAt: time.Now(), Entries: []forgequeue.Entry{}, - Candidates: []forgequeue.Candidate{}, Outcomes: []forgequeue.Outcome{}} +func (c *Client) ReadNativeQueueObservation(ctx context.Context, repo, base string, hints []forgequeue.QueueCandidate) (forgequeue.QueueObservation, error) { + out := forgequeue.QueueObservation{Provider: "github-native", Repo: repo, Base: base, + State: "unavailable", ObservedAt: time.Now(), Entries: []forgequeue.QueueEntry{}, + Candidates: []forgequeue.QueueCandidate{}, Outcomes: []forgequeue.QueueOutcome{}} parts := strings.Split(repo, "/") if len(parts) != 2 || base == "" { return out, fmt.Errorf("native queue scope unavailable") @@ -79,7 +79,7 @@ func (c *Client) ReadNativeQueueObservation(ctx context.Context, repo, base stri continue } seenIDs[entry.ID], seenPRs[entry.PullRequest.Number] = true, true - e := forgequeue.Entry{ID: entry.ID, Position: entry.Position, PR: entry.PullRequest.Number, + e := forgequeue.QueueEntry{ID: entry.ID, Position: entry.Position, PR: entry.PullRequest.Number, Head: entry.PullRequest.HeadRefOID, State: entry.State} if !entry.EnqueuedAt.IsZero() { at := entry.EnqueuedAt @@ -97,9 +97,9 @@ func (c *Client) ReadNativeQueueObservation(ctx context.Context, repo, base stri } // Candidate identity comes from actual merge_group runs/events, never FIFO // seats or the PR number encoded in a synthetic ref. - candidates := make(map[string]forgequeue.Candidate) + candidates := make(map[string]forgequeue.QueueCandidate) order := []string{} - hintBySHA := make(map[string]forgequeue.Candidate) + hintBySHA := make(map[string]forgequeue.QueueCandidate) for _, hint := range hints { if integrationOID(hint.SHA) && strings.HasPrefix(hint.Ref, "refs/heads/gh-readonly-queue/"+base+"/") { hintBySHA[hint.SHA] = hint @@ -129,7 +129,7 @@ func (c *Client) ReadNativeQueueObservation(ctx context.Context, repo, base stri out.Reason = "Candidate cohort exceeds the bounded observation budget." break } - candidates[run.GetHeadSHA()] = forgequeue.Candidate{SHA: run.GetHeadSHA(), Ref: "refs/heads/" + run.GetHeadBranch()} + candidates[run.GetHeadSHA()] = forgequeue.QueueCandidate{SHA: run.GetHeadSHA(), Ref: "refs/heads/" + run.GetHeadBranch()} if hint, exists := hintBySHA[run.GetHeadSHA()]; exists { candidates[run.GetHeadSHA()] = hint } @@ -154,8 +154,8 @@ func (c *Client) ReadNativeQueueObservation(ctx context.Context, repo, base stri required, requiredKnown := c.nativeObservationRequired(ctx, parts[0], parts[1], base) for _, key := range order { candidate := candidates[key] - candidate.Membership, candidate.Members = "unknown", []forgequeue.Member{} - candidate.CI, candidate.Checks = "unknown", []forgequeue.Check{} + candidate.Membership, candidate.Members = "unknown", []forgequeue.QueueMember{} + candidate.CI, candidate.Checks = "unknown", []forgequeue.QueueCheck{} // Expired refs are not proof of failure, rebuild or merge. ref, _, refErr := c.client.Git.GetRef(ctx, parts[0], parts[1], strings.TrimPrefix(candidate.Ref, "refs/")) if refErr != nil || ref.GetObject().GetSHA() != candidate.SHA { @@ -188,7 +188,7 @@ func (c *Client) ReadNativeQueueObservation(ctx context.Context, repo, base stri if proven { candidate.Membership, candidate.Tree = "proven", group.Tree for _, member := range group.Members { - candidate.Members = append(candidate.Members, forgequeue.Member{PR: member.PR, Head: member.Head}) + candidate.Members = append(candidate.Members, forgequeue.QueueMember{PR: member.PR, Head: member.Head, Entry: member.Entry, Position: member.Position, BaseCommit: member.BaseCommit, HeadCommit: member.HeadCommit}) } } } @@ -255,8 +255,8 @@ func (c *Client) nativeObservationRequired(ctx context.Context, owner, repo, bas return required, known } -func (c *Client) nativeObservationChecks(ctx context.Context, owner, repo, sha string, required map[string]int64, known bool) ([]forgequeue.Check, string, bool) { - checks := []forgequeue.Check{} +func (c *Client) nativeObservationChecks(ctx context.Context, owner, repo, sha string, required map[string]int64, known bool) ([]forgequeue.QueueCheck, string, bool) { + checks := []forgequeue.QueueCheck{} if len(required) == 0 { return checks, "unknown", known } @@ -287,7 +287,7 @@ func (c *Client) nativeObservationChecks(ctx context.Context, owner, repo, sha s state = "unknown" } for _, name := range names { - check := forgequeue.Check{Name: name, Status: "missing"} + check := forgequeue.QueueCheck{Name: name, Status: "missing"} var latest *gh.CheckRun for _, run := range runs.CheckRuns { if run.GetName() == name && run.GetHeadSHA() == sha && (required[name] == 0 || run.GetApp().GetID() == required[name]) && diff --git a/src/pkg/github/native_queue_observation_test.go b/src/pkg/github/native_queue_observation_test.go index 236ce570f8..b9ecc5703c 100644 --- a/src/pkg/github/native_queue_observation_test.go +++ b/src/pkg/github/native_queue_observation_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - "github.com/hivecommons/hive/pkg/forgequeue" + forgequeue "github.com/hivecommons/hive/pkg/forgestate" ) func TestNativeQueueObservationExactCandidateEvidence(t *testing.T) { @@ -97,7 +97,7 @@ func TestNativeQueueObservationExactCandidateEvidence(t *testing.T) { })) defer api.Close() client := NewClient("token", "o", []string{"r"}, nil, api.URL) - hints := []forgequeue.Candidate{{SHA: candidate, Ref: "refs/heads/gh-readonly-queue/v5/pr-7", BaseSHA: base}} + hints := []forgequeue.QueueCandidate{{SHA: candidate, Ref: "refs/heads/gh-readonly-queue/v5/pr-7", BaseSHA: base}} if mode == "no-event" { hints = nil }