Skip to content

test: make parallel-flaky files safe to run together (HACK-2727) - #1282

Merged
roodboi merged 6 commits into
nextfrom
claude-lead/parallel-test-flakes
Nov 27, 2026
Merged

roodboi merged 6 commits into
nextfrom
claude-lead/parallel-test-flakes

Conversation

@roodboi

@roodboi roodboi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Several test files failed when the suite ran 12 files at a time on a 16-CPU Mac, then passed alone (HACK-2727). The batch logs point to two causes, and load reruns found a third. None is a product bug.

  1. Compile scratch in the checkout (most of the failures). bun build --compile and Bun.build({ compile }) write the executable as a transient .<hash>-<n>.bun-build file in the compiling process's working directory, then rename it to the outfile. <n> counts up per process (-00000000, -00000001, ...). Seven compile sites ran with the checkout as that directory, either named or inherited: five bun build --compile spawns, the in-process Bun.build({ compile }) helper in step-store (called three times), and a Bun.build({ compile }) in a fixture child started in the checkout. While one of them compiled, every other file's checkout write guard (HACK-1343) that read git status saw an untracked file and failed its run, even though all of its cases had passed. In the retained batch logs, every file entry the guard named was a ?? .<hash>-<n>.bun-build; most end in -00000000, and the Nov 26 batch also has a -00000002.
  2. Bun's 5 s default timeout on cases with no timers, whose wall time is process starts and file work. env-migration-journal was the repeat offender. When a case timed out, it kept running after afterEach had removed its root, and its stranded work then threw errors into the next case.
  3. A readiness race in the TTY fixture. It showed up only in the load rerun. The probe sent SIGTERM as soon as input.txt existed, but the worker creates that file before it writes it and before it prints its stdout and stderr.
sequenceDiagram
    participant A as test file A (compile)
    participant FS as checkout root
    participant B as test file B (guard)
    A->>FS: bun build --compile, cwd = checkout
    FS-->>FS: .<hash>.bun-build appears
    B->>FS: afterAll: git status
    FS-->>B: ?? .<hash>.bun-build
    B-->>B: guard fails the run
    A->>FS: rename to --outfile (file gone)
Loading

Per-file causes and fixes

