From a5720f9fa3694d43298a9d56a06836aa878b1665 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Fri, 9 Oct 2026 16:25:11 +0200 Subject: [PATCH] refactor(git): the retry wait and the clone limit share one off-the-runtime wrapper Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- compliance-agent/src/pipeline/clone_limit.rs | 2 +- compliance-agent/src/pipeline/git_retry.rs | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/compliance-agent/src/pipeline/clone_limit.rs b/compliance-agent/src/pipeline/clone_limit.rs index 263402a..9f9c201 100644 --- a/compliance-agent/src/pipeline/clone_limit.rs +++ b/compliance-agent/src/pipeline/clone_limit.rs @@ -87,7 +87,7 @@ impl Drop for HostPermit { /// Run blocking `work` without stalling the async runtime: on a multi-thread /// runtime's worker, `block_in_place` moves the worker's other tasks first. -fn off_the_runtime(work: impl FnOnce() -> R) -> R { +pub(crate) fn off_the_runtime(work: impl FnOnce() -> R) -> R { let on_multi_thread_runtime = tokio::runtime::Handle::try_current() .is_ok_and(|h| h.runtime_flavor() == tokio::runtime::RuntimeFlavor::MultiThread); if on_multi_thread_runtime { diff --git a/compliance-agent/src/pipeline/git_retry.rs b/compliance-agent/src/pipeline/git_retry.rs index c5a23b2..81472a6 100644 --- a/compliance-agent/src/pipeline/git_retry.rs +++ b/compliance-agent/src/pipeline/git_retry.rs @@ -108,19 +108,11 @@ pub fn is_transient(error: &git2::Error) -> bool { } } -/// Wait `duration` on this thread. Clones run on the async runtime's worker -/// threads; `block_in_place` hands this worker's other tasks to another -/// worker first, so a waiting retry does not stall them. +/// Wait `duration` on this thread, without stalling the async runtime's +/// other tasks (clones run on its worker threads). fn sleep(duration: Duration) { - if duration.is_zero() { - return; - } - let on_multi_thread_runtime = tokio::runtime::Handle::try_current() - .is_ok_and(|h| h.runtime_flavor() == tokio::runtime::RuntimeFlavor::MultiThread); - if on_multi_thread_runtime { - tokio::task::block_in_place(|| std::thread::sleep(duration)); - } else { - std::thread::sleep(duration); + if !duration.is_zero() { + crate::pipeline::clone_limit::off_the_runtime(|| std::thread::sleep(duration)); } }