huskies: merge 543_story_resume_failed_coder_agents_with_resume_instead_of_starting_fresh_sessions

This commit is contained in:
dave
2026-04-12 12:52:46 +00:00
parent c80931c15c
commit 5f01631e6a
16 changed files with 135 additions and 52 deletions
+22 -3
View File
@@ -49,6 +49,7 @@ pub(in crate::agents) async fn run_agent_pty_streaming(
inactivity_timeout_secs: u64,
child_killers: Arc<Mutex<HashMap<String, Box<dyn ChildKiller + Send + Sync>>>>,
watcher_tx: broadcast::Sender<WatcherEvent>,
session_id_to_resume: Option<&str>,
) -> Result<PtyResult, String> {
let sid = story_id.to_string();
let aname = agent_name.to_string();
@@ -58,6 +59,7 @@ pub(in crate::agents) async fn run_agent_pty_streaming(
let cwd = cwd.to_string();
let tx = tx.clone();
let event_log = event_log.clone();
let resume_sid = session_id_to_resume.map(str::to_string);
tokio::task::spawn_blocking(move || {
run_agent_pty_blocking(
@@ -73,6 +75,7 @@ pub(in crate::agents) async fn run_agent_pty_streaming(
inactivity_timeout_secs,
&child_killers,
&watcher_tx,
resume_sid.as_deref(),
)
})
.await
@@ -166,6 +169,7 @@ fn run_agent_pty_blocking(
inactivity_timeout_secs: u64,
child_killers: &Arc<Mutex<HashMap<String, Box<dyn ChildKiller + Send + Sync>>>>,
watcher_tx: &broadcast::Sender<WatcherEvent>,
session_id_to_resume: Option<&str>,
) -> Result<PtyResult, String> {
let pty_system = native_pty_system();
@@ -180,9 +184,21 @@ fn run_agent_pty_blocking(
let mut cmd = CommandBuilder::new(command);
// -p <prompt> must come first
cmd.arg("-p");
cmd.arg(prompt);
// Launch mode: resume an existing session or start fresh.
if let Some(sid) = session_id_to_resume {
// Resume: --resume <session_id> restores previous conversation context.
// Only the failure context (prompt) is sent as a new message via -p.
cmd.arg("--resume");
cmd.arg(sid);
if !prompt.is_empty() {
cmd.arg("-p");
cmd.arg(prompt);
}
} else {
// Fresh session: deliver the full rendered prompt via -p.
cmd.arg("-p");
cmd.arg(prompt);
}
// Add configured args (e.g., --directory /path/to/worktree, --model, etc.)
for arg in args {
@@ -541,6 +557,7 @@ mod tests {
0,
child_killers,
watcher_tx,
None,
)
.await;
@@ -594,6 +611,7 @@ mod tests {
0,
child_killers,
watcher_tx,
None,
)
.await;
@@ -655,6 +673,7 @@ mod tests {
0,
child_killers,
watcher_tx,
None,
)
.await;
let after = chrono::Utc::now();