fix(cli-sub-agent): ScopedSessionSandbox uses tokio::sync::Mutex (#754)#960
Conversation
ScopedSessionSandbox previously held a std::sync::MutexGuard across .await points in #[tokio::test] call sites, violating AGENTS.md Rule 006 and risking Tokio executor stalls under load. Migrate TEST_ENV_LOCK to tokio::sync::Mutex and make ScopedSessionSandbox::new async. Async tests now acquire the lock via .await; sync tests use blocking helpers and the guard is released on Drop as before. Closes #754. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Local pre-PR cumulative review (csa review --range main...HEAD, tier-4-critical, session 01KPNS8SAHFKMVXPMM7685JDF2):
Targeted validation:
Merging per severity-tiered protocol: findings=[], zero P0/P1, codex explicit PASS. No production surface changed (test-only sandbox + call-site |
There was a problem hiding this comment.
Code Review
This pull request migrates the global test environment lock from a standard library Mutex to a tokio::sync::Mutex, enabling the lock to be safely held across await points in asynchronous tests. The ScopedSessionSandbox helper has been updated with both async and blocking constructors to support this transition, and a new test case verifies that the lock prevents deadlocks during yields. Consequently, numerous test files were updated to use the new locking mechanisms and sandbox initialization methods. The workspace version has also been bumped to 0.1.446. I have no feedback to provide as there were no review comments to evaluate.
Summary
ScopedSessionSandboxpreviously held astd::sync::MutexGuardacross.awaitpoints in#[tokio::test]call sites, violating AGENTS.md Rule 006 and risking Tokio executor stalls under load.TEST_ENV_LOCKtoArc<tokio::sync::Mutex<()>>. Async tests useScopedSessionSandbox::new(...).await; sync tests useScopedSessionSandbox::new_blocking(...). Guard is nowtokio::sync::OwnedMutexGuard<()>.sandbox_lock_can_span_await_without_deadlockingproving no deadlock across.awaitpoints.Closes #754.
Test plan
cargo test -p cli-sub-agent sandbox_lock_can_span_await_without_deadlockingcargo test -p cli-sub-agentcargo test --workspacejust clippyjust pre-commit🤖 Generated with Claude Code