Skip to content

Commit 4f794ad

Browse files
fix: improve cancellation support for force cancel (#2)
Add cancellation check after provider.complete() returns, before processing the response. This allows force cancel to take effect immediately after the provider call completes. Root cause: No cancellation checks during blocking provider calls meant force cancel (double Ctrl+C) wasn't working during initial LLM request. Verified: Shadow smoke test passed 100/100 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-authored-by: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
1 parent 9b14e80 commit 4f794ad

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

amplifier_module_loop_basic/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ async def execute(
236236
if self.extended_thinking:
237237
kwargs["extended_thinking"] = True
238238
response = await provider.complete(chat_request, **kwargs)
239+
240+
# Check for immediate cancellation after provider returns
241+
# This allows force-cancel to take effect as soon as the blocking
242+
# provider call completes, before processing the response
243+
if coordinator and coordinator.cancellation.is_immediate:
244+
# Emit cancelled status and exit
245+
await hooks.emit(
246+
ORCHESTRATOR_COMPLETE,
247+
{
248+
"orchestrator": "loop-basic",
249+
"turn_count": iteration,
250+
"status": "cancelled",
251+
},
252+
)
253+
return final_content
239254
else:
240255
raise RuntimeError(f"Provider {provider_name} missing 'complete'")
241256

0 commit comments

Comments
 (0)