Skip to content

Commit f549eb6

Browse files
RoyLinRoyLin
authored andcommitted
feat(code): implement proper cancellation via CancellationToken
Replace AbortHandle with CancellationToken in SessionManager so that cancel_operation() cooperatively cancels the streaming LLM loop via tokio::select! instead of hard-aborting the task. - ongoing_operations now stores CancellationToken instead of AbortHandle - cancel_operation() calls token.cancel() for cooperative cancellation - execute_streaming() returns the CancellationToken alongside the handle - The streaming loop in call_llm uses tokio::select! to exit immediately when the token is cancelled
1 parent e2d0921 commit f549eb6

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

core/src/agent_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ impl AgentSession {
15691569

15701570
let agent_loop = self.build_agent_loop();
15711571
let result = agent_loop
1572-
.execute_from_messages(effective_history, None, None)
1572+
.execute_from_messages(effective_history, None, None, None)
15731573
.await?;
15741574

15751575
if use_internal {
@@ -1604,7 +1604,7 @@ impl AgentSession {
16041604
let agent_loop = self.build_agent_loop();
16051605
let handle = tokio::spawn(async move {
16061606
let _ = agent_loop
1607-
.execute_from_messages(effective_history, None, Some(tx))
1607+
.execute_from_messages(effective_history, None, Some(tx), None)
16081608
.await;
16091609
});
16101610

core/src/session/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ impl SessionManager {
721721

722722
// Execute with session context
723723
let result = agent
724-
.execute_with_session(&history, &effective_prompt, Some(session_id), None)
724+
.execute_with_session(&history, &effective_prompt, Some(session_id), None, None)
725725
.await?;
726726

727727
// Update session

0 commit comments

Comments
 (0)