File Root cause Fix Evidence it is fixed
tests/host-exec-tty.test.ts Compiled index.ts with cwd set to the checkout Compile the absolute entry with cwd set to the test's temp directory A watcher on the checkout root saw 1 .bun-build during the file before the fix and 0 after
tests/v4-upgrade.test.ts Same, with cwd: repository Absolute fixture entry, cwd: buildRoot Root watcher 1 → 0
tests/native-interactive-exec.test.ts The compile inherited the runner's working directory (the checkout) The compile is now its own spawn with cwd: root, so the scan can tie the cwd to it Root watcher 1 → 0
tests/prerelease-plan.test.ts The compile inherited the runner's working directory Absolute entry, cwd: root Root watcher 1 → 0
tests/daemon-systemd-cli.test.ts Its Linux-only compile used cwd: REPO_ROOT. Its own Nov 26 failure was the guard seeing another file's .bun-build cwd: f.root The new scan flags the old line (its cases skip on macOS)
tests/step-store.test.ts Three in-process Bun.build({ compile }) calls ran in the test runner's process, whose cwd is the checkout Spawn bun build --compile (same entry and defines) with cwd set to the test's root Root watcher 3 → 0
tests/fixtures/cli-renderer-loading.ts cli-renderer-loading.test.ts starts this control with the checkout as cwd, and its build mode calls Bun.build({ compile }) there The control runs process.chdir into its outfile's owned directory before compiling Root watcher 1 → 0
tests/fixtures/tty-cancellation.py (host-exec-tty io case) The probe signalled when input.txt appeared. Under load the worker was cancelled before its writes and prints finished (input, stdout and stderr all empty, exit 143) The worker publishes io.done after all input and output; the probe waits for that file Did not recur in the 10-round runs below
tests/env-migration-journal.test.ts Cases wait on no timer; each makes about 60 sequential git probes plus private-file writes. The slowest takes 1.7 s alone, others took 4.4 s in a batch, and several crossed 5 s. The SIGKILL boundary case reached 106 s of its 120 s budget in batches File-scoped setDefaultTimeout(60_000) and a 300 s budget for the SIGKILL case. Each is written down as a load bound, following HACK-1439. No assertion changed 8 concurrent copies beside 12 CPU burners: before, 8/8 failed on the 5 s timeout; after, all 42 bounded cases passed
tests/prerelease-plan.test.ts (MCP packaging case) Packages and verifies the prerelease several times, each time hashing, archiving and probing every MCP executable. 0.66 s alone and at most 0.58 s in batches, but 4.7 s, and past 5 s in every round, beside the suite's other compile-heavy files 60 s budget on that case, reason recorded 10/10 below
tests/doctor-fix-noninteractive.test.ts Bun's 5 s default. Its cases run hack doctor --fix in process (Docker mocked). The HACK-1695 case takes 1.05 s alone and passed at up to 4.94 s in batches; on Nov 26 it timed out, and the stranded case then failed the next one with an ENOENT File-scoped setDefaultTimeout(30_000), matching the 30 s most cases there already name, with the reason recorded 10/10 below
tests/sync-spawn-bound.test.ts Its batch failures were the guard (.bun-build). Under more load, its scan, which TypeScript-parses about a thousand files (1 s alone, 3.6 s in batches), also crossed 5 s 60 s budget on the scan case, reason recorded 10/10 below
tests/internal-extra-hosts-worktree.test.ts Its batch failures were the guard. Its CLI case runs five cold CLI starts from source, reached 4.5 s of 5 s in batches, and crossed 5 s under more load 60 s budget on that case, reason recorded 10/10 below
subprocess-signal, native-image-tags, project-config, host-exec-lifetime, native-host-plan-transport (unchanged) Victims only. Their only parallel failure was the guard naming another file's .bun-build. I found no shared temp path, port, process-group signal or env leak None needed Reproduction below: 20/25 failed while a compile ran in the checkout, 0/25 with an owned cwd; 10/10 below
tests/compile-working-directory.test.ts (new) Regression guard. Its repository scan parses over a thousand files (about 1 s alone) and crossed 5 s once in ten rounds, so it has a 60 s budget with the reason recorded Parses tracked tests/**/*.ts and scripts/**/*.ts with the TypeScript compiler and finds: "--compile" argv arrays and single-string bun build … --compile commands, which must name a cwd in the options of the spawn call that receives them (tied to that call, not to a nearby one) and not the checkout; Bun shell $`bun build … --compile`, which must chain .cwd(...); and Bun.build({ compile }), which is refused in test files and helpers and needs a prior process.chdir in fixtures and scripts. Names it treats as the checkout: REPO, REPO_ROOT, ROOT, repository, repoRoot, checkout, process.cwd(), and anything built from import.meta.dir/url/path (including dirname(import.meta.dir) and resolve(import.meta.dir, "../..")). It skips its own sample code and scripts/build-release.ts (no test runs that one) On the origin/next sources it flags all seven old sites. The first version of this file failed on itself once tracked (its samples matched); it now excludes itself, and its sample cases are unit tests

sync-spawn-bound also failed in 7 batches for a different reason. Those trains added an unbounded spawnSync that also failed alone, so those were real regressions in the PRs under test, not flakes.

Nothing is marked serial, and no assertion, retry or guard was weakened.

Validation

  • Guard reproduction: a loop compiled the CLI while native-image-tags ran 25 times. With the compile's cwd in the checkout, 20 of 25 runs failed with ?? .<hash>.bun-build. With an owned cwd, 0 of 25 failed.
  • A root watcher saw .bun-build files at the checkout root during host-exec-tty, v4-upgrade, native-interactive-exec, prerelease-plan (1 each), step-store (3) and cli-renderer-loading (1) before the fix, and none after.
  • Final head, 10 rounds. Each round ran all 12 changed test files plus the Nov 26 failures not already among them (daemon-socket-permissions, compose-startup-phases, prerelease-platforms, project-target-inspect, system-tool), 17 bun test processes at once, each with its own temp HOME, beside 3 CPU burners. A recursive watcher on the checkout ran through every round and recorded 0 .bun-build files. Other sessions share this Mac, so each round started only after the 1-minute load fell below 12 (on 18 CPUs). Load during the rounds was 10–25. Result: 169/170 passed. The one failure was in round 10: cli-renderer-loading's source-mode controls hit that file's own fixed 10 s per-child budget at 11–13 s. That is 7× their batch maximum of 1.7 s. This change does not touch that path (only the build mode compile moved), so I left the budget alone.
  • Earlier rounds that overlapped other sessions' load (yes burners and TLA+ runs, load 25–61) also ran past internal wall-clock bounds that no batch comes near: the v4-upgrade fixture's 30 s per-command bound, the interactive frontend's 15 s readiness deadline, and the 20 s budgets of the journal key-publication cases. None of those runs saw a .bun-build file.
  • Root bun run typecheck and bun run check pass, the changed files pass biome check, privacy:check passes after staging, and gitleaks found no leaks in either staged diff.
  • Every run set HACK_DAEMON_AUTOSTART_DISABLE=1 and used a temp HOME. pgrep -x hackd showed 0 before and after. No VM or krun binary ran, and candidate-daemon-identity was not run.

