Skip to content

Commit 185e515

Browse files
nikomatsakisClaude
andcommitted
Use spawn_blocking for binary download in resolve_distribution
Extract spawn_blocking logic into async download_and_cache_binary wrapper that calls the sync download_and_cache_binary_sync implementation. This keeps the call site clean while properly handling blocking I/O. Co-authored-by: Claude <claude@anthropic.com>
1 parent 82bf6a1 commit 185e515

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/symposium-acp-agent/src/registry.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub async fn resolve_agent(agent_id: &str) -> Result<McpServer> {
266266
// Check built-ins first
267267
for agent in built_in_agents()? {
268268
if agent.id == agent_id {
269-
return resolve_distribution(&agent);
269+
return resolve_distribution(&agent).await;
270270
}
271271
}
272272

@@ -278,11 +278,11 @@ pub async fn resolve_agent(agent_id: &str) -> Result<McpServer> {
278278
.find(|a| a.id == agent_id)
279279
.with_context(|| format!("Agent '{}' not found in registry", agent_id))?;
280280

281-
resolve_distribution(&entry)
281+
resolve_distribution(&entry).await
282282
}
283283

284284
/// Resolve a registry entry's distribution to an McpServer
285-
fn resolve_distribution(entry: &RegistryEntry) -> Result<McpServer> {
285+
async fn resolve_distribution(entry: &RegistryEntry) -> Result<McpServer> {
286286
let dist = &entry.distribution;
287287

288288
// Priority: local > npx > pipx > binary
@@ -339,8 +339,7 @@ fn resolve_distribution(entry: &RegistryEntry) -> Result<McpServer> {
339339

340340
// Check if we need to download
341341
if !executable_path.exists() {
342-
// For now, we'll do blocking download. Could make this async in future.
343-
download_and_cache_binary(&entry.id, version, binary, &cache_dir)?;
342+
download_and_cache_binary(&entry.id, version, binary, &cache_dir).await?;
344343
}
345344

346345
return Ok(McpServer::Stdio(
@@ -357,7 +356,25 @@ fn resolve_distribution(entry: &RegistryEntry) -> Result<McpServer> {
357356
}
358357

359358
/// Download and cache a binary distribution
360-
fn download_and_cache_binary(
359+
async fn download_and_cache_binary(
360+
agent_id: &str,
361+
version: &str,
362+
binary: &BinaryDistribution,
363+
cache_dir: &PathBuf,
364+
) -> Result<()> {
365+
let agent_id = agent_id.to_string();
366+
let version = version.to_string();
367+
let binary = binary.clone();
368+
let cache_dir = cache_dir.clone();
369+
tokio::task::spawn_blocking(move || {
370+
download_and_cache_binary_sync(&agent_id, &version, &binary, &cache_dir)
371+
})
372+
.await
373+
.context("Download task panicked")?
374+
}
375+
376+
/// Download and cache a binary distribution (blocking implementation)
377+
fn download_and_cache_binary_sync(
361378
agent_id: &str,
362379
version: &str,
363380
binary: &BinaryDistribution,

0 commit comments

Comments
 (0)