Shadow mode: anvil decides every pull request head and compares with its native suite runs (MQ-12 step 3a) #54

Merged
merge-queue merged 2 commits from mq-12-shadow into main 2026-12-01 03:42:14 -08:00
Owner

Step 3a ("shadow") of stage 3 of anvil: https://openproject.home.romaine.life/wp/MQ-12

anvil now runs pipeline-templates' decide.mjs for every pull request head, from the suites package pinned in the image, and sets each decision beside the check jobs the head's native suite runs actually ran. It starts no run and writes no status: nothing the queue or CI does changes.

Removed: nothing.

Added

  • decide.go: on a pull request opened, synchronized or reopened event in any repository kept, once the head and base are in the clone, the repository's own detached worktree of its clone (under DATA_DIR/decide/work) is checked out at the head with --force and cleaned, and node suites/decide.mjs --dir --base <event's base sha> --head --repo --topics <repository's topics> --pr --tags <the clone's tags> runs. One decision per repository at a time, at most two node processes, 2-minute timeout, 768 MiB heap each, TMPDIR/HOME on the volume, no network or token for node (GIT_NO_LAZY_FETCH). The same head, base, topics and suites commit aren't decided twice.
  • store.go: SQLite at DATA_DIR/anvil.db (modernc.org/sqlite, CGO off), versioned migrations in code (PRAGMA user_version): decisions (repo, pr, head, base, suites_sha, topics, result, error, decided_at) and shadow (repo, head, suite, pr, run, its raw job events, decided jobs, native outcome per check, mismatch, detail). Rows older than 30 days go at startup.
  • shadow.go: job and run events of a suite's native pull_request run (<suite>/ci.yml, no plan in its event) are kept per head and suite, newest run only, by job ID and attempt. Once the run ends (not cancelled), each check-* job decide planned is compared with whether it ran; a matrix job counts for its check; a check its scope posted skipped "Identical inputs; passed on ..." counts as run (reused), since decide has no --passes yet. A mismatch is kept, counted (merge_queue_shadow_mismatch_total{suite}) and logged as a warn with both job sets. A run that ends before its decision is compared once it is decided.
  • GET /shadow (in-cluster; the route still carries only /health and /goproxy): counts of decisions, failed decisions, comparisons and mismatches, and the newest mismatches.
  • Metrics merge_queue_decisions_total{result} (ok, error, timeout) and the histogram merge_queue_decide_seconds.
  • Dockerfile: a node stage fetching @romaine-life/ci-suites 0.1.6 (latest published; gitHead 3adae99, the v0.1.6 tag) by npm pack with the CI job's packages sign-in as a build secret, checked against the pinned sha512 integrity, npm ci --omit=dev in its suites/; node and the package copied into the runtime stage with libstdc++, CI_SUITES=/opt/ci-suites.
  • .npmrc (root): the registry sign-in line, which is what makes the suites give the image build FORGEJO_PACKAGES_TOKEN (packages.mjs usesPackages). No package.json.
  • Self-test: node loads the package's decide.mjs and everything it imports.
  • Tests: decide through the real package on a fixture repository (runs with node and CI_SUITES set, skipped otherwise, so CI skips it), per-repository serialization, a timeout, which pull request events ask for a decision, store round trip and retention, mismatch detection from job events (disagreement, reuse, a run ending before its decision, cancelled runs, started runs, other runs, reruns, matrix jobs).

Changed

  • webhook.go: reads the pull request's base sha and the run's id, status, workflow, event, link and event payload, and the job; hands pull request events to the decider and run events to the shadow comparison before the queue's own handling, which is unchanged.
  • main.go: starts shadow mode after the landings (stops at start if CI_SUITES names no valid package or node is missing; off when unset).
  • k8s/deployment.yaml: memory limit 1Gi to 2Gi.
  • README: Shadow mode section, configuration, observability, testing and shipping.

