diff --git a/.github/CONTEXT.md b/.github/CONTEXT.md new file mode 100644 index 0000000000..35df3cfb60 --- /dev/null +++ b/.github/CONTEXT.md @@ -0,0 +1,106 @@ +# CI + +This context covers the checks that verify a change, and the machines that run those checks. +The context covers the GitHub Actions workflows of `cipherstash/stack`. +The context also covers the CI spending of the other repositories that share the CI budget with `cipherstash/stack`. + +## Language + +**CI budget**: +The most money that the repositories sharing the budget may spend on CI in one calendar month. +Vendor invoices are the measure of spending against the budget, including fixed costs such as licences and cloud infrastructure. +When an invoice also covers repositories that do not share the budget, only the part for the repositories that share it counts. +Estimates at list price track the spending between invoices, but do not replace the invoices. +_Avoid_: build minutes, runner minutes + +**PR push**: +A new head commit on the branch of a pull request. +Each PR push starts the push checks again. +_Avoid_: PR run, CI run + +**Push check**: +A check that runs on each PR push, if the change includes a file in the check's trigger paths. +The author of the pull request then learns of a failure while still working on the change. +_Avoid_: fast check, PR check + +**Gate check**: +A check that runs when a pull request is in a merge queue, instead of on every PR push. +A failed gate check blocks the merge. +Architecture decision record (ADR) 0003 plans a merge queue for `main` and one for `next`, but neither exists yet. +Under ADR 0003, an author can ask for a gate check to run earlier, on the pull request. +_Avoid_: heavy check, full CI, merge check + +**Early run**: +A run of the gate checks on a pull request before the pull request joins a merge queue. +An author asks for an early run by adding the `ci:full` label. +Each time someone adds the label, the pull request gets one early run. +No workflow reads the label yet, because work on ADR 0003 is paused. +_Avoid_: full run, ci:full run + +**Queue commit**: +The commit that GitHub builds for a pull request in a merge queue. +A queue commit contains the queue entry ahead of the pull request, plus the pull request. +Checks in the merge queue test the queue commit. +_Avoid_: merge group commit, temporary branch + +**Trigger paths**: +The paths that make a check run when a change includes a file in one of them. +Trigger paths apply on PR pushes and in the merge queue. +Every check has trigger paths, or a written reason for running on every change. +_Avoid_: path filter, relevance filter, affected checks + +**Selector job**: +The first job of a workflow. +The selector job selects the checks that run, by comparing the files in a change with the trigger paths of each check. +When the selector job cannot decide, it fails. +The change then cannot merge until someone runs the selector job again. +_Avoid_: path-filter job, decider, router + +**Summary job**: +The last job of a workflow. +The summary job passes when every check that the selector job selected has passed. +The summary job is the only job in the workflow that branch rules require. +_Avoid_: required job, status job + +**Failsafe**: +The test that fails when the selector job does not decide whether a job runs. +The failsafe passes a job that has a written exemption. +The failsafe reads workflow files, rather than acting while a workflow runs. +_Avoid_: lint, selector guard, path-filter lint + +**Light job**: +A job that runs acceptably on a GitHub-hosted standard runner. +ADR 0002 planned to run light jobs on GitHub-hosted standard runners. +Because ADR 0004 superseded that plan, being light no longer decides where a job runs. +Being light does not decide when a job runs: a light job can be a gate check. +_Avoid_: small job, cheap job + +**Heavy job**: +A job that needs a larger machine than a GitHub-hosted standard runner. +ADR 0002 planned to run heavy jobs on a self-provisioned cloud runner instead. +Because ADR 0004 superseded that plan, being heavy no longer decides where a job runs. +Being heavy does not decide when a job runs: a heavy job can be a push check. +_Avoid_: big job, 16-core job + +**Same-size swap**: +The change that moves each Blacksmith job to a RunsOn machine with the same vCPU count, architecture, and Ubuntu version. +Memory and disk may be smaller than on Blacksmith. +The triggers of each job stay the same. +The swap can add steps, such as a Docker Hub login before an image pull. +_Avoid_: like-for-like replacement, migration + +## Relationships + +- Two separate choices apply to each check. + The trigger paths of a check decide whether the check runs at all. + Being a push check or a gate check decides when the check runs. +- Being a light job or a heavy job is a third, separate property. + Under ADR 0002, that property decided where a check runs. + ADR 0004 superseded the plan in ADR 0002. +- For example, the fuzz regression replay is a light job and a gate check. +- Mutation testing is expensive but important. + So mutation testing only runs after the design and implementation of a change are settled. + Failures in mutation testing must be fixed before the change merges. + Those facts make mutation testing a heavy job and a gate check. +- A same-size swap does not use the distinction between light and heavy jobs. + A Blacksmith job moves to RunsOn even if a GitHub-hosted standard runner could run it. diff --git a/CONTEXT-MAP.md b/CONTEXT-MAP.md index 7c2ee257e5..7fed0c1e4f 100644 --- a/CONTEXT-MAP.md +++ b/CONTEXT-MAP.md @@ -14,6 +14,8 @@ Stack CLI and customer workers. - [Migration Harness](./e2e/migration-harness/CONTEXT.md) — tests the Protect.js upgrade guide by having agents follow it and judging the result. +- [CI](./.github/CONTEXT.md) — runs the checks that verify a change, and pays + for the machines that run them, within a shared monthly budget. ## Relationships diff --git a/docs/adr/0002-light-ci-jobs-on-github-hosted-runners-heavy-jobs-on-runs-on.md b/docs/adr/0002-light-ci-jobs-on-github-hosted-runners-heavy-jobs-on-runs-on.md new file mode 100644 index 0000000000..98ce3abfa2 --- /dev/null +++ b/docs/adr/0002-light-ci-jobs-on-github-hosted-runners-heavy-jobs-on-runs-on.md @@ -0,0 +1,85 @@ +--- +status: superseded by ADR-0004 +--- + +# Move CI from Blacksmith to GitHub-hosted runners and RunsOn + +> This architecture decision record (ADR) is no longer in force. +> [ADR 0004](0004-same-size-swap-from-blacksmith-to-runs-on.md) supersedes it. + +We decided in October 2026 to stop running CI on Blacksmith. +Light jobs run on GitHub-hosted standard runners. +Those runners cost nothing for this public repository. + +Heavy jobs run on RunsOn. +RunsOn starts a machine in our own AWS account for each job. +Heavy jobs use c8a machines with 8 vCPUs. +Mutants, the mutation testing workflow, uses a c8a machine with 16 vCPUs. +The other repositories that share the CI budget move their Blacksmith jobs to RunsOn too. + +Heavy jobs stay on x64 machines. +In the trial, arm64 machines were slower than x64 machines, and not cheaper. +Jobs that must run on arm64, such as native arm64 container image builds, are the exception. +Those jobs run on RunsOn's arm64 machines. + +We made the change because of cost. +CI for this repository cost about $3,865 a month on Blacksmith at October 2026's pace. +That was 20 times September's cost. +The CI budget for this repository and the others that share it is $1,000 a month. + +`.github/CONTEXT.md` defines the terms used here. + +```mermaid +flowchart LR + job[A CI job] --> size{Does a GitHub-hosted standard runner give it enough machine?} + size -- "Yes: light job" --> gh[GitHub-hosted runner. Free for this public repository. At most 60 jobs at a time for the organisation.] + size -- "No: heavy job" --> ro[RunsOn machine in our AWS account. c8a with 8 vCPUs. Mutants uses 16 vCPUs.] +``` + +## Considered options + +We rejected each of these options: + +- **Stay on Blacksmith and run fewer jobs.** + We modelled October's jobs with gate checks in place. + At Blacksmith's prices, this repository alone still came to about $2,000 a month. +- **Run every job on RunsOn.** + Light jobs would then cost money. + GitHub-hosted runners run them for nothing. +- **Run every job on GitHub-hosted runners.** + In the runner trial in pull request #1297, jobs took 2.46 times as long overall. + The integration suites took up to 4.8 times as long. +- **Build arm64 images on x64 machines.** + Cross-compiling Rust for another architecture is slow. +- **Run arm64 jobs on GitHub-hosted arm64 runners.** + Those runners cost money for private repositories. + So the cost applies to the private repositories that share the CI budget. + This public repository already builds `linux-arm64-gnu` on a GitHub-hosted arm64 runner for nothing, in `_build-auth-artifacts.yml`. +- **Pull Docker Hub images through a cache in RunsOn's AWS setup.** + RunsOn documents that cache only for its Terraform or OpenTofu installation. +- **Pull Docker's official images from Amazon Elastic Container Registry (ECR) Public.** + Every image name in every repository would change. + Images that are not official would need another source. + +## Consequences + +- GitHub runs at most 60 jobs at a time for the organisation on the Team plan. + When more than 60 jobs are queued, light jobs wait for a runner. +- We simulated October's light jobs against that limit, with gate checks in place. + One job in a hundred waited between 7 and 11 minutes. +- A RunsOn job starts 40 to 50 seconds later than a Blacksmith job did. +- RunsOn uses discounted spot machines. + When AWS has no spare c8a machines, a job runs at the full price. + The full price is more than twice the spot price. + The `family=c8a+m8a` label lets RunsOn try a second machine type before the job runs at the full price. +- Every job sets `timeout-minutes`. + In the trial, one job without a limit ran for more than 2 hours. +- We maintain the RunsOn resources in AWS. + Those resources cost $40 to $60 a month. +- Each RunsOn machine has its own public address. + Docker Hub limits anonymous pulls per address. + In October 2026, Docker Hub still refused anonymous pulls from RunsOn machines. + So a job logs in to Docker Hub before it pulls an image. + Runs for pull requests from forks get no secrets, so they still pull without a login. +- A pull request from a fork would run its code on a machine in our AWS account. + So this repository requires approval before any outside contributor's workflows run, not only a first-time contributor's. diff --git a/docs/adr/0003-expensive-ci-checks-run-in-merge-queues-on-main-and-next.md b/docs/adr/0003-expensive-ci-checks-run-in-merge-queues-on-main-and-next.md new file mode 100644 index 0000000000..5275e02790 --- /dev/null +++ b/docs/adr/0003-expensive-ci-checks-run-in-merge-queues-on-main-and-next.md @@ -0,0 +1,203 @@ +--- +status: accepted +--- + +# Merge queues on `main` and `next` run expensive CI checks + +> We paused work on this decision in November 2026, until the same-size swap in architecture decision record (ADR) 0004 is in place. +> That swap moves every Blacksmith job in this repository to a RunsOn machine of the same size. +> None of this decision has been built yet. + +In October 2026, we decided to split this repository's CI checks into push checks and gate checks. +Push checks run on every push to a pull request. +Gate checks run once, when the pull request is in a merge queue. +The `main` and `next` branches each get a merge queue. + +We made the change because of cost. +From 1 to 20 October 2026, 89% of this repository's CI spending came from runs for pull requests. +Each push to a pull request ran the expensive checks again. +ADR 0002 moves jobs to cheaper machines. +This decision runs the expensive checks less often. + +The glossary in `.github/CONTEXT.md` defines the terms used here. +The diagram shows each step for one pull request, from a push to the merge. + +```mermaid +flowchart TD + push["An author pushes to a pull request"] --> sel1{"Selector job: does the pull request have the ci:full label?"} + sel1 -- "No" --> pc["The push checks whose trigger paths changed run"] + sel1 -- "Yes" --> early["Push checks and gate checks run once. A job removes the label."] + pc --> ready["The pull request is approved. Its summary jobs pass."] + early --> ready + ready --> queue["The pull request joins the merge queue of main or next"] + queue --> sel2["Selector job compares the queue commit with the entry ahead of it"] + sel2 --> all["Push checks and gate checks run. Mutants starts at once."] + all --> sum{"Does every summary job pass?"} + sum -- "Yes" --> merge["GitHub merges the tested commit"] + sum -- "No" --> out["The pull request leaves the queue"] +``` + +## Gate checks and push checks + +The following checks are gate checks: + +- the Test EQL (Encrypt Query Language) suites that need a database: the PostgreSQL shards, the e2e property suite, and the test archive build +- Mutants, the mutation testing job +- CRAP (Change Risk Anti-Patterns) +- the fuzz regression replay +- Go on Windows and macOS, and the Go live tests +- the Drizzle, prisma-next, Supabase, and protect-ffi integration suites +- the two Prisma end-to-end (E2E) suites +- udeps and Miri + +Every other check is a push check. + +## How the merge queues work + +In a merge queue, each pull request is an entry. +For each entry, GitHub builds a queue commit. +The queue commit of an entry contains the entry ahead, plus that entry's pull request. + +- The merge queue runs the push checks and the gate checks against the queue commit. + A failure removes the pull request from the queue. +- Pushes to `main` no longer run the tests. + The queue has already tested the commit that GitHub merges. +- The `next` branch gets the same branch rules as `main`, including the merge queue. + When we made this decision, `next` had no protection. + Pushes to `next` ran no workflows. +- Each queue builds at most 3 entries at once. + The weekly cost report will show whether to change that limit. +- The queues merge with merge commits, as `main` did when we made this decision. + The selector job compares each queue commit with the entry ahead. + The comparison needs merge commits or squash merges. + +## How a workflow decides what runs + +- Every workflow starts with a selector job. + The selector job runs on a GitHub-hosted runner. + The selector job selects a check when the change touches one of the check's trigger paths. + A check's trigger paths are the paths that make the check run when they change. +- In a merge queue, the selector job compares the queue commit with its parent. + The parent is the entry ahead, so the difference is this pull request alone. + The entries ahead run their own checks. + If one of them fails, GitHub rebuilds the entries behind it. +- When the selector job cannot decide, it fails. + The change then cannot merge until someone runs the selector job again. + So people notice a fault in the selector job at once. +- Every workflow ends with a summary job. + The summary job is the only job of the workflow that branch rules require. +- The failsafe is a test in `scripts/__tests__/`. + The command `pnpm run test:scripts` runs it. + The failsafe fails when the selector job does not decide whether a job runs. + A job is exempt only with a written reason. + The failsafe also fails on an exemption that matches no job. + +## Early runs + +An author can ask for an early run by adding the `ci:full` label to the pull request. +An early run runs the gate checks on the pull request, before it joins the merge queue. +A job removes the label when the early run starts. +So each early run is a deliberate request. +The merge queue still runs the gate checks again. + +GitHub cannot start a workflow only when one particular label is added. +So every workflow starts when any label is added. +A run that starts this way is a label run. +On every label run, the selector job selects the push checks again. +For the `ci:full` label, the selector job selects the gate checks too. + +For each check name, GitHub counts the newest result. +So a label run gives new results for the push checks. +A label run cannot hide an earlier push check failure. + +A later push or label run without `ci:full` skips the gate checks. +If the summary job of that later run passes, its result replaces the failed result of an early run. + +## How Mutants runs + +- Mutants is a required gate check. + Mutants only tests the lines that the pull request changes. + In a merge queue, Mutants finds those lines the same way as the selector job. +- Mutants runs in every queue entry except the merge of `next` into `main`. + Each change on `next` has already passed Mutants in the `next` queue. +- Mutants runs as 4 parallel shards on c8a machines with 16 vCPUs. +- In the queue and on early runs, Mutants starts at the same time as the push checks. + A watcher job cancels Mutants when a push check fails. +- On an early run, a cancelled Mutants run counts as a failure. + The pull request cannot join the queue until Mutants runs again, or until a later push or label run replaces the result. +- The other heavy gate checks also start at once, as Mutants does. + +## Considered options + +We rejected each of these options: + +- **Run gate checks when a draft pull request becomes ready for review.** + Agents push to pull requests that are already ready for review. + So most pushes would still run every check. +- **Run gate checks when a pull request is approved.** + On `main`, an approval stays valid after later pushes. + So code pushed after an approval would merge without gate checks. +- **Run gate checks only when an author adds a label, with no merge queue.** + The gate checks would then depend on people remembering to add the label. +- **Filter workflows by path in `on:`, not in a selector job.** + GitHub cannot filter `merge_group` events by path. + If a path filter skips a workflow, the workflow's required checks stay pending. + GitHub's documentation on required status checks says that a pending required check blocks the merge. +- **Compare each queue commit with the base branch.** + With 3 entries building, the difference for the third entry would include the two entries ahead of it. + Mutants would then test the lines of those two entries again. + A failure could point to another author's lines. +- **Run every check when the selector job cannot decide.** + No needed check would be skipped. + But nobody would notice a fault in the selector job. + Each fault would also cost a full run. +- **Run Mutants on the merge of `next` into `main` as well.** + Such a run tests every line that `next` added, for a second time. + In October 2026, such a run reached its 120-minute timeout at least twice on pull request #1229. +- **Run Mutants only in the `main` queue.** + Mutants would test all of `next` together, when `next` merges into `main`. + A failure would then point to anyone who changed `next`. +- **Start Mutants after every push check passes.** + Waiting would spend nothing on failing commits. + But waiting would add up to 14 minutes to each queue entry and early run. + In the queue, push checks rarely fail. + A pull request joins the queue only after its required checks pass. +- **Keep the `ci:full` label until the author removes it.** + If an author forgot to remove the label, every later push would run every gate check. +- **Select nothing on a label other than `ci:full`.** + Every job would be skipped. + GitHub counts a skipped job as a pass. + A test on 28 October 2026 showed that the result of such a run then replaces an earlier failure. +- **Give the summary job a different name on label runs, or run early runs in separate workflows.** + With either option, a failed early run would no longer stop a pull request from joining the queue. + +## Consequences + +- If authors do not ask for an early run, they learn of a gate check failure in the queue. +- A merge waits for the slowest gate check. + Each queue's status check timeout must be longer than the slowest gate check takes. +- Every workflow with a required summary job must also run on `merge_group`. + GitHub's merge queue documentation says the queue only starts workflows that run on `merge_group`. + Without that trigger, the queue would wait for a check that never reports. +- The queue setting "Only merge non-failing pull requests" stays on. + Without that setting, a pull request that failed could merge with the one behind it. +- The smallest group the queue merges is 1 pull request. + So a pull request on its own never waits for others. +- Adding any label to a pull request runs its push checks again. + In October 2026, 74 labels were added to 53 pull requests. + Dependabot added most of them as it opened each pull request. + So those labels cost almost nothing extra. +- A test of a merge queue on 28 October 2026 confirmed three behaviours: + - Commits made by the merge queue pass the rule that requires signed commits. + - The parent of a queue commit is the entry ahead of it. + The value of `merge_group.base_sha` is that parent. + - GitHub does not cancel a running workflow when its entry leaves the queue. + The run continues to the end. +- A failed entry stays in the queue until the entry ahead of it finishes. + Meanwhile, GitHub builds the entry behind it. + The queue commit of that entry contains the failed entry. +- After a flaky push check on an early run, the author must re-run Mutants as well. +- The watcher job waits for up to about 14 minutes. + While it waits, it uses one of the organisation's 60 GitHub-hosted job slots. +- This decision only covers this repository. + The `proxy` repository may make the same change later. diff --git a/docs/adr/0004-same-size-swap-from-blacksmith-to-runs-on.md b/docs/adr/0004-same-size-swap-from-blacksmith-to-runs-on.md new file mode 100644 index 0000000000..53613e36fe --- /dev/null +++ b/docs/adr/0004-same-size-swap-from-blacksmith-to-runs-on.md @@ -0,0 +1,155 @@ +--- +status: accepted +supersedes: ADR-0002 +--- + +# Swap Blacksmith for RunsOn machines of the same size + +In November 2026, we decided to move every Blacksmith job in this repository to RunsOn. +RunsOn runs each job on a machine in our AWS account. +Each job gets the same vCPU count, architecture, and Ubuntu version as on Blacksmith. +`.github/CONTEXT.md` calls this a same-size swap. +The jobs' triggers and trigger paths stay as they are. + +We made the change to cut cost at once. +At November 2026's pace, CI for this repository costs about $3,470 a month on Blacksmith. +On RunsOn machines of the same size, we estimate $1,140 to $1,350 a month for the machines. +RunsOn's own AWS resources add $40 to $60 a month. +The estimate applies the cost ratios from the runner trial in pull request #1297 to Blacksmith's November bill. + +This architecture decision record (ADR) supersedes [ADR 0002](0002-light-ci-jobs-on-github-hosted-runners-heavy-jobs-on-runs-on.md). +The $1,000 monthly budget in the CI budget entry of `.github/CONTEXT.md` is not this decision's measure of success. +Work on ADR 0003 is paused until the swap is in place. + +## What changes + +Each Blacksmith label becomes a RunsOn label with the same vCPU count and Ubuntu version: + +| Blacksmith label | RunsOn label | +|---|---| +| `blacksmith-16vcpu-ubuntu-2204` | `runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache` | +| `blacksmith-4vcpu-ubuntu-2404` | `runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache` | + +- **Jobs that move.** + Every job that names a Blacksmith label moves, in every workflow of this repository. + That includes the Linux targets of the foreign function interface (FFI) release matrix. + `scripts/ffi-release-matrix.mjs` assigns their labels. + On 19 November 2026, `main` had 55 such job definitions in 27 workflows. +- **Jobs that stay.** + Jobs on GitHub-hosted runners stay there, such as `ubuntu-latest`, macOS, and Windows jobs. +- **Other repositories.** + `proxy` and the other repositories that use Blacksmith keep it for now. +- **Memory.** + The c8a machines have 2 GB per vCPU. + Blacksmith's x64 machines have 4 GB per vCPU. + A job that fails for lack of memory moves to `family=m8a`. + The m8a machines have 4 GB per vCPU. +- **Disk.** + Every job gets an 80 GB disk. + Blacksmith gives a 4 vCPU machine 80 GB. + Blacksmith gives a 16 vCPU machine 750 GB. +- **Cache.** + `extras=s3-cache` makes `actions/cache` use an Amazon Simple Storage Service (S3) bucket in our AWS account. + The jobs need no extra step for this. + RunsOn job logs from October 2026 show cache restores working with the label alone. +- **Machine family.** + RunsOn uses spot c8a machines first. + Spot machines cost less than on-demand machines. + AWS can interrupt a spot machine. + When AWS has no spare c8a spot machines, the `m8a` family gives RunsOn a second choice. + +Two changes go in with the swap, because RunsOn needs them: + +- **Docker Hub logins.** + A job logs in to Docker Hub before it pulls an image. + The login uses a free Docker Hub account. + The login needs the `DOCKER_HUB_USERNAME` and `DOCKER_HUB_PASSWORD` secrets. + Dependabot runs read Dependabot secrets, so both secrets need a Dependabot copy too. + Runs for pull requests from forks get no secrets, so they pull without a login. +- **Time limits.** + Every job sets `timeout-minutes`. + On RunsOn, a stuck job costs money until its time limit ends it. + In the trial, one job without a limit ran for more than 2 hours. + +## The RunsOn setup + +These settings are in place in the AWS account, or have been requested: + +- We upgraded RunsOn to v3.6.2 on 19 November 2026. + Before v3.6.0, RunsOn failed a job when the on-demand vCPU quota was full. + From v3.6.0, the job waits. +- RunsOn uses spot machines first, and on-demand machines when spot capacity runs out. + RunsOn reruns a job that AWS interrupts. +- RunsOn keeps no warm machines ready. + Warm machines cost money while idle. +- There is one RunsOn installation, in the `us-west-2` region. +- We asked for vCPU quotas of 5,000 for spot and for on-demand standard instances. + AWS had not yet approved the requests on 19 November 2026. + Until AWS approves them, each quota is 512 vCPUs. + Jobs above the quotas wait. + The swap does not wait for the approval. +- When AWS raises the `RunInstances` request rate from 2 to 4 a second, the RunsOn `AppSize` setting moves from `small` to `medium`. + We asked AWS for the higher rate on 19 November 2026. + Both sizes cost the same. + +## How we judge the swap + +We judge the swap on cost alone. +The AWS account contains only RunsOn. +So while only this repository uses RunsOn, the account's bill is the cost of this repository's CI. +We revert the swap only if CI stops working. + +## Considered options + +We rejected each of these options: + +- **Match Blacksmith's memory with m8a machines.** + We estimate that m8a machines cost 10 to 20% more per hour than c8a machines. + In the trial, none of 44 jobs on c8a machines failed for lack of memory. +- **Match Blacksmith's disk sizes.** + A 750 GB disk adds about a fifth to the spot price of a 16 vCPU machine. + In the pull requests open at the time, 16 vCPU jobs ran on 80 GB disks, and every check passed. +- **Keep ADR 0002's plan.** + Light jobs on GitHub-hosted runners and heavy jobs on 8 vCPU machines cost less than the same-size swap. + That plan gives its full saving only after more changes and ADR 0003's merge queues. +- **Switch in stages, starting with Test EQL.** + The Test EQL workflow is 53% of November's spend. + Two stages would need two reviews and two switches. + Most of the risk is in Test EQL anyway. +- **Use on-demand machines only.** + AWS would never interrupt a job. + The cost would be about 2.3 times the spot price. +- **Keep warm machines ready.** + Jobs would start faster. + Warm machines cost money while idle. +- **Pay for a Docker Team or Pro plan.** + Either plan removes the pull limit. + Billed yearly, Team costs $15 a user a month, for at least 2 users. + Pro costs $9 a month. + A Team plan also gives a token that belongs to the organisation, not to one person. + We keep the free account, for two reasons. + The swap is meant to reduce costs. + The swap is also an experiment to prove that RunsOn is viable for this repository. + +## Consequences + +- In the trial, a RunsOn job started 40 to 50 seconds later than a Blacksmith job. +- Blacksmith ran any number of jobs at once. + RunsOn runs as many jobs as the AWS vCPU quotas allow. + In October 2026, the peak need was between 2,700 and 4,700 vCPUs. +- AWS can interrupt a spot machine. + RunsOn then reruns the job, so the job takes longer. +- A 16 vCPU job has 32 GB of memory, not 64 GB. +- Each RunsOn machine has its own public address. + In the October 2026 trial, Docker Hub still refused anonymous pulls. + So jobs log in. +- The free Docker Hub account allows 200 pulls in 6 hours, for all jobs together. + That figure comes from Docker's documentation, at https://docs.docker.com/docker-hub/usage/pulls/. + Docker's pricing page says 100 pulls an hour instead. + In busy hours, jobs can reach the limit, and their pulls fail. +- A pull request from a fork runs its code on a machine in our AWS account. + So this repository requires approval before any outside contributor's workflows run. +- Blacksmith's GitHub App stays installed for the other repositories. + A revert of the swap returns these jobs to Blacksmith. +- Where a job runs no longer depends on the light job and heavy job entries in `.github/CONTEXT.md`. + A Blacksmith job moves to RunsOn even if a GitHub-hosted runner could run it. diff --git a/docs/superpowers/plans/2026-11-19-same-size-swap-blacksmith-to-runs-on.md b/docs/superpowers/plans/2026-11-19-same-size-swap-blacksmith-to-runs-on.md new file mode 100644 index 0000000000..5614b67fea --- /dev/null +++ b/docs/superpowers/plans/2026-11-19-same-size-swap-blacksmith-to-runs-on.md @@ -0,0 +1,694 @@ +# Same-size swap from Blacksmith to RunsOn: implementation plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. +> Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Move every Blacksmith job in `cipherstash/stack` to a RunsOn machine with the same vCPU count, architecture, and Ubuntu version. + +**Status:** Every task is done. +Every step box is ticked. +The line under each task heading says how that task was done. + +**Architecture:** Pull request #1419 already moves some jobs to RunsOn at 8 vCPUs. +Pull request #1419 also adds Docker Hub logins, and a test that requires them. +This plan merges `main` into that branch, gives every job the size it had on Blacksmith, and moves the remaining jobs. +The plan adds a test in `scripts/__tests__/` for each rule. +A later change that breaks a rule then fails that rule's test. + +**Tech Stack:** GitHub Actions YAML, RunsOn v3.6.2 labels, Node.js ESM scripts, Vitest, js-yaml, and actionlint 1.7.7. + +**Spec:** architecture decision record (ADR) 0004, in `docs/adr/0004-same-size-swap-from-blacksmith-to-runs-on.md`. + +## Global Constraints + +- The 16 vCPU label, verbatim: `runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache` +- The 4 vCPU label, verbatim: `runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache` +- `blacksmith-16vcpu-ubuntu-2204` becomes the 16 vCPU label. + `blacksmith-4vcpu-ubuntu-2404` becomes the 4 vCPU label. +- If a job fails for lack of memory, its label changes from `family=c8a+m8a` to `family=m8a`. + Nothing else in the label changes. + No job starts on `m8a`. +- Every job that names a Blacksmith label moves. + On `main` at `0a0fb63ec`, that is 55 job definitions in 27 workflows. + Of these, 31 have 16 vCPUs. + The other 24 have 4 vCPUs. +- The three Linux platforms of the FFI release matrix move too. + `scripts/ffi-release-matrix.mjs` gives them their label, with the run ID passed in. +- Jobs on GitHub-hosted runners stay where they are. +- Job IDs, job names, triggers, trigger paths, and existing steps stay the same. +- The swap adds only three things: Docker Hub logins, a wait for the apt lock, and two secrets for one reusable workflow. +- The login reads `DOCKER_HUB_USERNAME` and `DOCKER_HUB_PASSWORD`. + The login does nothing when either secret is empty. + The secrets are empty on a pull request from a fork. +- Pull request #1427 sets a time limit on every job. + Pull request #1427 merges before #1419. +- Commits are SSH-signed. + Commits contain no `Co-Authored-By` or `Claude-Session` lines. + Pull request text contains no Claude attribution. +- Pull requests stay drafts. + Push only after the user has asked for this plan to be carried out. + Never force-push. +- Text on GitHub contains no Linear issue IDs. + Text on GitHub never names or describes the private repository that the stack-* crates came from. +- Comments, commit messages, and pull request text use short, literal sentences, one idea each. +- Do not change repository settings or secrets. + The user does that. + +## Steps only the user does + +The person or agent who carries out the tasks does not do these steps. +No task waits for them. +Until the secrets exist, the login steps do nothing. +Image pulls stay anonymous until then. + +- Create the free Docker Hub account. + Create a personal access token for the account, with read-only access to public repositories. +- Add `DOCKER_HUB_USERNAME` and `DOCKER_HUB_PASSWORD` to `cipherstash/stack` as Actions secrets. + Add both as Dependabot secrets too, because a run that Dependabot starts reads only Dependabot secrets. +- Merge #1427. + When you choose, mark #1419 ready and merge it. + +## Review Focus + +1. **A reusable workflow whose caller passes no secrets.** In a called workflow, `secrets.*` is empty unless the caller passes it. + The login would then do nothing. + The job would pull images anonymously, with no error. + Task 3 adds a test that every such caller passes both secrets. +2. **A RunsOn runner chosen by a matrix.** The FFI `binaries` job takes its runner from `matrix.cfg.os`. + The login test from #1419 checks only jobs with a literal `runs-on=` label. + So the login test would miss the musl build. + The musl build pulls an Alpine image from Docker Hub. + Task 2 lists each job whose runner comes from a matrix. + Task 3 checks the ones that use RunsOn. +3. **apt on a new machine.** A new RunsOn machine can still be running an apt process that started at boot. + `apt-get` in the job then fails at once, because the lock is already held. + Task 4 adds a test that every apt command in a RunsOn job sets `DPkg::Lock::Timeout`. + `DPkg::Lock::Timeout` does not make `apt-get update` wait. + So #1419 also retries each `apt-get update`, as Task 4 explains. +4. **A label of the wrong size.** Pull request #1419 used `cpu=8`. + A label left at `cpu=8` would give a job the wrong machine. + If a label had no run ID, every run would share it. + Task 2's tests accept only the labels in Global Constraints. + The tests also refuse an FFI label with no run ID. +5. **A 16 vCPU job that needs more than 32 GB.** No test in the repository can show that a job needs this much memory. + The CI run of #1419 is the test. + Task 5 watches that run. + Task 5 then applies the `m8a` rule from Global Constraints to any job killed for lack of memory. + +--- + +## Outside this plan + +- AWS has not yet raised the `RunInstances` request rate. + When Service Quotas shows 4 for `L-A2D70E6C`, a second CloudFormation change set moves `AppSize` to `medium`. +- AWS has not yet approved the vCPU quotas of 5,000. + Until AWS approves them, jobs beyond the first 512 vCPUs wait for a machine. +- The repository already requires approval before a workflow from any outside contributor runs. + The GitHub API showed `all_external_contributors` on 19 November 2026. + +--- + +### Task 1: Bring #1427 up to date with `main` + +This task is done another way. +Pull request #1427 was rebased onto `main`, instead of merging `main` into it. +Pull request #1427 merged into `main` as 11db0ef99 on 20 November 2026. + +Pull request #1427 sets `timeout-minutes` on every job. +The test from #1427 fails when a job has no `timeout-minutes`. +Jobs added to `main` since 28 October may have no limit. + +**Files:** +- Modify: each `.github/workflows/*.yml` file the test lists +- Test: `scripts/__tests__/workflow-job-timeouts.test.mjs`, already on the branch + +**Interfaces:** +- Consumes: nothing +- Produces: branch `ci/job-timeouts`. + The branch merges into `main` with its test passing. + +- [x] **Step 1: Merge `main` into the branch** + +Create a worktree for `ci/job-timeouts` with the superpowers:using-git-worktrees skill. +In the worktree, run: + +```bash +git fetch origin +git merge --no-edit origin/main +pnpm install --frozen-lockfile +``` + +Expected: the merge completes. +If the merge has a conflict, keep `main`'s lines, and add the branch's `timeout-minutes` line to the job. + +- [x] **Step 2: Run the test** + +Run: `pnpm exec vitest run --config scripts/vitest.config.mjs scripts/__tests__/workflow-job-timeouts.test.mjs` + +Expected: PASS, or FAIL with a list of the jobs that have no limit, as `#` references. + +- [x] **Step 3: Give each listed job a limit** + +Use the rule from #1427's commit `ci(timeouts): set timeout-minutes on every job`. +The limit is about twice the job's longest successful run in the last 30 days. +Round the limit up to a multiple of 5 minutes. +The limit is never less than 10 minutes. +Read run times with `gh run list --workflow --status success --limit 50 --json databaseId` and `gh run view --json jobs`. + +- [x] **Step 4: Run the test again** + +Run: the command in Step 2. +Expected: PASS. + +- [x] **Step 5: Commit and push** + +If Step 1 had no conflict and Step 2 passed, push nothing, because the pull request already merges cleanly. +If Step 1 had a conflict and Step 2 passed, run `git push` to publish the merge commit. +Otherwise: + +```bash +git add .github/workflows +git commit -S -m "ci(timeouts): set timeout-minutes on the jobs added since 28 October" +git push +``` + +Then tell the user that #1427 is ready for them to merge. + +### Task 2: Swap every runner label + +This task is done. +The commit `ci(runners): move every Blacksmith job to a RunsOn machine of the same size` in #1419 made these changes. +Pull request #1419 was rebased onto the branch of pull request #1416, instead of merging `main` into it. + +**Files:** +- Create: `scripts/__tests__/lib/runs-on.mjs` +- Create: `scripts/__tests__/workflow-runs-on.test.mjs` +- Modify: `scripts/ffi-release-matrix.mjs`, in `runnerFor`, `releaseMatrix`, and their doc comment +- Modify: `scripts/__tests__/ffi-release-matrix.test.mjs` +- Modify: every `.github/workflows/*.yml` file that names `blacksmith-` or `cpu=8` in a `runs-on:` line +- Modify: `.github/actionlint.yaml` +- Modify: comments at lines 9 and 22 of `.github/workflows/lint-release.yml` + +**Interfaces:** +- Consumes: `imageOf()` in `scripts/__tests__/workflow-mise-cache-image.test.mjs`. + On #1419's branch, `imageOf()` already reads `image=ubuntuNN` from a RunsOn label. +- Produces, in `scripts/__tests__/lib/runs-on.mjs`: + - `runsOnLabel(cpu: 4 | 16, { family = 'c8a+m8a', runId = '${{ github.run_id }}' } = {}): string`. + A `cpu` of 16 gives `image=ubuntu22-full-x64`. + A `cpu` of 4 gives `image=ubuntu24-full-x64`. + Any other `cpu` throws an error. + - `RUNS_ON_LABELS: ReadonlySet`. + The set contains `runsOnLabel(16)` and `runsOnLabel(4)`, plus both with `family: 'm8a'`. + - `MATRIX_RUNNERS: Record`, keyed by `'#'`. + The workflow path is what `workflowFiles()` in `lib/workflows.mjs` returns. + - `isRunsOnJob(job: object, ref?: string): boolean`. + The result is true when `job['runs-on']` is a string that starts with `runs-on=`. + The result is also true when `MATRIX_RUNNERS[ref]?.runsOn` is true. +- Produces, in `scripts/ffi-release-matrix.mjs`: `runnerFor(platform: string, runId = process.env.GITHUB_RUN_ID): string` and `releaseMatrix(triples, runId = process.env.GITHUB_RUN_ID)`. + +- [x] **Step 1: Merge `main` into #1419's branch** + +The branch `ci/heavy-jobs-runs-on` already has a worktree, at `.claude/worktrees/agent-a7c8ac844ed823b0f`. +Check that `git status` is clean there. +Then run: + +```bash +git fetch origin +git merge --no-edit origin/main +pnpm install --frozen-lockfile +pnpm run test:scripts +``` + +Expected: PASS. +Resolve each conflict by keeping `main`'s lines, plus the branch's `runs-on:`, Docker Hub login, and apt lock changes. +A test that fails at this step fails because of the merge. +Fix the failure before you go on. + +- [x] **Step 2: Write `scripts/__tests__/lib/runs-on.mjs`** + +Implement the interface above. +`MATRIX_RUNNERS` contains exactly these entries: + +```js +export const MATRIX_RUNNERS = { + '.github/workflows/_build-ffi-artifacts.yml#binaries': { + runsOn: true, + reason: 'scripts/ffi-release-matrix.mjs gives every Linux platform a RunsOn label.', + }, + '.github/workflows/_build-auth-artifacts.yml#binaries': { + runsOn: false, + reason: 'Its matrix names GitHub-hosted runners only.', + }, + '.github/workflows/tests-golang.yml#go-binding-cross': { + runsOn: false, + reason: 'Its matrix is macos-latest and windows-latest.', + }, +} +``` + +- [x] **Step 3: Write the failing tests in `scripts/__tests__/workflow-runs-on.test.mjs`** + +Read every job with `workflowFiles()` and `readWorkflow()`, as `{ ref: '#', job }`. +Two local helpers return references. +`refsWhere(predicate)` returns the `ref` of each job that matches. +`expressionRunnerRefs()` returns the `ref` of each job whose runner comes from an expression. + +```js +describe('RunsOn runner labels', () => { + it('builds the labels ADR 0004 names', () => { + expect(runsOnLabel(16)).toBe('runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache') + expect(runsOnLabel(4)).toBe('runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache') + expect(runsOnLabel(4, { family: 'm8a' })).toBe('runs-on=${{ github.run_id }}/family=m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache') + expect(() => runsOnLabel(8)).toThrow() + }) + + it('finds the jobs it checks', () => { + expect(jobs.filter(({ job, ref }) => isRunsOnJob(job, ref)).length).toBeGreaterThan(50) + }) + + it('names no Blacksmith label', () => { + // JSON.stringify covers a runs-on that is a list or an object. + expect(refsWhere(({ job }) => /blacksmith-/.test(JSON.stringify(job['runs-on'] ?? '')))).toEqual([]) + }) + + it('uses only the labels ADR 0004 names', () => { + expect(refsWhere(({ job }) => { + const label = job['runs-on'] + return typeof label === 'string' && label.startsWith('runs-on=') && !RUNS_ON_LABELS.has(label) + })).toEqual([]) + }) + + it('lists every job whose runner comes from an expression', () => { + // An expression runner: runs-on is not a string, or contains `${{` and + // does not start with `runs-on=`. Both directions, so a stale entry fails. + expect(expressionRunnerRefs().sort()).toEqual(Object.keys(MATRIX_RUNNERS).sort()) + expect(Object.values(MATRIX_RUNNERS).every(({ reason }) => reason.trim())).toBe(true) + }) +}) +``` + +Each string that contains `${{` needs the `biome-ignore lint/suspicious/noTemplateCurlyInString` comment that `workflow-mise-cache-image.test.mjs` uses. + +- [x] **Step 4: Update `scripts/__tests__/ffi-release-matrix.test.mjs`** + +Import `runsOnLabel` from `./lib/runs-on.mjs`. +Set `const RUN_ID = '1234'`, `const MATRIX = releaseMatrix(TRIPLES, RUN_ID)`, and `const RUNS_ON_4 = runsOnLabel(4, { runId: RUN_ID })`. +Then make these changes: + +- The `linux-x64-gnu`, `linux-arm64-gnu`, and `linux-x64-musl` entries expect `os: RUNS_ON_4`. + The `script` and `log` of those entries stay as they are. +- The fallback test expects `runnerFor('linux-arm64-musl', RUN_ID)` to be `RUNS_ON_4`. + The comment in that test says that a platform the table does not name is built on RunsOn. +- Keep the test that refuses an empty run ID: `expect(() => runnerFor('linux-x64-gnu', '')).toThrow(/GITHUB_RUN_ID/)`. +- Add `expect(runnerFor('darwin-x64', '')).toBe('macos-latest')`, because only a RunsOn label needs the run ID. + +- [x] **Step 5: Run both tests to see them fail** + +Run: `pnpm exec vitest run --config scripts/vitest.config.mjs scripts/__tests__/workflow-runs-on.test.mjs scripts/__tests__/ffi-release-matrix.test.mjs` + +Expected: FAIL. +The test "names no Blacksmith label" lists the jobs still on Blacksmith. +The test "uses only the labels ADR 0004 names" lists the `cpu=8` jobs. +The FFI test shows `cpu=8` labels, and a Blacksmith label for musl. + +- [x] **Step 6: Replace the labels in the workflows** + +```bash +sed -i \ + -e 's|runs-on: blacksmith-16vcpu-ubuntu-2204|runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=16/image=ubuntu22-full-x64/volume=80gb/extras=s3-cache|' \ + -e 's|runs-on: blacksmith-4vcpu-ubuntu-2404|runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache|' \ + -e 's|/cpu=8/image=ubuntu22-full-x64/|/cpu=16/image=ubuntu22-full-x64/|' \ + -e 's|/cpu=8/image=ubuntu24-full-x64/|/cpu=4/image=ubuntu24-full-x64/|' \ + .github/workflows/*.yml +``` + +The last two `-e` expressions undo #1419's sizes. +On `main`, every 16 vCPU label is Ubuntu 22.04. +Every 4 vCPU label on `main` is Ubuntu 24.04. +So the image of a `cpu=8` job shows its Blacksmith size. + +The labels of the publish jobs contain `extras=s3-cache` too. +`extras=s3-cache` has no effect in a job with no cache step. +`scripts/lint-no-workflow-caching.mjs` makes sure the publish jobs have no cache steps. + +- [x] **Step 7: Change `runnerFor` in `scripts/ffi-release-matrix.mjs`** + +For a `win32` platform, `runnerFor` returns `windows-latest`. +For a `darwin` platform, `runnerFor` returns `macos-latest`. +Neither label needs the run ID. +For every other platform, `runnerFor` returns the 4 vCPU label, with the run ID in place of `${{ github.run_id }}`. +If that run ID is empty, `runnerFor` throws an error that names `GITHUB_RUN_ID`. + +Rewrite the doc comment to say three things: + +- Darwin and Windows need GitHub-hosted images for their SDKs. +- Every Linux platform is built on a RunsOn machine with 4 vCPUs, the size it had on Blacksmith. +- A matrix value cannot read `${{ github.run_id }}`, so the run ID is passed in. + +Remove #1419's sentences about build times, and about musl staying on Blacksmith. + +- [x] **Step 8: Empty the self-hosted label list in `.github/actionlint.yaml`** + +Replace the file's content with: + +```yaml +# actionlint checks every `runs-on:` label against the GitHub-hosted labels it +# knows, and against the self-hosted labels listed here. +# +# The list is empty. Every self-hosted job runs on RunsOn, and each RunsOn +# label starts with `runs-on=${{ github.run_id }}`. actionlint does not check +# a label that contains an expression. So a Blacksmith label is now unknown, +# and actionlint reports it. +self-hosted-runner: + labels: [] +``` + +In `.github/workflows/lint-release.yml`, change "for the Blacksmith runner label" at line 9 to "for its self-hosted runner labels". +Change "the config it resolves the Blacksmith label from" at line 22 to "the config it reads runner labels from". + +- [x] **Step 9: Run the tests to see them pass** + +Run: `pnpm run test:scripts` + +Expected: PASS, with one exception. +`workflow-docker-hub-login.test.mjs` now checks every moved job. +The login test lists each moved job that pulls an image with no login. +Task 3 adds those logins. +`workflow-mise-cache-image.test.mjs` passes, because each job keeps its Ubuntu version. + +- [x] **Step 10: Run actionlint on the release workflows** + +Run the `actionlint` command from the "actionlint (release workflows)" step of `lint-release.yml`. +Start the command with `mise x go -- go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.7` in place of `actionlint`. + +Expected: no output, and exit code 0. +The release workflows now contain RunsOn labels. +So this result also shows that actionlint skips a label that contains an expression. + +- [x] **Step 11: Check the counts and what is left** + +```bash +git grep -h 'runs-on: blacksmith-16vcpu-ubuntu-2204' origin/main -- .github/workflows | wc -l +git grep -h 'cpu=16/image=ubuntu22-full-x64' -- .github/workflows | wc -l +git grep -h 'runs-on: blacksmith-4vcpu-ubuntu-2404' origin/main -- .github/workflows | wc -l +git grep -h 'cpu=4/image=ubuntu24-full-x64' -- .github/workflows | wc -l +git grep -n -E 'cpu=8|blacksmith-' -- .github scripts/ffi-release-matrix.mjs +``` + +Expected: + +- The first two numbers are equal. + At `0a0fb63ec`, this pair was 31. +- The next two numbers are equal. + At `0a0fb63ec`, this pair was 24. +- The last command lists only comments. + The comments say why some jobs use GitHub-hosted runners. + One comment names an arm64 label in `_build-auth-artifacts.yml`. + +- [x] **Step 12: Commit** + +```bash +git add .github scripts +git commit -S -m "ci(runners): move every Blacksmith job to a RunsOn machine of the same size" +``` + +### Task 3: Log in to Docker Hub on every RunsOn job that pulls an image + +This task is done. +Two commits in #1419 made these changes: `ci(runners): log in to Docker Hub before every RunsOn job pulls an image` and `ci(runners): log in before the README walkthrough pulls its database`. + +**Files:** +- Modify: `scripts/__tests__/workflow-docker-hub-login.test.mjs` +- Modify: each workflow the test lists +- Modify: `.github/workflows/_build-ffi-artifacts.yml`, `.github/workflows/release.yml`, and `.github/workflows/ffi-preflight.yml` + +**Interfaces:** +- Consumes: `isRunsOnJob(job, ref)` from `scripts/__tests__/lib/runs-on.mjs`, made in Task 2. +- Produces, in `workflow-docker-hub-login.test.mjs`: + - `jobFindings(where: string, job: object, ref?: string): string[]`. + The RunsOn check in `jobFindings` becomes `isRunsOnJob(job, ref)`. + - `callerFinding(job: object): string | null`. + `callerFinding` returns null when `job.secrets` is `'inherit'`. + `callerFinding` also returns null when `job.secrets` maps `DOCKER_HUB_USERNAME` to `${{ secrets.DOCKER_HUB_USERNAME }}` and `DOCKER_HUB_PASSWORD` to `${{ secrets.DOCKER_HUB_PASSWORD }}`. + Otherwise, `callerFinding` returns a message that names each missing secret. + +- [x] **Step 1: Write the failing tests** + +In `workflow-docker-hub-login.test.mjs`: + +- Replace the local `isRunsOn` with `isRunsOnJob`. + `runsOnJobs()` builds `ref` as `${file}#${name}`, and passes `ref` to `jobFindings`. +- Rewrite the last paragraph of the header comment to say the following. + A job counts as RunsOn when its label starts with `runs-on=`. + A job also counts as RunsOn when `MATRIX_RUNNERS` in `lib/runs-on.mjs` says its matrix gives it RunsOn machines. +- Raise the count in the test "finds the jobs it checks" from 20 to 50. +- Add `it('passes the Docker Hub secrets to every called workflow whose RunsOn jobs log in')`. + For each job whose `uses` starts with `./.github/workflows/`, read the workflow that the job calls. + When one of that workflow's RunsOn jobs has a step with `loginFinding(step) === null`, `callerFinding(job)` must be null. + Collect each failure as `#: `, and expect `[]`. +- Add these unit cases: + +```js +expect(callerFinding({ uses: './.github/workflows/x.yml' })).toMatch(/DOCKER_HUB_USERNAME/) +expect(callerFinding({ uses: './.github/workflows/x.yml', secrets: 'inherit' })).toBeNull() +expect(callerFinding({ uses: './.github/workflows/x.yml', secrets: { DOCKER_HUB_USERNAME: USERNAME, DOCKER_HUB_PASSWORD: PASSWORD } })).toBeNull() +expect(callerFinding({ uses: './.github/workflows/x.yml', secrets: { DOCKER_HUB_USERNAME: USERNAME } })).toMatch(/DOCKER_HUB_PASSWORD/) +expect(jobFindings('w j', { 'runs-on': '${{ matrix.cfg.os }}', steps: [up] }, '.github/workflows/_build-ffi-artifacts.yml#binaries')) + .toEqual([expect.stringMatching(/no Docker Hub login comes before it/)]) +``` + +- [x] **Step 2: Run the test to see it fail** + +Run: `pnpm exec vitest run --config scripts/vitest.config.mjs scripts/__tests__/workflow-docker-hub-login.test.mjs` + +Expected: FAIL. +The test "logs in before every pull" lists each job that pulls an image with no login before it. +The list includes `_build-ffi-artifacts.yml binaries`. + +- [x] **Step 3: Add a login before each pull the test lists** + +Copy the "Log in to Docker Hub" step, with its comment, from a `test-eql.yml` job that has one. +Put the copy directly before the step that the finding names. +For a service container or a job container from Docker Hub, use the `credentials:` expression and its comment instead. +Copy both from the `encryption-postgres` service in `test-eql.yml`. + +- [x] **Step 4: Give the musl FFI build its login and its secrets** + +In `.github/workflows/_build-ffi-artifacts.yml`: + +- Under `on.workflow_call`, declare both secrets with `required: false`. +- Add the login step directly before "Build the binding in Alpine (linux-x64-musl)", with `if: ${{ matrix.cfg.platform == 'linux-x64-musl' }}`. + The macOS and Windows legs of the matrix have no Docker. + Without the condition, `docker login` would fail on those legs once the secrets exist. + +In `release.yml`, in the job that calls `_build-ffi-artifacts.yml`, pass both secrets. +Do the same in the `artifacts` job of `ffi-preflight.yml`: + +```yaml + secrets: + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} + DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} +``` + +Pass these two secrets by name, not with `secrets: inherit`. +The called workflow then receives no other secret of the release workflow. + +- [x] **Step 5: Run the tests to see them pass** + +Run: `pnpm run test:scripts`. +Expected: PASS. + +- [x] **Step 6: Run actionlint on the release workflows** + +Run: the command in Task 2, Step 10. +Expected: no output, and exit code 0. +actionlint fails when a caller passes a secret that the called workflow does not declare. + +- [x] **Step 7: Commit** + +```bash +git add .github scripts +git commit -S -m "ci(runners): log in to Docker Hub before every RunsOn job pulls an image" +``` + +### Task 4: Wait for the apt lock on every RunsOn job + +This task is done. +Two commits in #1419 made these changes: `test(ci): require every RunsOn job to wait for the apt lock` and `ci(runners): retry apt-get update until boot-time apt lets go`. + +Pull request #1419 added `-o DPkg::Lock::Timeout=300` to the two `apt-get` steps that run on RunsOn. +Nothing yet stops a new step that leaves the option out. + +`DPkg::Lock::Timeout` makes apt wait only for the dpkg lock. +`apt-get update` takes the package-list lock instead. +`apt-get update` does not wait for the package-list lock, with or without the option. +So `apt-get update` can still fail at once on a new machine. + +The commit `ci(runners): retry apt-get update until boot-time apt lets go` in #1419 handles this case. +Each `apt-get update` runs in a loop of up to 20 tries, 15 seconds apart. +The `apt-get update` line in the loop ends with `&& break`. +`aptFinding` also returns a finding for an `apt-get update` line that has no `&& break`. + +**Files:** +- Modify: `scripts/__tests__/workflow-runs-on.test.mjs` +- Modify: each workflow or local action the test lists. + None is expected. + +**Interfaces:** +- Consumes: `isRunsOnJob(job, ref)`, made in Task 2. +- Produces: `aptFinding(run: string): string | null`, exported from `workflow-runs-on.test.mjs`. + `aptFinding` ignores comment lines. + The function looks for a line that runs `apt` or `apt-get` with `update`, `install`, `upgrade`, `dist-upgrade`, `remove`, `purge`, or `autoremove`. + When such a line has no `DPkg::Lock::Timeout=`, the function returns a message that names the line. + Otherwise, the function returns null. + +- [x] **Step 1: Write the failing tests** + +```js +it('recognises an apt command that does not wait for the lock', () => { + expect(aptFinding('sudo apt-get update')).toMatch(/DPkg::Lock::Timeout/) + expect(aptFinding('sudo apt install -y jq')).toMatch(/DPkg::Lock::Timeout/) + expect(aptFinding('sudo apt-get -o DPkg::Lock::Timeout=300 install -y doxygen')).toBeNull() + expect(aptFinding('# sudo apt-get update')).toBeNull() + expect(aptFinding('apt-cache policy doxygen')).toBeNull() +}) + +it('waits for the apt lock in every RunsOn job', () => { + // Every step of every RunsOn job. A `uses: ./…` step is followed into the + // composite action's runs.steps, as stepPulls does in + // workflow-docker-hub-login.test.mjs. + expect(aptFindingsInRunsOnJobs()).toEqual([]) +}) +``` + +- [x] **Step 2: Run the tests to see them fail** + +Run: `pnpm exec vitest run --config scripts/vitest.config.mjs scripts/__tests__/workflow-runs-on.test.mjs` + +Expected: FAIL with "aptFinding is not defined". + +- [x] **Step 3: Implement `aptFinding` and `aptFindingsInRunsOnJobs`** + +`aptFindingsInRunsOnJobs()` returns one `# step : ` string for each step that `aptFinding` reports. + +- [x] **Step 4: Run the tests to see them pass** + +Run: the command in Step 2. +Expected: PASS. +If the second test lists a step, add `-o DPkg::Lock::Timeout=300` after each `apt-get` in that step. + +- [x] **Step 5: Commit** + +```bash +git add scripts .github +git commit -S -m "test(ci): require every RunsOn job to wait for the apt lock" +``` + +### Task 5: Check the branch, and update #1419 + +This task is done. +The FFI run in Step 5 is GitHub Actions run 45574782571, from 25 November 2026. + +**Files:** no new files. + +- [x] **Step 1: Run the checks that CI runs on these files** + +```bash +pnpm run test:scripts +pnpm run lint:workflow-cache +pnpm run code:check +``` + +Expected: all three pass. +`code:check` fails only on errors. +The check may still print warnings. + +- [x] **Step 2: Check that no job name changed** + +```bash +git diff origin/main...HEAD -U0 -- .github/workflows | grep -E '^[-+][[:space:]]+(- )?name:' +``` + +With three dots, `git diff` compares with the commit where the branch left `main`. +Without them, the diff also shows `main`'s newer changes, as if the branch had made them. + +Expected: only added lines that read `+ - name: Log in to Docker Hub`. +A removed or changed job `name:` means the diff changes more than ADR 0004 allows. + +- [x] **Step 3: Push** + +Run: `git push origin ci/heavy-jobs-runs-on` + +Expected: a normal push. +If git refuses because the remote branch moved, stop and tell the user. + +- [x] **Step 4: Update the title and body of #1419** + +Use the meta-pr-creation skill. +The title is `ci(runners): move every Blacksmith job to a RunsOn machine of the same size`. +The body says what changes, why, and how to check it. +The body points to ADR 0004 for the cost reasons. + +Set the title and body with `gh pr edit 1419 --title --body-file <file>`. +Keep the pull request a draft. + +- [x] **Step 5: Run the FFI build on RunsOn** + +The release workflows do not run on a pull request. +`ffi-preflight.yml` runs the FFI build without publishing anything: + +```bash +gh workflow run ffi-preflight.yml --ref ci/heavy-jobs-runs-on -f ref=ci/heavy-jobs-runs-on +``` + +Expected: the two gnu legs pass. +The musl leg fails as it does on `main`, for the reason in #1380. +The wrapper job is skipped, because it needs the musl leg. + +- [x] **Step 6: Watch the pull request's CI run** + +Run: `gh pr checks 1419 --watch`. +Read each failed job's log with `gh run view <run-id> --log-failed`. + +- **Killed for lack of memory:** the log shows exit code 137, "Killed", or "signal: 9, SIGKILL". + Change that job's `family=c8a+m8a` to `family=m8a`. + Run `pnpm run test:scripts`. + Then commit with the message `ci(runners): give <job name> 4 GB per vCPU on m8a`, and push. +- **`toomanyrequests` from Docker Hub:** report the job to the user. + The secrets may not exist yet. + Or the jobs may have used all 200 pulls that the free account allows in 6 hours. + ADR 0004 names the source of that figure. +- **Any other failure:** compare it with the same job's latest run on `main`. + Report the failure to the user, with an excerpt from each log. + +### Task 6: Record the decision and this plan in #1416 + +This task is done. +The commit `docs(ci): record the same-size swap from Blacksmith to RunsOn` in #1416 made these changes. + +**Files:** +- Modify: `docs/adr/0004-same-size-swap-from-blacksmith-to-runs-on.md`, to `status: accepted` +- Add: `docs/superpowers/plans/2026-11-19-same-size-swap-blacksmith-to-runs-on.md` +- Add: the uncommitted changes to `.github/CONTEXT.md`, ADR 0002, and ADR 0003 + +Work in the worktree of branch `docs/ci-cost-decisions`. +Leave out the CSV and PDF files at the repository root. +Those files are local data, not documentation. + +- [x] **Step 1: Set the ADR's status** + +Change line 2 of ADR 0004 to `status: accepted`. + +- [x] **Step 2: Commit** + +```bash +git add .github/CONTEXT.md docs/adr/0002-light-ci-jobs-on-github-hosted-runners-heavy-jobs-on-runs-on.md docs/adr/0003-expensive-ci-checks-run-in-merge-queues-on-main-and-next.md docs/adr/0004-same-size-swap-from-blacksmith-to-runs-on.md docs/superpowers/plans/2026-11-19-same-size-swap-blacksmith-to-runs-on.md +git commit -S -m "docs(ci): record the same-size swap from Blacksmith to RunsOn" +``` + +- [x] **Step 3: Push and update #1416** + +Run `git push`. +Then add one paragraph to the body of #1416. +The paragraph says that ADR 0004 supersedes ADR 0002, and pauses ADR 0003. +Keep the pull request a draft.