Not covered here

  • env-migration-provider ("production CLI explicitly repairs Compose…") also hit Bun's 5 s default in older batches. It looks like the same class but was outside this ticket's list.
  • The scan covers TypeScript only; shell scripts that run bun build --compile are not checked.
  • Many files outside the list (for example private-env-file, native-interactive-launcher and system-tool) failed in batches only through the .bun-build guard, so this change should clear them too.

🤖 Generated with Claude Code

Five test compiles ran `bun build --compile` with the checkout as their
working directory. Bun stages the executable as a transient
`.<hash>.bun-build` there, so every other file's checkout write guard
that read `git status` meanwhile failed its run. Compile in the test's
own directory, and add a scan that keeps it that way.

Give the in-process env migration cases, the SIGKILL boundary case, the
sync-spawn scan and the five-CLI extra-hosts case load budgets, with the
measured reasons written next to each. Make the TTY fixture signal only
after its worker has finished all input and output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hack-docs Ready Ready Preview Nov 27, 2026 12:14am UTC

Request Review

@linear-code

linear-code Bot commented Nov 26, 2026

Copy link
Copy Markdown

HACK-2727

roodboi and others added 3 commits November 26, 2026 16:35
…rd (HACK-2727)

Bun.build({ compile }) also stages its .bun-build in the compiling
process's working directory. step-store compiled in the test runner's
process and the renderer-loading control compiled in a child started in
the checkout. Spawn the step-store compile in its own root and move the
control to its outfile's directory before it compiles.

Rewrite the compile scan over the TypeScript syntax tree: tie cwd to
the call that runs the argv, recognize more names for the checkout,
cover command strings, Bun shell and Bun.build({ compile }), and skip
the scan's own samples.

Give doctor-fix-noninteractive a file-scoped 30 s budget, with the
measured reason written next to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ACK-2727)

Both wait on no timer and crossed Bun's 5 s default beside the suite's compile-heavy files; the measured reasons sit next to each budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hdir targets (HACK-2727)

cli-compile-define read compile-working-directory's sample code as real CLI compiles; list it with the other description-only files. The Bun.build rule now also refuses a process.chdir into the checkout before the compile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Update at db572f76bc10cff24801b3431ff0b5cb69a4a1d6:

  • Fix: tests/cli-compile-define.test.ts failed at b525bda8 because its repository scan read the sample code in tests/compile-working-directory.test.ts as real CLI compiles. That file is now in DESCRIPTIONS_ONLY, next to cli-compile-flags.
  • Rule change: the Bun.build({ compile }) rule now also checks the process.chdir target. The latest process.chdir before the compile must not name the checkout. New unit cases cover a chdir into the checkout and the order of several chdirs.
    • Known limit: "latest" means latest in source order, not along the code paths that actually run, so a chdir in a branch that does not run still counts.
  • Repository-scan tests: every one passes together. That is cli-compile-define, cli-compile-flags, fixture-hermeticity, secrets-hygiene, env-secret-sentinel-scan, checkout-write-guard, sync-spawn-bound, compile-working-directory and cli-spawn-env-isolation, plus the other tests that call git ls-files or Glob: doctor-fix-adopted-project, doctor-generated-files, env-legacy-service-scope, env-set-local-contract, project-domain-migration and project-task-catalog. Result: 412 pass, 0 fail.
  • Other gates: root bun run typecheck and bun run check pass, biome check passes on both files, privacy:check passes after staging, and gitleaks found no leaks.

@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Merged origin/next (cd2e21fd) into the branch with a merge commit; no rebase, no force. The overlapping file, tests/native-interactive-exec.test.ts, merged cleanly. New head: f48f66ad11bf894527c3b962ff4cec75ebbb9bf0.

At this head:

  • All 12 changed test files plus the scan tests (cli-compile-define, cli-compile-flags, fixture-hermeticity, secrets-hygiene, env-secret-sentinel-scan, checkout-write-guard, sync-spawn-bound, compile-working-directory, cli-spawn-env-isolation) pass together: 19 files, 338 pass, 9 skip, 0 fail.
  • Root bun run typecheck and bun run check pass.
  • privacy:check passes.
  • gitleaks found no leaks in origin/next..HEAD.

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T23:23:32.521244Z f48f66a Manual request
🔒 Security Review ✅ Completed 2026-11-26T23:24:33.680884Z f48f66a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: f48f66ad11

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: f48f66ad11

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Resolved to the tree tested in batch run m3:z494 (lead train sync).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roodboi
roodboi merged commit 22355a6 into next Nov 27, 2026
6 of 7 checks passed
@roodboi
roodboi deleted the claude-lead/parallel-test-flakes branch November 27, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant