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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .agents/skills/work-issue/references/ci-and-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ Forks use ordinary `pull_request` with a read-only token (`contents: read`,
plus `actions: read` / `checks: read` for bounded proof lookup), no secrets
and nonpersisted checkout credentials; an approval-held run has not passed.
Drafts run cheap gates only, and tests-only changes may intentionally skip
packaging while complete affected tests run. Read actual GitHub checks
packaging while complete affected tests run. One job is the exception: when a
PR adds or modifies a Bun test file, `determinism` repeats those files under
CPU load at every cadence, drafts included, and `draft gates` and `proof`
require it. A failing repetition is fixed in the test, never rerun
([the gate](../../../../docs/process/testing.md#changed-tests-repeat-under-load)). Read actual GitHub checks
and logs for the current head, never an old Depot receipt or latest-main run.
GitHub checks/statuses may include additional gates. No rows,
queued/running checks or cancelled runs are not green.
Expand Down
61 changes: 60 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ concurrency:

# Drafts run cheap gates; synchronize gives fast feedback. Open/ready/reopen
# requests final affected confirmation. The proof gate refuses intermediate feedback.
# One job is selected at every pull-request cadence, drafts included: `determinism`
# repeats the Bun test files a change adds or modifies under CPU load (#4109).
# Independent jobs start together; each PR owns its cancellation group (#1326).
jobs:
changeset:
Expand All @@ -38,6 +40,7 @@ jobs:
unit_shards: ${{ steps.plan.outputs.unit_shards }}
verify: ${{ steps.plan.outputs.verify }}
pack: ${{ steps.plan.outputs.pack }}
determinism: ${{ steps.plan.outputs.determinism }}
run_browser: ${{ steps.reuse.outputs.run_browser }}
run_layout: ${{ steps.reuse.outputs.run_layout }}
reuse: ${{ steps.reuse.outputs.reuse }}
Expand Down Expand Up @@ -651,10 +654,66 @@ jobs:
if-no-files-found: warn
retention-days: 7

determinism:
# A changed test that passes once can still fail on someone else's merge (#4109).
needs: changeset
if: ${{ !cancelled() && (needs.changeset.result == 'success' || github.event_name == 'push') && needs.changeset.outputs.determinism == 'true' }}
runs-on: ubuntu-24.04
# 12 minutes setup + 40 minutes proof + 3 minutes for other steps.
timeout-minutes: 55
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
fetch-depth: 0
- uses: oven-sh/setup-bun@v2
with:
bun-version: "1.4.2"
# Native source freezes require dependency inodes owned by this checkout.
- run: bun install --frozen-lockfile --backend=copyfile
- name: Recompute affected proof on the actual checkout
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BEFORE_SHA: ${{ github.event.before }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
RED_MAIN_OID: ${{ needs.changeset.outputs.red_main_oid }}
run: bun scripts/ci-plan.ts
# The unit job's prerequisites: a changed file may drive real Chrome or the offline namespaces.
- name: Real Chrome and offline Linux namespace prerequisites
id: runtime_setup
timeout-minutes: 12
run: bash scripts/ci-runtime-setup.sh
- name: Repeat changed Bun test files under CPU load
id: runtime_proof
timeout-minutes: 40
run: bun scripts/ci-proof.ts determinism
- name: Environment setup and proof outcomes
if: always()
env:
SETUP_OUTCOME: ${{ steps.runtime_setup.outcome }}
PROOF_OUTCOME: ${{ steps.runtime_proof.outcome }}
run: |
printf 'Environment setup (infrastructure prerequisite, 12-minute limit): %s\nProof (40-minute limit): %s\n' \
"$SETUP_OUTCOME" "$PROOF_OUTCOME" >> "$GITHUB_STEP_SUMMARY"
- name: Proof receipts and failure diagnostics
if: always()
uses: actions/upload-artifact@v7
with:
name: determinism-proof
path: |
tmp/determinism-report.json
tmp/determinism-junit.xml
tmp/proof-checkout.json
tmp/proof-resources.json
tmp/runner-disk.json
include-hidden-files: true
if-no-files-found: warn
retention-days: 7

proof:
name: ${{ github.event_name != 'pull_request' && 'integrated or exhaustive proof' || github.event.pull_request.draft && 'draft gates' || 'proof' }}
# Evaluate even after failures or skips; never interpret missing selected proof as green.
needs: [changeset, verify, pack, unit, runtime, runtime_host, browser, layout, captures, endurance]
needs: [changeset, verify, pack, unit, runtime, runtime_host, browser, layout, captures, endurance, determinism]
if: ${{ always() && !cancelled() }}
runs-on: ubuntu-24.04
timeout-minutes: 3
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/heavy-feedback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
unit_shards: "${{ steps.plan.outputs.unit_shards }}"
verify: "${{ steps.plan.outputs.verify }}"
pack: "${{ steps.plan.outputs.pack }}"
determinism: "${{ steps.plan.outputs.determinism }}"
run_browser: "${{ steps.reuse.outputs.run_browser }}"
run_layout: "${{ steps.reuse.outputs.run_layout }}"
red_main_oid: "${{ steps.plan.outputs.red_main_oid }}"
Expand Down Expand Up @@ -444,6 +445,50 @@ jobs:
include-hidden-files: true
if-no-files-found: warn
retention-days: 7
determinism:
needs: changeset
if: "${{ !cancelled() && (needs.changeset.result == 'success' || github.event_name == 'push') && needs.changeset.outputs.determinism == 'true' }}"
runs-on: ubuntu-24.04
timeout-minutes: 55
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
fetch-depth: 0
ref: "${{ inputs.head_sha }}"
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.4.2
- run: bun install --frozen-lockfile --backend=copyfile
- name: Recompute affected proof on the actual checkout
env:
BASE_SHA: "${{ needs.changeset.outputs.base_sha }}"
HEAD_SHA: "${{ inputs.head_sha }}"
FEEDBACK_PR: "${{ inputs.pr }}"
run: bun scripts/ci-plan.ts
- name: Real Chrome and offline Linux namespace prerequisites
id: runtime_setup
timeout-minutes: 12
run: bash scripts/ci-runtime-setup.sh
- name: Repeat changed Bun test files under CPU load
id: runtime_proof
timeout-minutes: 40
run: bun scripts/ci-proof.ts determinism
- name: Environment setup and proof outcomes
if: always()
env:
SETUP_OUTCOME: "${{ steps.runtime_setup.outcome }}"
PROOF_OUTCOME: "${{ steps.runtime_proof.outcome }}"
run: "printf 'Environment setup (infrastructure prerequisite, 12-minute limit): %s\\nProof (40-minute limit): %s\\n' \\\n \"$SETUP_OUTCOME\" \"$PROOF_OUTCOME\" >> \"$GITHUB_STEP_SUMMARY\"\n"
- name: Proof receipts and failure diagnostics
if: always()
uses: actions/upload-artifact@v7
with:
name: determinism-proof
path: "tmp/determinism-report.json\ntmp/determinism-junit.xml\ntmp/proof-checkout.json\ntmp/proof-resources.json\ntmp/runner-disk.json\n"
include-hidden-files: true
if-no-files-found: warn
retention-days: 7
aggregate:
name: draft heavy feedback
needs:
Expand All @@ -457,6 +502,7 @@ jobs:
- layout
- captures
- endurance
- determinism
if: "${{ always() && !cancelled() && github.event_name == 'workflow_dispatch' }}"
runs-on: ubuntu-24.04
timeout-minutes: 3
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ real Chrome and required namespaces may not silently skip. The final `proof`
check requires every selected category to pass. Scheduled/manual exhaustive
runs supplement affected PR proof; they do not replace it.

Drafts stay on cheap gates. Opening/reopening a ready PR or marking it ready
Drafts stay on cheap gates, plus one job: a PR that adds or modifies a Bun
test file has those files repeated under CPU load
([why](docs/process/testing.md#changed-tests-repeat-under-load)). Opening/reopening a ready PR or marking it ready
requests affected candidate confirmation of the fast categories (types,
packaging, unit/integration); heavy runtime, browser, layout, capture and
endurance proof runs on the squash's own main run
Expand Down
75 changes: 74 additions & 1 deletion docs/decisions/ci-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ stay pre-merge; heavy categories move to the squash's own main run.
`unit` (complete affected unit/integration discovery, unchanged). It no
longer runs `runtime`, `runtime_host`, `browser`, `layout`, `captures` or
`endurance`. The exclusion lives in one place:
`proofSelections` (`scripts/ci-plan.ts:424-433`) applies
`proofSelections` (`scripts/ci-plan.ts:441-453`) applies
`POST_MERGE_CATEGORIES` (`scripts/red-main.ts:20-25`). Candidate admission,
the aggregate and the merge path validate that same selection, so none of
them can require a post-merge category.
Expand Down Expand Up @@ -1907,6 +1907,79 @@ lease, red-main refusal, main's complete affected proof and releases from a
green main all still apply. A fast-lane merge is not a successful delivery
until its main run is green.

## Changed tests repeat under load before merge

The maintainer ruled on 2026-11-16
([#4109](https://github.com/schlessera/brain-kit/issues/4109)) that a Bun test
file a pull request adds or modifies must pass repeated runs under CPU load
before it merges.

**Why.** Main went red 25 times between 2026-11-02 and 2026-11-16. About 18 of
those incidents were cleared by changing only a test: a wait, a pinned clock,
a readiness signal, a deadline a loaded shard could meet. About six were
product defects. The first-main failure rate was about the same for PRs under
100 lines (19%) as for PRs over 2,000 lines (22%). These are tests that pass
once and fail later on someone else's merge, and nothing ran a new or changed
test more than once before it merged.

- **What runs.** `bun scripts/test-determinism.ts --base <ref>` selects the
Bun test files under `packages/` and `tests/` that the change adds or
modifies against its merge base (`determinismTests`,
`scripts/ci-plan.ts:323-328`). It runs them in one invocation of the offline
wrapper with Bun's `--rerun-each=<n> --bail=1` (`repetitionArgv`,
`scripts/test-determinism.ts:84-87`), so the offline preload applies and
preparation builds once. One busy loop per CPU runs for the duration. Each
is killed by PID on every exit path, and exits by itself if its parent dies
(`startBurners`, `scripts/test-determinism.ts:136-151`). The first failing
repetition fails the command, which names the file, the repetition and the
case. A passing run must also show every repetition in Bun's test report.
- **Bounded.** Five repetitions by default, within a budget of 600 seconds of
the reviewed weights in `scripts/test-shard-costs.json`. When five do not
fit, every file gets the same reduced count, down to a floor of two
(`planRepetitions`, `scripts/test-determinism.ts:62-81`). A selection too
heavy for the floor still runs every file twice and is reported over budget.
No selected file is skipped; the report lists each one with the repetitions
it got. Over 150 merges before the gate, 142 selections fit five
repetitions. A selection too heavy for the job's step limit is
[#4117](https://github.com/schlessera/brain-kit/issues/4117).
- **Where it is required.** The hosted `determinism` job is selected whenever
the plan lists such a file, at every pull-request cadence: draft, ready
`synchronize` feedback and ready confirmation. Draft heavy feedback runs it
too (`proofSelections`, `scripts/ci-plan.ts:441-453`). This amends "drafts
run cheap gates only" for this one job, so the
[fast lane](#fast-lane-outside-the-core-packages)'s newest run includes it.
`draft gates`, `proof` and the merge path require it when selected and
require its intentional skip otherwise. It is a fast category under the
[hybrid split](#hybrid-post-merge-heavy-proof): it is not in
`POST_MERGE_CATEGORIES`. The job has the `unit` job's runtime prerequisites,
because a changed file may drive real Chrome.
- **Not on main.** A main push never selects it. The squash's files were
repeated before they merged, and the main run already runs each of them once
in `unit`.
- **Not local.** `check:pr` never runs it, because it occupies every CPU of a
shared host. `check:pr --plan` names the command when the change selects it.
A deliberate local run takes a
[host admission](../process/testing.md#host-admission-for-heavy-local-commands) slot.

**What does not change.** No test deadline changes. No failure is retried
into a pass: a failing repetition is a failed job, and the remedy is fixing
the test or what it exposes. Unchanged tests are not repeated.

**First hosted run.** The job's first run, on the PR that added it, repeated
seven changed files five times and then failed in the gate's own test: under
GitHub Actions Bun prints each run's header as a `::group::` annotation, which
the failure parser did not read, so the failure was reported without its file
and repetition. The parser reads both forms now. That run took 552 seconds
for about 174 weighted seconds, a ratio of about 3.2 under four burners on
four CPUs, so a selection at the 600-second budget needs about 32 minutes of
the 40-minute step limit.

**Known limits.** Repetitions of one file share a process. Bun 1.4.2 evaluates
the module again for each run, but `globalThis` and process state persist, so a
file that leaks state into its next run fails too. Vitest browser, layout,
endurance and story specs run in the pinned container and are not covered
([#4116](https://github.com/schlessera/brain-kit/issues/4116)).

## Historical measurement and upstream guidance

The following guidance records the paid-provider investigation which motivated
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/test-health.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ follows is in [ci-utility.md](ci-utility.md) and
enumerated fields.
- **A batch stays inside one group and lands as one pull request.** Hosted
proof for a test edit is priced by the workspaces it touches, not by the
number of files (`const packageCode`, `scripts/ci-plan.ts:355-356`): any path
number of files (`const packageCode`, `scripts/ci-plan.ts:372-373`): any path
under a package's `tests/` selects that package and its reverse dependants.
One changed test in a package costs the same confirmation as thirty, so
small pull requests are the most expensive way to land this work. A large
Expand Down
9 changes: 9 additions & 0 deletions docs/process/test-authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ test("the date field shows the parsed date and refuses an unparseable one", asyn
discovers. Prevents `skipped`, `conditional-skip`, `retry`, `only` and
`undiscovered`.

A Bun test file that a pull request adds or modifies is checked against these
rules before it merges: the hosted `determinism` job runs it five times in a
row under CPU load and fails on the first failing repetition
([the gate](testing.md#changed-tests-repeat-under-load)). A test that waits for
a while, reads the wall clock or keeps state from its previous run fails
there, not on someone else's merge. Reproduce a failure with
`bun scripts/test-determinism.ts --base origin/main`, and fix the test under
the rule it broke. A longer deadline or a retry is not a fix.

## Cost

- **C1. Know the budget of the tier.** Most unit files finish in under a
Expand Down
46 changes: 43 additions & 3 deletions docs/process/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,41 @@ Await it and assert on the result, or use `expectRejection`
(`packages/ui-server/tests/helpers/expect-rejection.ts`)
([why](../decisions/sqlite-write-worker.md#testing-note)).

## Changed tests repeat under load

A Bun test file that a pull request adds or modifies runs several times under
CPU load before it merges
([the 2026-11-16 ruling](../decisions/ci-utility.md#changed-tests-repeat-under-load-before-merge)).
Most red-main incidents in the two weeks before it were cleared by changing
only a test that had passed once.

```sh
bun scripts/test-determinism.ts --base origin/main # what the hosted job runs
bun scripts/test-determinism.ts --base origin/main --json # the report on stdout
```

- **Selection.** Files that `bun test` discovers under `packages/` and
`tests/`, added or modified against the merge base. Deleted files, the
experiment tier and Vitest specs are not selected.
- **The run.** One invocation of `bun run test` with `--rerun-each` and
`--bail=1`, so the offline preload is active and a non-loopback connection
fails as it does in any test. One busy loop per CPU runs until the command
exits; each is stopped by PID and exits by itself if the command is killed.
- **The bound.** Five repetitions, reduced uniformly to no fewer than two when
the reviewed weights in `scripts/test-shard-costs.json` exceed 600 seconds.
The report lists every selected file with the repetitions it got, and says
when the selection is over budget at the floor.
- **A failure** names the file, the repetition and the case. Repetitions of a
file share one process, so state left on `globalThis`, in the environment or
on disk reaches the next run. Fix the test; do not raise its deadline.
- **Where it runs.** The hosted `determinism` job, at every pull-request
cadence including draft, and in draft heavy feedback. `draft gates` and
`proof` require it when the change selects it. `check:pr` never runs it: it
occupies every CPU, and the host is shared. `check:pr --plan` prints the
command when it applies. A local run waits for
[host admission](#host-admission-for-heavy-local-commands);
`--burners <n>` lowers the load for a diagnosis.

## Tests that cannot fail

A green test is evidence only if it could have been red. Each of these shapes
Expand Down Expand Up @@ -636,7 +671,10 @@ in the [CI and merge reference](../../.agents/skills/work-issue/references/ci-an
release preparation runs instead of PR proof. Scheduled
exhaustive CI is additional coverage, not a replacement for selected
pre-merge proof.
- Drafts run cheap gates. Ready `opened`, `reopened` and `ready_for_review`
- Drafts run cheap gates, plus the `determinism` job when the change adds or
modifies a Bun test file
([changed tests repeat under load](#changed-tests-repeat-under-load)).
Ready `opened`, `reopened` and `ready_for_review`
events request full affected confirmation. Ready `synchronize` runs affected
fast invariants and types only; `proof` remains nonpassing until the author
converts to draft and marks ready after the final push. A push invalidates
Expand Down Expand Up @@ -713,13 +751,15 @@ action/runtime versions, pinned offline browser image and diagnostic
artifacts. Independent selected categories run after metadata; the final proof
aggregate rejects failures, cancellations, missing outputs and unexpected
skips. Tests-only changes may intentionally skip packaging while complete
affected tests run. Drafts run cheap gates only. Forks use ordinary
affected tests run. Drafts run cheap gates only, with one exception: the
`determinism` job repeats a change's added or modified Bun test files under
CPU load at every pull-request cadence. Forks use ordinary
`pull_request`, a read-only token (`contents: read`, plus `actions: read` /
`checks: read` for bounded proof lookup), no secrets and nonpersisted checkout
credentials. A fork run awaiting maintainer approval has not passed.

Environment setup via `scripts/ci-runtime-setup.sh` has its own 12-minute
step limit in `unit`, `runtime` and `runtime_host`. Proof retains a separate
step limit in `unit`, `runtime`, `runtime_host` and `determinism`. Proof retains a separate
30-minute unit allowance or 15-minute runtime allowance. The job caps are
45 and 30 minutes respectively, including three minutes for the remaining
steps. The [timeout basis](../decisions/ci-utility.md#separate-environment-setup-and-proof-budgets)
Expand Down
Loading
Loading