Skip to content

ci: isolate Bun test shards into fresh-process batches - #1469

Merged
Wibias merged 6 commits into
devfrom
fix/ci-bun-test-batching
Aug 11, 2026
Merged

ci: isolate Bun test shards into fresh-process batches#1469
Wibias merged 6 commits into
devfrom
fix/ci-bun-test-batching

Conversation

@Wibias

@Wibias Wibias commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Keep the four Linux test shards, but replace each shard's single long-lived bun test process with deterministic fresh-process batches.
  • Print every file in a batch before execution so a runtime crash or hang identifies a small, reproducible suspect set.
  • Bound every Linux batch to 120 seconds, with a 15-second TERM-to-KILL grace period, so a deadlocked Bun process cannot consume the full 15-minute shard timeout.
  • When a multi-file batch times out or Bun crashes, fall back to running that batch's files one at a time in separate Bun processes. If all singleton runs pass, continue the shard; if one singleton crashes or times out, retry that exact file once before failing with the file named explicitly.
  • Ordinary assertion/test failures fail immediately and are never retried.
  • Preserve the existing dedicated storage-policy and api-usage jobs, plus the unsharded macOS control and dispatch-only Windows lane.
  • Keep the default primary batch size at 12 files, configurable through BUN_TEST_BATCH_SIZE; the timeout is configurable through BUN_TEST_BATCH_TIMEOUT_SECONDS.
  • Update the existing api-usage and storage-policy CI contract tests to assert isolation through the new batching helper instead of the removed inline shard command.

Verification

  • bash -n scripts/ci/run-bun-test-batches.sh
  • Parsed the updated Linux test-step YAML snippet with PyYAML.
  • Synthetic fake-Bun checks covering:
    • primary batches succeeding normally
    • a multi-file timeout recovering through one-file-per-process isolation
    • a normal assertion/test failure with zero retries or singleton fallback
    • a runtime-crashing primary batch falling back to singleton isolation
    • a singleton runtime crash passing on exactly one retry
    • a singleton timeout repeated twice failing with the exact file named
    • exclusion of the existing storage-policy/api-usage special-job files
  • CI on 4fb67f8 supplied the root-cause evidence for the adaptive fallback:
    • shard 2/4 entered tests/cli-help.test.ts and then hung until the outer 120-second timeout on both attempts
    • shard 1/4 entered tests/cli-status-json.test.ts and then hung until the same timeout on both attempts
    • both files synchronously spawn real CLI child processes, while one bun test invocation still runs its selected files inside one Bun process
  • fb38f4b replaces the repeated whole-batch retry with singleton process isolation after a runtime crash or timeout, preserving fast 12-file batches on the healthy path.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. No user-facing docs/release-note change is needed for CI-only hardening.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. No permissions, secrets, third-party actions, runner routing, or trust boundaries changed; the matrix shard value and timeout settings are validated before use.

Summary by CodeRabbit

  • Tests
    • Improved Linux test execution by running tests in controlled batches.
    • Added automatic isolation and retry handling for timeouts and runtime crashes.
    • Expanded coverage to include API usage and storage-related tests in shard validation.
  • Chores
    • Updated continuous integration workflows to use the new test batching process.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Linux CI replaces direct Bun shard execution with deterministic fresh-process batching. The helper validates configuration, assigns tests to shards, classifies failures, and retries runtime crashes or timeouts per file. Workflow tests verify API and storage test inclusion.

Changes

Bun CI batching

Layer / File(s) Summary
Validate configuration and assign tests
scripts/ci/run-bun-test-batches.sh
The helper validates shard settings, discovers and sorts test files, excludes selected patterns, and assigns files to shards with round-robin selection.
Execute batches and recover failures
scripts/ci/run-bun-test-batches.sh
The helper runs bounded Bun batches, captures logs, classifies failures, and retries runtime crashes or timeouts as singleton files. Test failures stop immediately.
Wire CI and update workflow assertions
.github/workflows/ci.yml, tests/zz-ci-api-usage-isolation.test.ts, tests/zz-ci-storage-policy-isolation.test.ts
The Linux workflow invokes the helper with TEST_SHARD. Documentation and workflow assertions now cover fresh-process batching and API/storage test inclusion.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CIWorkflow
  participant BatchHelper
  participant BunTestProcess
  CIWorkflow->>BatchHelper: pass TEST_SHARD and batch settings
  BatchHelper->>BunTestProcess: run a bounded test batch
  BunTestProcess-->>BatchHelper: return status and log output
  BatchHelper->>BunTestProcess: retry affected files individually after timeout or runtime crash
  BatchHelper-->>CIWorkflow: return shard status
Loading

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: isolating Bun test shards into fresh-process batches.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ci-bun-test-batching

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Aug 11, 2026
@Wibias
Wibias marked this pull request as ready for review August 11, 2026 10:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 236-239: Update the workflow comment describing
scripts/ci/run-bun-test-batches.sh to document both one-time Bun runtime-crash
recovery and the one-time retry for singleton files after a timeout, while
preserving the statement that ordinary test failures are not retried.

