From 978af45d5fc6493878513dfed80732d8a7ad3e1f Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 10 Mar 2026 18:37:45 +0000 Subject: [PATCH] fix: preserve step chat history when resuming after wait_for_approval Previously, current_step_chat_history was cleared unconditionally on resume, causing the agent to lose context and re-run the step from scratch after approval. Now only clear when advancing to a new step. --- src/agent.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/agent.rs b/src/agent.rs index b6bf3d7..9362f4d 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -473,13 +473,18 @@ async fn agent_loop( // Prepare state for execution: set first pending step to Running if let Some(next) = state.first_actionable_step() { + let was_same_step = matches!(state.phase, AgentPhase::Executing { step } if step == next); if let Some(step) = state.steps.iter_mut().find(|s| s.order == next) { if matches!(step.status, StepStatus::Pending) { step.status = StepStatus::Running; } } state.phase = AgentPhase::Executing { step: next }; - state.current_step_chat_history.clear(); + // Only clear chat history when advancing to a new step; + // keep it when resuming the same step after wait_for_approval + if !was_same_step { + state.current_step_chat_history.clear(); + } } let instructions = read_instructions(&workdir).await;