Repository navigation
fix(ci): stop the api integration shard partition rotating every run - #955
Conversation
Every test in settings-agents.integration.test.ts persisted per-user rows into the shared in-memory database — user_app_settings, user_tool_settings, and the built-in agent overrides a PUT saves — under one fixed user id, and nothing truncates those rows between tests. Isolation does not cover this: `--isolate` gives each file a fresh module graph, not each test. The file was therefore order-dependent, and in one direction it failed. With "updates built-in default settings per user" running first, its persisted `default` override is what "synthesizes default from legacy app settings and enabled tools" then reads, so the assertion on `Legacy chat prompt` got `Persisted chat prompt`. Reproduced with `bun test --randomize --seed=2` (also 4, 5 and 6; 1, 3, 7 and 8 were clean) — the failure the randomized-order nightly has reported on the api lane every night since that workflow landed. Namespace the rows with a fresh identity per test rather than enumerating the tables to truncate, so a test that later writes a new one cannot reopen the hole. All eight probe seeds now pass. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
PR #951 took the api integration suite out of isolate mode to dodge Bun's isolate-runner hang (oven-sh/bun#39709), leaving one lane that is both sharded and unisolated. Its 101 files share a module graph, so what a shard runs a file beside decides what that file inherits: the in-memory database from setupTestEnvironment(), any mock.module registration, the memoized getAuth(). The partition deciding those companions came from a timings file that --update-timings refreshes every run and CI caches across runs, so it rotated — a leak would surface as an intermittent failure in a file nobody touched, on a partition nobody could reproduce. #951's own first CI run already hit the class: shard 3 failed because app.ts snapshotted getConfig().corsOrigins at module evaluation, so which file imported app first decided what the CORS gate saw. Drop the lane's timingsPath and the --timings/--update-timings flags, so `--shard=i/N` falls back to the round-robin over the alphabetical file list every shard derives independently from the file set alone. The same commit now always produces the same partition. Measured on the lane (Bun 1.4.0, 101 files, 85.3s total, --shard=i/8): the critical shard goes 20.3s -> 29.9s. Cheap because one file (spawn-runtime-child, 20.3s) is 24% of the lane and is the floor under any split, so the balancing had little left to win. Determinism verified rather than assumed: two consecutive no-timings runs produced byte-identical partitions, union 101 files, no duplicates. A soak of 48 shard runs over six partitions — two round-robin and four rotated, from +/-20% jitter to 0.5-2x — came back 0 fail, which is the evidence for taking this over unsharding the lane. If the nightly's unisolated lane ever does go red on cross-file leakage, that escalation is still available at 85.3s on the critical path instead of 29.9s. Closes #952. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
randomized-order-nightly.yml exists for "the one class the merge gate cannot see: a test that passes only because of what the file before it left behind." Every lane in it ran with --parallel=1, which means one worker *isolated* — Bun implies --isolate — so each file got a fresh global and cross-file leakage was unreachable. The workflow could only ever surface order dependence inside a single file, and the class it was written for had no detector anywhere in CI. That gap is what let the api integration lane rely on a rotating shard partition for safety rather than on evidence. Give it a detector: the matrix becomes include-only so each lane carries its own isolation setting and path, and a new api-integration entry re-runs tests/integration with no --parallel at all — the mode the merge gate actually uses. Artifacts and the job name key on the lane rather than the workspace, since two entries now share `workspace: api`. scripts/tests/randomized-order-nightly.unit.test.ts pins the two properties that decide whether the workflow can detect anything: that the unisolated lane exists, and that it is never quietly handed the --parallel=1 every other lane takes. Refs #952. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
The new randomized-order lane failed 4-5 tests on every seed tried (1, 2, 3), in three files that are green in the fixed order. `--randomize` reorders `it` and `describe` blocks within a file as well as the files themselves, so all three are reachable without any cross-file leakage at all. settings-app-settings: every test persisted `user_app_settings` under one fixed user id, so "persists app settings per user" was what "returns defaults for a new user" read back when the shuffle put them in that order. Fresh identity per test, and the malformed-JSON row's fixed primary key namespaced with it. chat-todos: `insertTestUser`/`insertTestChat` already mint fresh ids per call, but they were called once in `beforeAll`, so every test shared one chat. The three todos written by "returns the persisted todo list" were what "returns an empty list when the chat has no todos" then read. Minting the fixtures in `beforeEach` is the whole fix. settings-connectors: `beforeAll` runs per `describe`, and the `openai connector routes` block seeded `user` rows for two identities it never authenticates as — both belong to the `openai project-scoped connector routes` block, which had no `beforeAll` of its own. Scheduled the other way round, every route there that persists a connector failed `secret_metadata`'s foreign key and answered 500 (`PRAGMA foreign_keys = ON` is unconditional). Each block now seeds exactly the identities it uses, through one idempotent helper. Verified on the full 101-file lane, unisolated: seeds 1, 2 and 3 all give 837 pass / 17 skip / 0 fail, against 5, 5 and 4 failures before. Refs #952. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. Summary by CodeRabbit
WalkthroughThe PR adds an explicit unisolated Sequence Diagram(s)sequenceDiagram
participant NightlyWorkflow
participant TEST_LANES
participant BunTestRunner
participant APIIntegrationTests
NightlyWorkflow->>TEST_LANES: Select api-integration lane
TEST_LANES->>BunTestRunner: Configure deterministic round-robin shards
BunTestRunner->>APIIntegrationTests: Run each shard in one shared module graph
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope functional changes found. Merge Risk: ⚪ Minimal · up to The change makes API integration sharding reproducible and adds detection for cross-test leakage while fixing the exposed tests. No actionable merge-blocking risk remains beyond normal checks and review. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
PR head: Commits — 9 commitsBase
Full commit messages
|
| Metric | Base | Head | Δ |
|---|---|---|---|
| Wall clock (shared jobs) | 11m 36s | 5h 41m 2s | 🔴 ▲ +5h 29m 26s |
| Critical path | Distribution / Build immutable distribution · 2m 28s |
Distribution / Build immutable distribution · 2m 25s |
🟢 ▼ -3s |
Since previous PR run: 11m 3s → 5h 41m 2s (🔴 ▲ +5h 29m 59s)
Five slowest head jobs
| Job | Base | Head | Δ |
|---|---|---|---|
Distribution / Build immutable distribution |
2m 28s | 2m 25s | 🟢 ▼ -3s |
QA Metrics / Collect |
1m 53s | 1m 43s | 🟢 ▼ -10s |
Test / Tests (frontend) |
59s | 1m 7s | 🔴 ▲ +8s |
Test / Tests (shard 3/8) |
51s | 1m 0s | 🔴 ▲ +9s |
Smoke — Binary / Binary darwin-x64 |
40s | 58s | 🔴 ▲ +18s |
QA Gate — Coverage & Quality
Base: 3986a32 • Head: 2e2fe6c • generated 2026-08-27T14:14:58.120Z
✅ No attention signals — collected metrics look healthy against base.
LoC (code): 🟢 ▼ -8 • Line coverage (all workspaces): ⚪ ▲ = 0 • Quick check: pass • Duplication: 🟢 ▼ -0.01pp • Bundle gzip: ⚪ ▲ = 0 • Locked deps: ⚪ ▲ = 0 • Tests passed: 🟢 ▲ +6
Metric details (coverage, LoC, bundle, dependencies, tests, duplication, tooling)
Coverage
API/shared/runtime branches and statements are source-derived from LCOV line hits because Bun LCOV does not emit branch or statement records.
| Workspace | Metric | Base | Head | Δ |
|---|---|---|---|---|
| frontend | lines | 82.51% (46,694/56,594) | 82.55% (46,693/56,563) | 🟢 ▲ +0.04pp |
| frontend | statements | 84.08% (12,157/14,459) | 84.08% (12,157/14,459) | ⚪ ▲ = 0 |
| frontend | functions | 79.19% (3,284/4,147) | 79.19% (3,284/4,147) | ⚪ ▲ = 0 |
| frontend | branches | 56.16% (6,222/11,080) | 56.16% (6,222/11,080) | ⚪ ▲ = 0 |
| api | lines | 82.73% (73,770/89,165) | 82.69% (73,792/89,234) | 🔴 ▼ -0.04pp |
| api | statements | 81.92% (29,373/35,854) | 81.91% (29,378/35,865) | 🔴 ▼ -0.01pp |
| api | functions | 83.54% (7,179/8,594) | 82.77% (7,080/8,554) | 🔴 ▼ -0.77pp |
| api | branches | 50.81% (11,153/21,949) | 50.84% (11,159/21,949) | 🟢 ▲ +0.03pp |
| shared | lines | 98.02% (15,619/15,935) | 98.02% (15,619/15,935) | ⚪ ▲ = 0 |
| shared | statements | 94.90% (2,736/2,883) | 94.90% (2,736/2,883) | ⚪ ▲ = 0 |
| shared | functions | 92.90% (445/479) | 92.89% (444/478) | 🔴 ▼ -0.01pp |
| shared | branches | 60.69% (928/1,529) | 60.69% (928/1,529) | ⚪ ▲ = 0 |
| runtime | lines | 82.83% (27,468/33,161) | 82.83% (27,472/33,168) | ⚪ ▲ = 0 |
| runtime | statements | 79.74% (9,801/12,291) | 79.74% (9,801/12,291) | ⚪ ▲ = 0 |
| runtime | functions | 77.25% (2,007/2,598) | 76.99% (1,997/2,594) | 🔴 ▼ -0.26pp |
| runtime | branches | 49.69% (3,790/7,627) | 49.68% (3,789/7,627) | 🔴 ▼ -0.01pp |
Lines of Code
| Workspace | Base | Head | Δ |
|---|---|---|---|
| frontend | 760 files / 82,243 lines | 760 files / 82,243 lines | files ⚪ ▲ = 0 • code ⚪ ▲ = 0 |
| api | 1,057 files / 154,168 lines | 1,057 files / 154,160 lines | files ⚪ ▲ = 0 • code 🟢 ▼ -8 |
| shared | 206 files / 29,551 lines | 206 files / 29,551 lines | files ⚪ ▲ = 0 • code ⚪ ▲ = 0 |
| runtime | 836 files / 43,219 lines | 836 files / 43,219 lines | files ⚪ ▲ = 0 • code ⚪ ▲ = 0 |
| total | 2,859 files / 309,181 lines | 2,859 files / 309,173 lines | files ⚪ ▲ = 0 • code 🟢 ▼ -8 |
Frontend Bundle
| Metric | Base | Head | Δ |
|---|---|---|---|
| gzip total | 1.11 MiB | 1.11 MiB | ⚪ ▲ = 0 |
| gzip JavaScript | 1.10 MiB | 1.10 MiB | ⚪ ▲ = 0 |
| gzip CSS | 18.8 KiB | 18.8 KiB | ⚪ ▲ = 0 |
| gzip HTML | 808 B | 808 B | ⚪ ▲ = 0 |
| tracked files | 50 | 50 | ⚪ ▲ = 0 |
Dependencies
| Metric | Base | Head | Δ |
|---|---|---|---|
| locked packages | 668 | 668 | ⚪ ▲ = 0 |
| direct dependencies | 43 | 43 | ⚪ ▲ = 0 |
| direct devDependencies | 36 | 36 | ⚪ ▲ = 0 |
| workspace manifests | 5 | 5 | ⚪ ▲ = 0 |
Tests
Single full-suite pass (unit + integration, from the coverage run).
| Base | Head | Δ passed |
|---|---|---|
| 9,091 passed (root 842 / frontend 1,904 / api 4,552 / shared 832 / runtime 961) · exit 0 · 40s | 9,097 passed (root 848 / frontend 1,904 / api 4,552 / shared 832 / runtime 961) · exit 0 · 40s | 🟢 ▲ +6 |
Code Duplication (jscpd)
| Metric | Base | Head | Δ |
|---|---|---|---|
| clones | 1,324 | 1,322 | 🟢 ▼ -2 |
| duplicated lines | 15,482 | 15,459 | 🟢 ▼ -23 |
| percentage | 3.94% | 3.94% | 🟢 ▼ -0.01pp |
Repo Tooling
| Metric | Base | Head | Δ |
|---|---|---|---|
| Full repo check | pass | pass | ⚪ ▲ = 0 |
| TS errors (total) | 0 | 0 | ⚪ ▲ = 0 |
| Circular dependencies | 0 | 0 | ⚪ ▲ = 0 |
`mock.restore()` does not revert `mock.module()`, so the stubs the
`Gemini aliases API` block installs for `src/services/gemini` stayed
swapped for the rest of the lane. `restoreConnectorProviderMocks()` only
re-registered openai and base-url-policy, so nothing put gemini back.
Under `--randomize` that block can run before the alias route tests in
the same file, which then assert against the stub rather than the route
— a vacuous pass, and the wrong-state failure the unisolated
`api-integration` lane exists to catch.
Captures the whole namespace at module load (`{ ...geminiService }`)
rather than a hand-listed subset: the overrides tests install are
partial, and the route modules bind `InvalidGeminiApiKeyError` and
`GeminiValidationUnavailableError` for `instanceof` checks, so restoring
a subset leaves the same hole in a different shape. `mock.module` on an
already-loaded module merges, so re-registering the full namespace
overwrites every stubbed key back to the real one.
Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
`settings-agents` and `settings-app-settings` each carried their own `interface TestIdentity` and their own `identitySeq` mint — the same contract `UserFixture` in tests/support/factories already exports, in a third and fourth copy. The next suite that needs per-test identities would have copied a fifth. `makeTestIdentity(prefix, name)` mints without inserting, which is what these suites want: their rows are keyed by user id and nothing truncates the tables in between, so the id is the namespace and the `user` row itself is never read. The counter is module-level, so ids stay unique across the files sharing one module graph in the unisolated `api-integration` lane. Row ids now suffix `testUser.id` rather than the bare counter, so the row and the identity that owns it cannot drift apart. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
…te as TEST_USER The file's own rule is that every `describe` seeds the identities it authenticates as, but `settings connectors routes` and `Gemini aliases API` both authenticate as `TEST_USER` with no `user` row behind it. That holds only while no route those blocks exercise persists a user-owned row: the first test added to either that POSTs a connector hits `secret_metadata`'s foreign key on a missing `user.id` and answers 500 — reopening the hole the project-scoped block just closed. `seedUsers` moves to tests/support/factories as `ensureTestUsers`, next to the `insertTestUser` it was re-implementing. Keeping a private copy meant a `user` schema change had to land in two places, and missing the test-only one fails with a NOT NULL violation on an unrelated PR. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
…check
Two of the five guards were passing for reasons unrelated to what they
assert:
- `covers every workspace that owns a Bun test lane` did a bare
`toContain('workspace: api')`, which the new integration-only entry
satisfies on its own. Deleting the whole-workspace `api` lane would
stop `apps/api/tests/unit` running under randomization while the test
stayed green. Now asserted against the entries carrying `path: ""`.
- `expect(entry).not.toContain('--parallel')` passed only because the
comment mentioning `--parallel=1` happens to land inside the *api*
entry's capture. Moving that paragraph one entry down — a comment
edit, no behavior change — turned a load-bearing test red. Comments
are now stripped before the assertions read the entry.
Extraction moves onto `extractStepBlocksAtIndent`, the helper every other
workflow policy test in this directory uses, instead of a second regex
dialect; entries are bounded to the `include:` body so the last one no
longer runs to EOF; the lane is matched on the entry's own first line so
`api` cannot claim `api-integration`'s block by prefix; and the workflow
is read once rather than per test.
Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
The header comment promises each job prints the exact command to reproduce its own lane, but the notice printed only the `bun test` flags, dropping the `DATABASE_PATH` and `MANGOSTUDIO_DIAGNOSTIC_LOGS` the job sets. Pasting it locally ran a different suite than the one that went red — and for the unisolated `api-integration` lane that notice is the only record of how to reproduce a leak. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
Summary
Make the
api-integrationshard partition reproducible, and give the bug classit was exposed to an actual detector.
PR #951 took that suite out of isolate mode to dodge Bun's isolate-runner hang,
leaving one lane that is both sharded and unisolated: 101 files sharing a
module graph, split by a timings-balanced partition that rotates every run. A
file's companions changed run to run, so a leak surfaced as an intermittent
failure in a file nobody touched. Separately, the randomized-order nightly — the
only thing in CI meant to catch that class — ran every lane at
--parallel=1,which implies
--isolate, so it could not see cross-file leakage at all.Fixing that second half exposed four real leaks in the first. Additional silent
leakage gaps found during review are tracked separately in #956.
Changes
timingsPathfrom theapi-integrationlane and the--timings/--update-timingsflags from its coverage script, so--shardfalls back to Bun's round-robin over the alphabetical file list — a partition
every shard derives from the file set alone. The same commit now always splits
the same way.
api-integrationentry torandomized-order-nightly.yml.The matrix becomes
include-only so each lane carries its own isolationsetting and path; artifacts and job names key on the lane, since two entries
now share
workspace: api.and three shapes: per-user rows under a fixed user id
(
settings-agents,settings-app-settings), one fixture built inbeforeAlland shared by every test (
chat-todos), and abeforeAllseedinguserrowsthat a sibling
describeconsumed (settings-connectors, which failedsecret_metadata's foreign key and answered 500 on every persisting route).scripts/tests/, so neither can drift back silently.Test Plan
bun run checkpassesbun run testpassesbun run buildpasses@mangostudio/shared/i18n(no hardcoded strings)No production application code changed — this is CI topology, test fixes, and
documentation, so the manual smoke path has nothing to exercise.
Measured on Bun 1.4.0,
apps/api/tests/integration(101 files, 85.3s total,--shard=i/8):--timings, balanced (rotates)+9.6s, and cheap because one file (
spawn-runtime-child, 20.3s) is 24% of thelane and is the floor under any split.
partitions — the stride
i-1, i-1+8, …over the sorted paths, union 101files, no duplicates.
±20% jitter and 0.5–2×) came back 0 fail. That is the evidence for taking this
over unsharding the lane, which would cost 85.3s on the critical path.
--randomizeseeds 1, 2 and3 failed 5, 5 and 4 tests in files that are green in the fixed order — the
detector caught those leaks. After the fixes, all three seeds give 837 pass /
17 skip / 0 fail. These results do not establish that no silent gaps remain;
the known follow-ups are listed in bug: three order-dependency holes remain in the unisolated api-integration lane #956.
Screenshots / GIFs
Not applicable; no UI changes.
Notes
does not stop one. The partition is also stable for a given file set, not
across them — adding or deleting an integration file shifts the whole stride.
loadConfigForTestoverrides are not reverted, one connector filtering testcan pass vacuously when scheduled first, and the
@google/genaimodule mockcan leak out of the connector suite. They are outside this focused change.
fixed in the tests: unshard
api-integrationand run it whole in its own CIjob the way the frontend lane does. Re-isolating stays blocked on
test --isolate: end the outgoing file's process stdio sinks at the global swap oven-sh/bun#38008 (Run test lanes across available CPUs by default, with a worker-count override flag #889).
apilane crashed Bun's isolate runner on 2026-08-26and the job has no watchdog to bound it — filed separately as The randomized-order nightly's api lane crashes Bun's isolate runner, and the job has no watchdog to bound it #954.
merge-timings-shards.tsnow skipsapi-integrationentirely, so its staleentry drops out of the saved timings cache on the first merged run. The
duplicate-claim check it loses only ever existed because
--timingsmade thepartition a function of a shared file.
Closes #952. Refs #889, #951, #954, #956.