Skip to content

fix(test): make subagent sleep hook portable on Windows - #13

Merged
echoVic merged 1 commit into
mainfrom
fix/windows-subagent-hook-flake
Jul 30, 2026
Merged

fix(test): make subagent sleep hook portable on Windows#13
echoVic merged 1 commit into
mainfrom
fix/windows-subagent-hook-flake

Conversation

@echoVic

@echoVic echoVic commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Problem

The Windows CI gate on main has been failing on the subagent_contract test binary (all 12 tests reported failed, e.g. run 30501966908).

Root cause

async_subagent_completes_after_launching_exec_process_exits writes a pre_model_call hook that runs sleep 0.4:

  • On Windows the resolved host shell is PowerShell (pwsh/powershell.exe), where sleep is an alias for Start-Sleep.
  • Windows PowerShell 5.1's Start-Sleep rejects the fractional 0.4 seconds argument (only PowerShell 6.2+ accepts a double), and cmd.exe has no sleep at all.
  • The hook therefore fails → orca exec exits 1 instead of 0 → the test panics (left: Some(1), right: Some(0)).

Because every test in the file shares one static Mutex, that first panic poisons the lock, cascading into all other tests failing with PoisonError and masking the real cause. (Evidence: the suite "finished in 1.70s", proving the 0.4s hook never actually slept.)

Fix

  1. Portable hook command — emit sleep {seconds} on Unix and Start-Sleep -Milliseconds {ms} (integer, valid on both PowerShell 5.1 and 7) on Windows, mirroring the existing #[cfg(unix)]/#[cfg(windows)] hook idiom in tests/exec_jsonl.rs.
  2. Poison resilience — recover from a poisoned test lock so a single failure is reported on its own merits instead of cascading across the suite.

Verification

  • cargo test --test subagent_contract → 12/12 pass on macOS (host).
  • The #[cfg(windows)] branch was compiled in isolation and produces Start-Sleep -Milliseconds 400.
  • Full cross-compile to x86_64-pc-windows-msvc is blocked locally by ring's C toolchain requirement (no Windows C headers on this Mac); the Windows CI gate on this PR is the authoritative check.

Summary by CodeRabbit

  • Bug Fixes
    • Improved test reliability by recovering from locking errors instead of failing immediately.
    • Updated generated hook commands to use platform-appropriate sleep syntax on Unix and Windows.

The `async_subagent_completes_after_launching_exec_process_exits` test
wrote a `pre_model_call` hook running `sleep 0.4`. On Windows the resolved
host shell is PowerShell, where `sleep` aliases `Start-Sleep`, and Windows
PowerShell 5.1 rejects the fractional `0.4` seconds argument (and cmd.exe
has no `sleep` at all). The hook therefore failed and `orca exec` exited
with code 1 instead of 0, panicking the test.

Because every test in this file shares a single static `Mutex`, that first
panic poisoned the lock and cascaded into all 12 tests failing with
`PoisonError`, masking the real cause on the Windows CI gate.

- Emit a platform-specific delay command: `sleep {seconds}` on Unix and
  `Start-Sleep -Milliseconds {ms}` (integer, valid on PowerShell 5.1 and 7)
  on Windows, mirroring the existing hook idiom in tests/exec_jsonl.rs.
- Recover from a poisoned test lock so a single failure is reported on its
  own merits instead of cascading across the whole suite.

Co-authored-by: TRAE CLI <noreply@bytedance.com>
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: eaaf4443-ec29-4b03-bc41-f1d8ae46cfe2

📥 Commits

Reviewing files that changed from the base of the PR and between d5a23be and c8fccec.

📒 Files selected for processing (1)
  • tests/subagent_contract.rs

📝 Walkthrough

Walkthrough

The test helpers now recover from poisoned mutex locks and generate operating-system-specific pre-model hook sleep commands for Unix and Windows.

Changes

Subagent contract test robustness

Layer / File(s) Summary
Poisoned lock recovery
tests/subagent_contract.rs
subagent_cli_test_guard recovers the inner mutex guard when the lock is poisoned instead of failing with expect.
Platform-specific sleep hook configuration
tests/subagent_contract.rs
write_sleep_hook_config generates Unix sleep commands and Windows PowerShell Start-Sleep commands in config.toml.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 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 matches the main change: making the subagent sleep hook portable on Windows.
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/windows-subagent-hook-flake

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.

@echoVic
echoVic merged commit ffee0ea into main Jul 30, 2026
1 of 3 checks passed
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