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.
This commit is contained in:
Fam Zheng
2026-03-10 18:37:45 +00:00
parent 5188027d8b
commit 978af45d5f

View File

@@ -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;