In `@tests/zz-ci-api-usage-isolation.test.ts`:
- Around line 28-31: Update the assertions in
tests/zz-ci-api-usage-isolation.test.ts lines 28-31 to verify that the
tests/api-usage.test.ts matching branch returns 1, rather than only checking
filename text. Update tests/zz-ci-storage-policy-isolation.test.ts lines 28-32
to verify that its storage-policy patterns are within the exclusion branch
returning 1; both sites require direct assertion changes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5b9fca9d-3ef0-40fb-91c5-11b128cb21db

📥 Commits

Reviewing files that changed from the base of the PR and between 5d8c4fe and fb38f4b.

📒 Files selected for processing (4)
  • .github/workflows/ci.yml
  • scripts/ci/run-bun-test-batches.sh
  • tests/zz-ci-api-usage-isolation.test.ts
  • tests/zz-ci-storage-policy-isolation.test.ts

Comment thread .github/workflows/ci.yml
Comment on lines +236 to +239
# `scripts/ci/run-bun-test-batches.sh` mirrors Bun's sorted round-robin shard
# assignment, then runs each shard in small batches so every batch gets a fresh
# Bun process. The helper prints the exact files before each batch and retries
# only a Bun runtime crash once; ordinary test failures are never retried.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Document timeout retries.

Lines 238-239 state that the helper retries only a Bun runtime crash. scripts/ci/run-bun-test-batches.sh also retries a singleton file once after a timeout. Update this text to describe both runtime-crash and timeout recovery. Otherwise, CI operators can misdiagnose an expected retry as unexpected behavior.

Proposed fix
-  # Bun process. The helper prints the exact files before each batch and retries
-  # only a Bun runtime crash once; ordinary test failures are never retried.
+  # Bun process. The helper prints the exact files before each batch and isolates
+  # runtime crashes and timeouts per file. Ordinary test failures are never retried.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# `scripts/ci/run-bun-test-batches.sh` mirrors Bun's sorted round-robin shard
# assignment, then runs each shard in small batches so every batch gets a fresh
# Bun process. The helper prints the exact files before each batch and retries
# only a Bun runtime crash once; ordinary test failures are never retried.
# `scripts/ci/run-bun-test-batches.sh` mirrors Bun's sorted round-robin shard
# assignment, then runs each shard in small batches so every batch gets a fresh
# Bun process. The helper prints the exact files before each batch and isolates
# runtime crashes and timeouts per file. Ordinary test failures are never retried.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 236 - 239, Update the workflow comment
describing scripts/ci/run-bun-test-batches.sh to document both one-time Bun
runtime-crash recovery and the one-time retry for singleton files after a
timeout, while preserving the statement that ordinary test failures are not
retried.

Comment on lines +28 to +31
const batchHelper = await Bun.file(
new URL("../scripts/ci/run-bun-test-batches.sh", import.meta.url),
).text();
expect(batchHelper).toContain("tests/api-usage.test.ts)");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the exclusion result, not only filename text.

These assertions pass if the filename appears in a comment or if the matching case branch returns 0. A regression can then run dedicated tests in general shards and remove the intended isolation.

  • tests/zz-ci-api-usage-isolation.test.ts#L28-L31: assert that the tests/api-usage.test.ts branch returns 1.
  • tests/zz-ci-storage-policy-isolation.test.ts#L28-L32: assert that the storage-policy patterns are in the exclusion branch that returns 1.
Proposed fix
-  expect(batchHelper).toContain("tests/api-usage.test.ts)");
+  expect(batchHelper).toMatch(
+    /tests\/api-usage\.test\.ts\)\s*\n\s*return 1/,
+  );
-  expect(batchHelper).toContain("tests/api-storage-policy*.test.ts");
-  expect(batchHelper).toContain("tests/api-storage.test.ts");
+  expect(batchHelper).toMatch(
+    /tests\/api-storage-policy\*\.test\.ts\|tests\/api-storage\.test\.ts\|tests\/api-usage\.test\.ts\)\s*\n\s*return 1/,
+  );
📍 Affects 2 files
  • tests/zz-ci-api-usage-isolation.test.ts#L28-L31 (this comment)
  • tests/zz-ci-storage-policy-isolation.test.ts#L28-L32
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/zz-ci-api-usage-isolation.test.ts` around lines 28 - 31, Update the
assertions in tests/zz-ci-api-usage-isolation.test.ts lines 28-31 to verify that
the tests/api-usage.test.ts matching branch returns 1, rather than only checking
filename text. Update tests/zz-ci-storage-policy-isolation.test.ts lines 28-32
to verify that its storage-policy patterns are within the exclusion branch
returning 1; both sites require direct assertion changes.

@Wibias
Wibias merged commit 9ef7df8 into dev Aug 11, 2026
31 checks passed
@Wibias
Wibias deleted the fix/ci-bun-test-batching branch August 11, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant