Hydrate previous model across resume/fork/rollback/task start (#11497)

- Replace pending resume model state with persistent previous_model and
hydrate it on resume, fork, rollback, and task end in spawn_task
This commit is contained in:
Ahmed Ibrahim
2026-02-11 16:45:18 -08:00
committed by GitHub
parent 23444a063b
commit bb5dfd037a
3 changed files with 139 additions and 20 deletions

View File

@@ -140,6 +140,7 @@ impl Session {
tokio::spawn(
async move {
let ctx_for_finish = Arc::clone(&ctx);
let model_slug = ctx_for_finish.model_info.slug.clone();
let last_agent_message = task_for_run
.run(
Arc::clone(&session_ctx),
@@ -155,6 +156,11 @@ impl Session {
sess.on_task_finished(ctx_for_finish, last_agent_message)
.await;
}
// Set previous model regardless of completion or interruption for model-switch handling.
session_ctx
.clone_session()
.set_previous_model(Some(model_slug))
.await;
done_clone.notify_waiters();
}
.instrument(session_span),
@@ -267,6 +273,10 @@ impl Session {
task.handle.abort();
// Set previous model even when interrupted so model-switch handling stays correct.
self.set_previous_model(Some(task.turn_context.model_info.slug.clone()))
.await;
let session_ctx = Arc::new(SessionTaskContext::new(Arc::clone(self)));
session_task
.abort(session_ctx, Arc::clone(&task.turn_context))