From 41adf7ead9c1fe7bd2fa57357aa816672ff0ef72 Mon Sep 17 00:00:00 2001 From: LHaghfoss Date: Wed, 25 Nov 2026 23:43:37 +0100 Subject: [PATCH 1/3] feat(engine): retry a failed, timed-out or stopped workflow run --- apps/desktop/src/acp/mock.ts | 4 + apps/desktop/src/acp/workflows.ts | 1 + apps/desktop/src/state/workflows.test.ts | 40 ++++ apps/desktop/src/state/workflows.ts | 38 ++++ apps/desktop/src/ui/WorkflowRuns.tsx | 27 +++ docs/workflows.md | 10 + .../engine/src/acp/dispatch_table_tests.rs | 6 + rustcode/engine/src/acp/extension_dispatch.rs | 15 ++ rustcode/engine/src/acp/workflows.rs | 25 +++ rustcode/engine/src/workflow.rs | 207 +++++++++++++++++- 10 files changed, 372 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/acp/mock.ts b/apps/desktop/src/acp/mock.ts index bfc31dbf2..f115e2fb7 100644 --- a/apps/desktop/src/acp/mock.ts +++ b/apps/desktop/src/acp/mock.ts @@ -1391,6 +1391,10 @@ export class MockEngine { return { run: { run_id: str(obj(params)?.runId) ?? "", status: "running", driven: true }, }; + case "_rustcode/workflows/retry": + return { + run: { run_id: str(obj(params)?.runId) ?? "", status: "running", driven: true }, + }; case "_rustcode/workflows/stop": // The mock has no runs of its own: a staged run (state/workflows.ts) is simply stopped. return { diff --git a/apps/desktop/src/acp/workflows.ts b/apps/desktop/src/acp/workflows.ts index 9922940f3..1a132bed7 100644 --- a/apps/desktop/src/acp/workflows.ts +++ b/apps/desktop/src/acp/workflows.ts @@ -9,6 +9,7 @@ export const WorkflowMethod = { list: "_rustcode/workflows/list", stop: "_rustcode/workflows/stop", resume: "_rustcode/workflows/resume", + retry: "_rustcode/workflows/retry", wake: "_rustcode/workflows/wake", changed: "_rustcode/workflows/changed", } as const; diff --git a/apps/desktop/src/state/workflows.test.ts b/apps/desktop/src/state/workflows.test.ts index 5af50c70b..0effcc3ec 100644 --- a/apps/desktop/src/state/workflows.test.ts +++ b/apps/desktop/src/state/workflows.test.ts @@ -5,6 +5,7 @@ import { resetForTests, useApp, watchMachineConnection } from "./store"; import { emptyThread, isContinueMessage, WORKFLOW_MARK, wakeLine } from "./thread"; import { runIdOf } from "./toolNames"; import { + canRetry, currentPhase, elapsedMs, endNotice, @@ -15,6 +16,7 @@ import { progressText, resetWorkflows, resumeWorkflow, + retryWorkflow, runLine, runTitle, shouldWake, @@ -327,3 +329,41 @@ test("Resume targets the owning machine and keeps the saved progress", async () expect(useWorkflows.getState().runs[key]?.[0]?.workers).toHaveLength(3); conn.close("test finished"); }); + +test("Retry continues a failed run on its machine and only a run that ended unfinished offers it", async () => { + expect(canRetry({ ...run(), status: "failed" })).toBe(true); + expect(canRetry({ ...run(), status: "timed_out" })).toBe(true); + expect(canRetry({ ...run(), status: "cancelled" })).toBe(true); + expect(canRetry({ ...run(), status: "done" })).toBe(false); + expect(canRetry(run())).toBe(false); + + const { conn, calls } = engine( + (method): JsonObject => + method === WorkflowMethod.retry + ? { run: { run_id: "wf-1-aaaaaaaa", status: "running", driven: true } } + : {}, + ); + watchMachineConnection("machine", conn); + const key = "machine/t1"; + upsertRun(key, { ...run(), status: "failed", error: "a worker failed", finishedAt: 5 }); + await retryWorkflow(key, "wf-1-aaaaaaaa"); + expect(calls.find((c) => c.method === WorkflowMethod.retry)?.params).toEqual({ + sessionId: "t1", + runId: "wf-1-aaaaaaaa", + }); + const retried = useWorkflows.getState().runs[key]?.[0]; + expect(retried?.status).toBe("running"); + expect(retried?.error).toBeUndefined(); + expect(retried?.workers).toHaveLength(3); + conn.close("test finished"); + + const refused = engine(() => ({ + error: { code: "failed", message: "run wf-1-aaaaaaaa finished; there is nothing to retry" }, + })); + watchMachineConnection("other", refused.conn); + upsertRun("other/t1", { ...run(), status: "done" }); + await retryWorkflow("other/t1", "wf-1-aaaaaaaa"); + expect(useWorkflows.getState().runs["other/t1"]?.[0]?.status).toBe("done"); + expect(useApp.getState().toasts.some((t) => t.text.includes("Could not retry the workflow"))).toBe(true); + refused.conn.close("test finished"); +}); diff --git a/apps/desktop/src/state/workflows.ts b/apps/desktop/src/state/workflows.ts index 1b3be548b..1783ca0ba 100644 --- a/apps/desktop/src/state/workflows.ts +++ b/apps/desktop/src/state/workflows.ts @@ -259,6 +259,44 @@ export async function stopWorkflow(key: string, runId: string): Promise { } } +/** Whether a run ended without finishing, so Retry can continue it from its finished calls (issue 4383). */ +export function canRetry(run: WorkflowRun): boolean { + return run.status === "failed" || run.status === "timed_out" || run.status === "cancelled"; +} + +/** + * Retry a failed, timed-out or stopped run on the machine that owns it: the engine answers its finished + * calls from the run and starts workers only for the failed or missing ones. + */ +export async function retryWorkflow(key: string, runId: string): Promise { + try { + const { host, id } = splitThreadKey(key); + const conn = connectionFor(host); + if (!conn) throw new Error("That machine is not connected."); + const answer = obj(await conn.request(WorkflowMethod.retry, { sessionId: id, runId }, 30_000)); + const error = obj(answer?.error); + if (error) throw new Error(str(error.message) ?? "The engine rejected the request."); + const run = parseWorkflowRun(answer?.run); + if (!run) throw new Error("The engine did not return the workflow."); + const known = useWorkflows.getState().runs[key]?.find((candidate) => candidate.id === runId); + upsertRun( + key, + known && !run.workers.length + ? { + ...known, + status: run.status, + error: run.error, + finishedAt: run.finishedAt, + driven: run.driven, + woken: run.woken, + } + : run, + ); + } catch (error) { + toast(`Could not retry the workflow: ${errorText(error)}`, "error"); + } +} + /** Resume one saved run on the machine that owns it. */ export async function resumeWorkflow(key: string, runId: string): Promise { try { diff --git a/apps/desktop/src/ui/WorkflowRuns.tsx b/apps/desktop/src/ui/WorkflowRuns.tsx index e008ebc6d..8b3a19251 100644 --- a/apps/desktop/src/ui/WorkflowRuns.tsx +++ b/apps/desktop/src/ui/WorkflowRuns.tsx @@ -12,12 +12,14 @@ import { selectThread } from "../state/store"; import { formatDuration } from "../state/thread"; import { splitThreadKey } from "../state/threadKeys"; import { + canRetry, elapsedMs, isLive, type PhaseStepState, phaseSteps, progressText, resumeWorkflow, + retryWorkflow, runLine, runTitle, statusWord, @@ -154,6 +156,30 @@ function ResumeButton({ run, threadId }: { run: WorkflowRun; threadId: string }) ); } +function RetryButton({ run, threadId }: { run: WorkflowRun; threadId: string }) { + const [pending, setPending] = useState(false); + return ( + + + + ); +} + function StopButton({ run, threadId }: { run: WorkflowRun; threadId: string }) { const stopping = useWorkflows((s) => s.stopping[run.id] === true); return ( @@ -256,6 +282,7 @@ export function WorkflowCard({ threadId, runId }: { threadId: string; runId: str {formatDuration(elapsedMs(run, now))} {live && !run.driven && } {live && } + {canRetry(run) && }
diff --git a/docs/workflows.md b/docs/workflows.md index 2874281ff..5e8e275dc 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -140,6 +140,16 @@ they **nest under it**, count against its delegate slots (`delegates-per-thread` the agent starts by hand. When every slot is taken, the run waits and tries again rather than failing. +**Retrying a run.** A run that ended `failed`, `timed_out` or `cancelled` can +be retried (#4383): `run_workflow` with `retry_run_id` (and no `script`, `name` +or `args`), or **Retry** on the run's card in the app +(`_rustcode/workflows/retry`). The run goes back to `running` under the same id +with its saved script; its finished calls are answered from `calls.jsonl` with +no thread started and no budget spent, and only failed or missing calls start +workers. `concurrency`, `call_budget` and `timeout_minutes` may lower its +limits, the timeout counts from the retry, and the thread is told once when it +ends. A `done` or still `running` run is refused. + ## Durability Everything is under the starting thread's folder, diff --git a/rustcode/engine/src/acp/dispatch_table_tests.rs b/rustcode/engine/src/acp/dispatch_table_tests.rs index 95e425e21..fd0fe3e10 100644 --- a/rustcode/engine/src/acp/dispatch_table_tests.rs +++ b/rustcode/engine/src/acp/dispatch_table_tests.rs @@ -599,6 +599,12 @@ fn every_dispatched_method_matches_its_request_type() { ), "method mismatch for workflows::WorkflowResumeRequest" ); + assert!( + ::matches_method( + "_rustcode/workflows/retry" + ), + "method mismatch for workflows::WorkflowRetryRequest" + ); assert!( ::matches_method( "_rustcode/workflows/wake" diff --git a/rustcode/engine/src/acp/extension_dispatch.rs b/rustcode/engine/src/acp/extension_dispatch.rs index f46fc1d80..230eb70b4 100644 --- a/rustcode/engine/src/acp/extension_dispatch.rs +++ b/rustcode/engine/src/acp/extension_dispatch.rs @@ -1890,6 +1890,21 @@ pub(super) async fn dispatch_request( responder.respond(workflows::resume(request, host)) } + "_rustcode/workflows/retry" => { + let request: workflows::WorkflowRetryRequest = parse_params(params)?; + let asker = server.clients.info(client_id).orchestration; + let host = (asker >= 2) + .then(|| { + super::preview::orchestration_client_for( + true, + &server.clients.session(&request.session_id), + ) + }) + .flatten() + .map(|client| (client, asker)); + + responder.respond(workflows::retry(request, host)) + } "_rustcode/workflows/wake" => { let request: workflows::WorkflowWakeRequest = parse_params(params)?; diff --git a/rustcode/engine/src/acp/workflows.rs b/rustcode/engine/src/acp/workflows.rs index fd6381b79..2a80e70e5 100644 --- a/rustcode/engine/src/acp/workflows.rs +++ b/rustcode/engine/src/acp/workflows.rs @@ -69,6 +69,31 @@ pub(crate) fn resume( } } +/// Retry one failed, timed-out or stopped run from its finished calls (#4383). +#[derive( + Debug, Clone, serde::Serialize, serde::Deserialize, agent_client_protocol::JsonRpcRequest, +)] +#[request(method = "_rustcode/workflows/retry", response = serde_json::Value)] +#[serde(rename_all = "camelCase")] +pub(crate) struct WorkflowRetryRequest { + pub session_id: String, + pub run_id: String, +} + +pub(crate) fn retry( + request: WorkflowRetryRequest, + host: Option<(Arc, u8)>, +) -> Value { + let (client, version) = match host { + Some((client, version)) => (Some(client), version), + None => (None, 0), + }; + match crate::workflow::retry_run(&request.session_id, &request.run_id, client, version) { + Ok(run) => json!({ "run": run }), + Err(message) => json!({ "error": { "code": "failed", "message": message } }), + } +} + /// `_rustcode/workflows/wake`: claim the wake of an ended run. Answers /// `{claimed}`: true once, for the client that should tell the thread. #[derive( diff --git a/rustcode/engine/src/workflow.rs b/rustcode/engine/src/workflow.rs index 2cd063d45..462961f80 100644 --- a/rustcode/engine/src/workflow.rs +++ b/rustcode/engine/src/workflow.rs @@ -138,7 +138,8 @@ pub(crate) fn run_schema() -> Value { "args": {"description": "Any JSON; the script reads it as the global `args`"}, "concurrency": {"type": "integer", "minimum": 1, "maximum": MAX_CONCURRENCY, "description": "How many workers may run at once; the user's setting is the most"}, "call_budget": {"type": "integer", "minimum": 1, "maximum": MAX_CALL_BUDGET, "description": "How many agent() calls the run may make in all; the user's setting is the most"}, - "timeout_minutes": {"type": "integer", "minimum": 1, "maximum": MAX_TIMEOUT_MINUTES, "description": "How long the run may take; the user's setting is the most"} + "timeout_minutes": {"type": "integer", "minimum": 1, "maximum": MAX_TIMEOUT_MINUTES, "description": "How long the run may take; the user's setting is the most"}, + "retry_run_id": {"type": "string", "minLength": 1, "maxLength": 64, "description": "Retry this thread's failed, timed-out or stopped run instead of starting one: finished calls are answered from the run, only failed or missing calls start workers. Give this instead of script or name"} }, "additionalProperties": false }) @@ -176,6 +177,7 @@ pub(crate) fn validate(tool: &str, args: &Value) -> Result<(), String> { "concurrency", "call_budget", "timeout_minutes", + "retry_run_id", ], STATUS_TOOL_NAME => &["run_id", "wait_ms"], STOP_TOOL_NAME => &["run_id"], @@ -218,6 +220,18 @@ pub(crate) fn validate(tool: &str, args: &Value) -> Result<(), String> { Some(Value::String(text)) if !text.trim().is_empty() => Ok(Some(text.as_str())), Some(_) => Err(format!("{key} must be a non-empty string")), }; + if let Some(retry) = map.get("retry_run_id").filter(|value| !value.is_null()) { + if text("script")?.is_some() || text("name")?.is_some() || map.contains_key("args") { + return Err( + "retry_run_id retries a run as it was started: give no script, name or args" + .to_owned(), + ); + } + return match retry { + Value::String(id) if store::valid_run_id(id) => Ok(()), + _ => Err("retry_run_id must be a run id from run_workflow or workflow_status".to_owned()), + }; + } match (text("script")?, text("name")?) { (Some(_), Some(_)) => Err("give a script or a name, not both".to_owned()), (None, None) => Err("give a script, or the name of one in .rustcode/workflows/".to_owned()), @@ -472,6 +486,22 @@ pub(crate) fn start( args: &Value, ) -> Result { validate(RUN_TOOL_NAME, args)?; + if let Some(run_id) = args.get("retry_run_id").and_then(Value::as_str) { + let store = Store::for_thread(thread) + .ok_or_else(|| "this thread has no folder that keeps runs".to_owned())?; + let run = retry_in(&store, run_id, runner, args)?; + announce(thread, run_id); + let mut answer = json!({ + "run_id": run_id, + "status": "running", + "retried": true, + "note": "Finished calls are answered from the run; failed or missing calls start workers again. Read it with workflow_status, stop it with stop_workflow." + }); + if let Some(limits) = run.get("limits") { + answer["limits"] = limits.clone(); + } + return Ok(answer.to_string()); + } let (name, source) = match args.get("name").and_then(Value::as_str) { Some(name) => (Some(name.to_owned()), named_script(thread, name)?), None => ( @@ -585,6 +615,75 @@ fn resume_run_in( .ok_or_else(|| format!("no run {run_id} in this thread")) } +/// Retry `run_id` for a client that asked (the app's Retry button), with its +/// workers routed like [`resume_run`]'s. +pub(crate) fn retry_run( + thread: &str, + run_id: &str, + client: Option>, + version: u8, +) -> Result { + validate(STOP_TOOL_NAME, &json!({ "run_id": run_id }))?; + let store = Store::for_thread(thread) + .ok_or_else(|| "this thread has no folder that keeps runs".to_owned())?; + let version = resume_version(client.is_some(), version); + let run = retry_in( + &store, + run_id, + ThreadRunner::new(thread, client, version), + &Value::Null, + )?; + announce(thread, run_id); + Ok(run) +} + +/// Put a settled run that did not finish back to `running` and drive it again +/// from its saved script (#4383). Its finished calls are answered from +/// `calls.jsonl` and failed ones run anew, as on a resume; `args` may lower its +/// limits like a start. The run's summary. +fn retry_in( + store: &Store, + run_id: &str, + runner: Arc, + args: &Value, +) -> Result { + { + let _transition = DRIVER_TRANSITION + .lock() + .unwrap_or_else(|error| error.into_inner()); + let mut record = store + .load(run_id) + .ok_or_else(|| format!("no run {run_id} in this thread"))?; + match record.status { + RunStatus::Running => { + return Err(format!( + "run {run_id} is still running; resume it instead of retrying" + )); + } + RunStatus::Done => { + return Err(format!("run {run_id} finished; there is nothing to retry")); + } + RunStatus::Failed | RunStatus::TimedOut | RunStatus::Cancelled => {} + } + if store.script(run_id).is_none() { + return Err(format!("no saved script for run {run_id}")); + } + record.status = RunStatus::Running; + record.error = None; + record.result = None; + record.finished_at = None; + record.woken = false; + record.limits = lowered(record.limits, args); + record.updated_at = now_ms(); + store.save(&record)?; + } + resume_one(store, run_id, runner)?; + store + .load(run_id) + .map(|record| summary(store, &record)) + .ok_or_else(|| format!("no run {run_id} in this thread")) +} + fn resume_one(store: &Store, run_id: &str, runner: Arc) -> Result { let _transition = DRIVER_TRANSITION .lock() @@ -1270,6 +1369,112 @@ mod tests { assert_eq!(echo.started.load(Ordering::SeqCst), 0); } + fn finished_call(prompt: &str, result: Value) -> store::CallRecord { + store::CallRecord { + key: format!("{}#0", run::call_hash(prompt, &json!({}))), + seq: 0, + phase: None, + prompt: prompt.to_owned(), + harness: None, + model: None, + state: CallState::Done, + attempt: 0, + session_id: Some("old-session".to_owned()), + link_id: Some("old-link".to_owned()), + started_at: 1, + finished_at: Some(2), + result: Some(result), + error: None, + } + } + + #[tokio::test] + async fn a_retry_answers_finished_calls_from_the_run_and_starts_only_the_failed_ones() { + let dir = tempfile::tempdir().unwrap(); + let store = Store::at(dir.path().join("workflows")); + let (echo, runner) = echo(); + let mut record = new_record( + "1784626803679", + None, + Value::Null, + Limits { + concurrency: 2, + call_budget: 2, + timeout_secs: 30, + }, + ); + record.status = RunStatus::Failed; + record.error = Some("the worker thread s-2 ended as failed".to_owned()); + record.finished_at = Some(3); + record.woken = true; + store + .create(&record, r#"return [await agent("one"), await agent("two")];"#) + .unwrap(); + store + .append_call(&record.id, &finished_call("one", json!("cached answer"))) + .unwrap(); + + let summary = retry_in(&store, &record.id, runner, &json!({"concurrency": 1})).unwrap(); + assert_eq!(summary["status"], json!("running")); + let finished = settled(&store, &record.id).await; + assert_eq!(finished.status, RunStatus::Done, "{:?}", finished.error); + assert_eq!( + finished.result, + Some(json!(["cached answer", "done by session-1"])) + ); + assert_eq!(echo.started.load(Ordering::SeqCst), 1); + assert_eq!(finished.limits.concurrency, 1); + assert_eq!(finished.resumes, 1); + assert!(!finished.woken); + } + + #[tokio::test] + async fn only_a_run_that_ended_without_finishing_can_be_retried() { + let dir = tempfile::tempdir().unwrap(); + let store = Store::at(dir.path().join("workflows")); + let (echo, runner) = echo(); + let limits = Limits { + concurrency: 1, + call_budget: 5, + timeout_secs: 30, + }; + let running = new_record("1784626803679", None, Value::Null, limits); + store.create(&running, "return 1;").unwrap(); + let mut done = new_record("1784626803679", None, Value::Null, limits); + done.status = RunStatus::Done; + store.create(&done, "return 1;").unwrap(); + + let refused = retry_in(&store, &running.id, runner.clone(), &Value::Null).unwrap_err(); + assert!(refused.contains("still running"), "{refused}"); + let refused = retry_in(&store, &done.id, runner.clone(), &Value::Null).unwrap_err(); + assert!(refused.contains("nothing to retry"), "{refused}"); + let refused = retry_in(&store, "wf-0-00000000", runner, &Value::Null).unwrap_err(); + assert!(refused.contains("no run"), "{refused}"); + assert_eq!(echo.started.load(Ordering::SeqCst), 0); + assert_eq!(store.load(&done.id).unwrap().status, RunStatus::Done); + } + + #[test] + fn a_retry_takes_a_run_id_and_nothing_that_would_change_the_script() { + assert!(validate(RUN_TOOL_NAME, &json!({"retry_run_id": "wf-1-2"})).is_ok()); + assert!( + validate( + RUN_TOOL_NAME, + &json!({"retry_run_id": "wf-1-2", "timeout_minutes": 5}) + ) + .is_ok() + ); + for bad in [ + json!({"retry_run_id": "wf-1-2", "script": "return 1;"}), + json!({"retry_run_id": "wf-1-2", "name": "review"}), + json!({"retry_run_id": "wf-1-2", "args": {}}), + json!({"retry_run_id": "../x"}), + json!({"retry_run_id": 3}), + ] { + assert!(validate(RUN_TOOL_NAME, &bad).is_err(), "{bad}"); + } + } + #[tokio::test] async fn status_waits_for_a_run_to_end_and_answers_at_the_deadline_otherwise() { let dir = tempfile::tempdir().unwrap(); From 8d6ad5ab88109bb32c700644703fccd236a9e4eb Mon Sep 17 00:00:00 2001 From: LHaghfoss Date: Wed, 25 Nov 2026 23:44:12 +0100 Subject: [PATCH 2/3] style(engine): format the workflow retry --- rustcode/engine/src/workflow.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rustcode/engine/src/workflow.rs b/rustcode/engine/src/workflow.rs index 462961f80..3fdb5dbb6 100644 --- a/rustcode/engine/src/workflow.rs +++ b/rustcode/engine/src/workflow.rs @@ -229,7 +229,9 @@ pub(crate) fn validate(tool: &str, args: &Value) -> Result<(), String> { } return match retry { Value::String(id) if store::valid_run_id(id) => Ok(()), - _ => Err("retry_run_id must be a run id from run_workflow or workflow_status".to_owned()), + _ => { + Err("retry_run_id must be a run id from run_workflow or workflow_status".to_owned()) + } }; } match (text("script")?, text("name")?) { @@ -1408,7 +1410,10 @@ mod tests { record.finished_at = Some(3); record.woken = true; store - .create(&record, r#"return [await agent("one"), await agent("two")];"#) + .create( + &record, + r#"return [await agent("one"), await agent("two")];"#, + ) .unwrap(); store .append_call(&record.id, &finished_call("one", json!("cached answer"))) From 251983f075b81811f3ccb23bff817f99586e9b42 Mon Sep 17 00:00:00 2001 From: LHaghfoss Date: Wed, 25 Nov 2026 23:56:20 +0100 Subject: [PATCH 3/3] refactor(engine): share the workflow resume and retry host lookup --- rustcode/engine/src/acp/extension_dispatch.rs | 24 ++----------------- rustcode/engine/src/acp/workflows.rs | 14 +++++++++++ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/rustcode/engine/src/acp/extension_dispatch.rs b/rustcode/engine/src/acp/extension_dispatch.rs index 4fd4e8475..06591243c 100644 --- a/rustcode/engine/src/acp/extension_dispatch.rs +++ b/rustcode/engine/src/acp/extension_dispatch.rs @@ -1885,32 +1885,12 @@ pub(super) async fn dispatch_request( } "_rustcode/workflows/resume" => { let request: workflows::WorkflowResumeRequest = parse_params(params)?; - let asker = server.clients.info(client_id).orchestration; - let host = (asker >= 2) - .then(|| { - super::preview::orchestration_client_for( - true, - &server.clients.session(&request.session_id), - ) - }) - .flatten() - .map(|client| (client, asker)); - + let host = workflows::host(&server.clients, client_id, &request.session_id); responder.respond(workflows::resume(request, host)) } "_rustcode/workflows/retry" => { let request: workflows::WorkflowRetryRequest = parse_params(params)?; - let asker = server.clients.info(client_id).orchestration; - let host = (asker >= 2) - .then(|| { - super::preview::orchestration_client_for( - true, - &server.clients.session(&request.session_id), - ) - }) - .flatten() - .map(|client| (client, asker)); - + let host = workflows::host(&server.clients, client_id, &request.session_id); responder.respond(workflows::retry(request, host)) } "_rustcode/workflows/wake" => { diff --git a/rustcode/engine/src/acp/workflows.rs b/rustcode/engine/src/acp/workflows.rs index 2a80e70e5..88977c775 100644 --- a/rustcode/engine/src/acp/workflows.rs +++ b/rustcode/engine/src/acp/workflows.rs @@ -69,6 +69,20 @@ pub(crate) fn resume( } } +/// The orchestration host a resume or retry asked by `client_id` starts its +/// workers through: that client's, when it advertised orchestration v2 or up. +pub(crate) fn host( + clients: &Clients, + client_id: super::clients::ClientId, + session_id: &str, +) -> Option<(Arc, u8)> { + let asker = clients.info(client_id).orchestration; + (asker >= 2) + .then(|| super::preview::orchestration_client_for(true, &clients.session(session_id))) + .flatten() + .map(|client| (client, asker)) +} + /// Retry one failed, timed-out or stopped run from its finished calls (#4383). #[derive( Debug, Clone, serde::Serialize, serde::Deserialize, agent_client_protocol::JsonRpcRequest,