Enable minitest parallelization after thread-safety audit #488

Closed
opened 2026-08-23 13:48:40 +00:00 by jared · 3 comments
Owner

Context

The os-sdlc suite is fully serial (no parallelize_me!/Minitest.parallel_executor anywhere); dominant cost is subprocess I/O wait, so parallelization should scale near core count (83s → ~15-25s even before tickets 2-3 land). Blocker: with_target_env in tests/test_helper.rb mutates ENV["OS_SDLC_TARGET"] globally, unsafe under concurrency.

Tasks

  • Audit shared ENV/global state (with_target_env, tmpdir usage, any class-level caches) for thread safety.
  • Enable parallelize_me! (or the executor) once safe.
  • Confirm stable green across 5 consecutive runs.

Acceptance criteria

suite runs parallel and green repeatedly; wall time materially reduced.

Origin

  • Trigger: manual full-suite run of plugins/os-sdlc tests on 2026-08-23 (77.9s, 1 failure) prompting a root-cause probe session
  • Improvised: none
  • Chain: additive serial wait ← no parallel executor configured ← ENV-mutating test helpers assume serial execution — DESIGN (tests/test_helper.rb with_target_env)
  • Root candidate: this ticket
  • Note: do after the subprocess-conversion ticket lands, or re-measure need.
## Context The os-sdlc suite is fully serial (no parallelize_me!/Minitest.parallel_executor anywhere); dominant cost is subprocess I/O wait, so parallelization should scale near core count (83s → ~15-25s even before tickets 2-3 land). Blocker: with_target_env in tests/test_helper.rb mutates ENV["OS_SDLC_TARGET"] globally, unsafe under concurrency. ## Tasks - [ ] Audit shared ENV/global state (with_target_env, tmpdir usage, any class-level caches) for thread safety. - [ ] Enable parallelize_me! (or the executor) once safe. - [ ] Confirm stable green across 5 consecutive runs. ## Acceptance criteria suite runs parallel and green repeatedly; wall time materially reduced. ## Origin - Trigger: manual full-suite run of plugins/os-sdlc tests on 2026-08-23 (77.9s, 1 failure) prompting a root-cause probe session - Improvised: none - Chain: additive serial wait ← no parallel executor configured ← ENV-mutating test helpers assume serial execution — DESIGN (tests/test_helper.rb with_target_env) - Root candidate: this ticket - Note: do after the subprocess-conversion ticket lands, or re-measure need.
Author
Owner

Work started: thread-safety audit + minitest parallelization (batch session 2026-08-23).

Work started: thread-safety audit + minitest parallelization (batch session 2026-08-23).
Author
Owner

Done: minitest parallelization enabled after thread-safety audit. Commit 090c0b1. Wall time 49.1s -> ~13-20s across 5 verification runs (all green). See commit for details; full report in session transcript.

Done: minitest parallelization enabled after thread-safety audit. Commit 090c0b1. Wall time 49.1s -> ~13-20s across 5 verification runs (all green). See commit for details; full report in session transcript.
Author
Owner

Resolution

Done: Thread-safety audit completed and minitest parallelization enabled. Fixed at the root: with_target_env removed from the shared helper (now local to GateCommandsTest), InProcessRunnerCli's global stdout/stderr redirect replaced with a thread-local ThreadRoutedIO, and the process-wide Open3.capture3 monkeypatch replaced with a permanent thread-local seam. Classes touching Dir.chdir/ENV[HOME] run under executor-drain exclusivity (Minitest.run_test_exclusively); 9 classes stay serial.

Evidence: Commit 090c0b1: 12 test files, no lib/ changes. Agent's 5 consecutive green runs: 18.0/20.4/16.6/16.9/17.5s. Independent verification run: 1035 runs, 2692 assertions, 0 failures, 18.2s wall at 475% CPU, vs 83s batch baseline. Two diagnosis rounds used within the agreed two-attempt policy, both root-caused (Dir.chdir concurrent-block crash, Open3 stub cross-thread contamination). No net-new rubocop offenses.

Follow-ups: Dropped: re-parallelizing the 9 serial classes — suite is at ~17s, further work is speculative optimization. Dropped: giving RecordingOpen3's status struct a success? method — speculative hardening, fails loudly if ever hit. Dropped: moving ThreadRoutedIO/Open3 seams out of test_helper.rb — style preference with no observed cost.

## Resolution **Done:** Thread-safety audit completed and minitest parallelization enabled. Fixed at the root: with_target_env removed from the shared helper (now local to GateCommandsTest), InProcessRunnerCli's global stdout/stderr redirect replaced with a thread-local ThreadRoutedIO, and the process-wide Open3.capture3 monkeypatch replaced with a permanent thread-local seam. Classes touching Dir.chdir/ENV[HOME] run under executor-drain exclusivity (Minitest.run_test_exclusively); 9 classes stay serial. **Evidence:** Commit 090c0b1: 12 test files, no lib/ changes. Agent's 5 consecutive green runs: 18.0/20.4/16.6/16.9/17.5s. Independent verification run: 1035 runs, 2692 assertions, 0 failures, 18.2s wall at 475% CPU, vs 83s batch baseline. Two diagnosis rounds used within the agreed two-attempt policy, both root-caused (Dir.chdir concurrent-block crash, Open3 stub cross-thread contamination). No net-new rubocop offenses. **Follow-ups:** Dropped: re-parallelizing the 9 serial classes — suite is at ~17s, further work is speculative optimization. Dropped: giving RecordingOpen3's status struct a success? method — speculative hardening, fails loudly if ever hit. Dropped: moving ThreadRoutedIO/Open3 seams out of test_helper.rb — style preference with no observed cost.
jared closed this issue 2026-08-23 15:11:09 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jared/cc-os#488
No description provided.