huskies: merge 1006
This commit is contained in:
@@ -163,35 +163,56 @@ pub(super) async fn run_agent_spawn(
|
||||
let watcher_tx_clone = watcher_tx;
|
||||
let _ = inactivity_timeout_secs; // currently unused inside the closure body
|
||||
|
||||
// Step 1: create the worktree (slow — git checkout, pnpm install, etc.)
|
||||
let wt_info = match crate::worktree::create_worktree(
|
||||
&project_root_clone,
|
||||
&sid,
|
||||
&config_clone,
|
||||
port_for_task,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(wt) => wt,
|
||||
Err(e) => {
|
||||
let error_msg = format!("Failed to create worktree: {e}");
|
||||
slog_error!("[agents] {error_msg}");
|
||||
let event = AgentEvent::Error {
|
||||
story_id: sid.clone(),
|
||||
agent_name: aname.clone(),
|
||||
message: error_msg,
|
||||
};
|
||||
if let Ok(mut log) = log_clone.lock() {
|
||||
log.push(event.clone());
|
||||
// Step 1: wait for the worktree created by the worktree lifecycle subscriber.
|
||||
// The Coding transition fires before this task is spawned; the subscriber
|
||||
// creates the worktree asynchronously. Poll until it exists or the deadline.
|
||||
// Tests use a short deadline (1 s) so the failure path exercises quickly;
|
||||
// production uses 120 s to allow slow git operations to complete.
|
||||
#[cfg(not(test))]
|
||||
let worktree_wait_secs: u64 = 120;
|
||||
#[cfg(test)]
|
||||
let worktree_wait_secs: u64 = 1;
|
||||
let wt_info = {
|
||||
let wt_path = crate::worktree::worktree_path(&project_root_clone, &sid);
|
||||
let branch = format!("feature/story-{sid}");
|
||||
let base_branch = config_clone
|
||||
.base_branch
|
||||
.clone()
|
||||
.unwrap_or_else(|| crate::worktree::detect_base_branch(&project_root_clone));
|
||||
let deadline =
|
||||
tokio::time::Instant::now() + std::time::Duration::from_secs(worktree_wait_secs);
|
||||
loop {
|
||||
if wt_path.exists() {
|
||||
break crate::worktree::WorktreeInfo {
|
||||
path: wt_path,
|
||||
branch,
|
||||
base_branch,
|
||||
};
|
||||
}
|
||||
let _ = tx_clone.send(event);
|
||||
if let Ok(mut agents) = agents_ref.lock()
|
||||
&& let Some(agent) = agents.get_mut(&key_clone)
|
||||
{
|
||||
agent.status = AgentStatus::Failed;
|
||||
if tokio::time::Instant::now() >= deadline {
|
||||
let error_msg = format!(
|
||||
"Worktree for story '{sid}' did not appear within {worktree_wait_secs} s; \
|
||||
the lifecycle subscriber may have failed."
|
||||
);
|
||||
slog_error!("[agents] {error_msg}");
|
||||
let event = AgentEvent::Error {
|
||||
story_id: sid.clone(),
|
||||
agent_name: aname.clone(),
|
||||
message: error_msg,
|
||||
};
|
||||
if let Ok(mut log) = log_clone.lock() {
|
||||
log.push(event.clone());
|
||||
}
|
||||
let _ = tx_clone.send(event);
|
||||
if let Ok(mut agents) = agents_ref.lock()
|
||||
&& let Some(agent) = agents.get_mut(&key_clone)
|
||||
{
|
||||
agent.status = AgentStatus::Failed;
|
||||
}
|
||||
AgentPool::notify_agent_state_changed(&watcher_tx_clone);
|
||||
return;
|
||||
}
|
||||
AgentPool::notify_agent_state_changed(&watcher_tx_clone);
|
||||
return;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user