Left alone: the queue, lines, groups, landings and module proxy; CI and pipeline-templates; no run is started and no status written. prepare.go, landing.go and groups.go (stage 6b's work) are untouched.

🤖 Generated with Claude Code

Step 3a ("shadow") of stage 3 of anvil: https://openproject.home.romaine.life/wp/MQ-12 anvil now runs pipeline-templates' `decide.mjs` for every pull request head, from the suites package pinned in the image, and sets each decision beside the check jobs the head's native suite runs actually ran. It starts no run and writes no status: nothing the queue or CI does changes. **Removed:** nothing. **Added** - `decide.go`: on a pull request `opened`, `synchronized` or `reopened` event in any repository kept, once the head and base are in the clone, the repository's own detached worktree of its clone (under `DATA_DIR/decide/work`) is checked out at the head with `--force` and cleaned, and `node suites/decide.mjs --dir --base <event's base sha> --head --repo --topics <repository's topics> --pr --tags <the clone's tags>` runs. One decision per repository at a time, at most two node processes, 2-minute timeout, 768 MiB heap each, TMPDIR/HOME on the volume, no network or token for node (`GIT_NO_LAZY_FETCH`). The same head, base, topics and suites commit aren't decided twice. - `store.go`: SQLite at `DATA_DIR/anvil.db` (modernc.org/sqlite, CGO off), versioned migrations in code (`PRAGMA user_version`): `decisions` (repo, pr, head, base, suites_sha, topics, result, error, decided_at) and `shadow` (repo, head, suite, pr, run, its raw job events, decided jobs, native outcome per check, mismatch, detail). Rows older than 30 days go at startup. - `shadow.go`: job and run events of a suite's native `pull_request` run (`<suite>/ci.yml`, no plan in its event) are kept per head and suite, newest run only, by job ID and attempt. Once the run ends (not cancelled), each `check-*` job decide planned is compared with whether it ran; a matrix job counts for its check; a check its scope posted `skipped` "Identical inputs; passed on ..." counts as run (`reused`), since decide has no `--passes` yet. A mismatch is kept, counted (`merge_queue_shadow_mismatch_total{suite}`) and logged as a `warn` with both job sets. A run that ends before its decision is compared once it is decided. - `GET /shadow` (in-cluster; the route still carries only `/health` and `/goproxy`): counts of decisions, failed decisions, comparisons and mismatches, and the newest mismatches. - Metrics `merge_queue_decisions_total{result}` (ok, error, timeout) and the histogram `merge_queue_decide_seconds`. - Dockerfile: a node stage fetching `@romaine-life/ci-suites` 0.1.6 (latest published; gitHead 3adae99, the v0.1.6 tag) by `npm pack` with the CI job's packages sign-in as a build secret, checked against the pinned sha512 integrity, `npm ci --omit=dev` in its `suites/`; node and the package copied into the runtime stage with `libstdc++`, `CI_SUITES=/opt/ci-suites`. - `.npmrc` (root): the registry sign-in line, which is what makes the suites give the image build `FORGEJO_PACKAGES_TOKEN` (packages.mjs usesPackages). No package.json. - Self-test: node loads the package's `decide.mjs` and everything it imports. - Tests: decide through the real package on a fixture repository (runs with node and `CI_SUITES` set, skipped otherwise, so CI skips it), per-repository serialization, a timeout, which pull request events ask for a decision, store round trip and retention, mismatch detection from job events (disagreement, reuse, a run ending before its decision, cancelled runs, started runs, other runs, reruns, matrix jobs). **Changed** - `webhook.go`: reads the pull request's base sha and the run's id, status, workflow, event, link and event payload, and the job; hands pull request events to the decider and run events to the shadow comparison before the queue's own handling, which is unchanged. - `main.go`: starts shadow mode after the landings (stops at start if `CI_SUITES` names no valid package or node is missing; off when unset). - `k8s/deployment.yaml`: memory limit 1Gi to 2Gi. - README: Shadow mode section, configuration, observability, testing and shipping. **Left alone:** the queue, lines, groups, landings and module proxy; CI and pipeline-templates; no run is started and no status written. `prepare.go`, `landing.go` and `groups.go` (stage 6b's work) are untouched. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Read a run's event payload whatever form Forgejo sends it in
All checks were successful
Suite go / scope (pull_request) Successful in 4s
Suite cluster-service / scope (pull_request) Successful in 5s
Suite go / check-test-windows (pull_request) Has been skipped
Suite go / check-services (pull_request) Has been skipped
Suite cluster-service / publish (pull_request) Has been skipped
Suite cluster-service / check-smoke (pull_request) Has been skipped
Suite default / check-fetches (pull_request) Successful in 5s
Suite default / check-rules (pull_request) Successful in 6s
Suite default / check-logs (pull_request) Successful in 6s
Suite cluster-service / check-manifests (pull_request) Successful in 6s
Suite go / check-format (pull_request) Successful in 7s
Suite default / reused-checks (pull_request) Successful in 5s
Suite go / reused-checks (pull_request) Successful in 4s
merge-queue landed on main
Suite default / scope (pull_request) Successful in 4s
Suite cluster-service / scope (push) Has been skipped
Suite cluster-service / check-manifests (push) Has been skipped
Suite cluster-service / check-image (push) Has been skipped
Suite cluster-service / check-smoke (push) Has been skipped
Suite cluster-service / publish (push) Has been skipped
Suite cluster-service / check-image (pull_request) Successful in 40s
Suite go / check-test-linux (pull_request) Successful in 1m1s
Suite cluster-service / reused-checks (push) Has been skipped
Suite cluster-service / reused-checks (pull_request) Successful in 4s
b1c8e45194
merge-queue deleted branch mq-12-shadow 2026-12-01 03:42:14 -08:00
Sign in to join this conversation.
No reviewers
No labels
queue
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/merge-queue!54
No description provided.