microsoft/autogen · warning · ValueError
Pip install was cancelled
Error message
Pip install was cancelled
What it means
Raised during LocalCommandLineCodeExecutor function setup when the pip install subprocess future/task is cancelled - either via the CancellationToken passed to execute_code_blocks (linked through cancellation_token.link_future) or by cancelling the surrounding task - and asyncio.CancelledError is caught and rewrapped as ValueError.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/local/__init__.py:309
py_executable = sys.executable
task = asyncio.create_task(
asyncio.create_subprocess_exec(
py_executable,
*cmd_args,
cwd=self.work_dir,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
)
cancellation_token.link_future(task)
try:
proc = await task
stdout, stderr = await asyncio.wait_for(proc.communicate(), self._timeout)
except asyncio.TimeoutError as e:
raise ValueError("Pip install timed out") from e
except asyncio.CancelledError as e:
raise ValueError("Pip install was cancelled") from e
if proc.returncode is not None and proc.returncode != 0:
raise ValueError(f"Pip install failed. {stdout.decode()}, {stderr.decode()}")
# Attempt to load the function file to check for syntax errors, imports etc.
exec_result = await self._execute_code_dont_check_setup(
[CodeBlock(code=func_file_content, language="python")], cancellation_token
)
if exec_result.exit_code != 0:
raise ValueError(f"Functions failed to load: {exec_result.output}")
self._setup_functions_complete = True
async def execute_code_blocks(
self, code_blocks: List[CodeBlock], cancellation_token: CancellationToken
) -> CommandLineCodeResult:
"""(Experimental) Execute the code blocks and return the result.View on GitHub (pinned to 027ecf0a37)
Solutions
- If cancellation was intentional, no fix is needed - treat it as a clean abort and handle the ValueError in the caller.
- Trigger setup earlier by calling execute_code_blocks with a trivial block before exposing cancellation controls to users.
- Raise the executor timeout so setup is not externally cancelled as 'stuck'.
Example fix
# before token = CancellationToken() task = asyncio.create_task(executor.execute_code_blocks(blocks, token)) token.cancel() # -> ValueError: Pip install was cancelled # after result = await executor.execute_code_blocks(blocks, CancellationToken()) # cancel only for genuine aborts; catch and treat as aborted: # except ValueError as e: ... if 'cancelled' in str(e): handle_abort()
Defensive patterns
Strategy: try-catch
Try / catch
try:
await executor.execute_code_blocks(blocks, token)
except ValueError as e:
if "Pip install was cancelled" in str(e):
return AbortedResult() # treat as a clean user abort
raise Prevention
- Trigger lazy setup early with a trivial code block before exposing cancel controls to users.
- Only cancel tokens for genuine aborts, not as a timeout mechanism during setup.
When it happens
Trigger: Cancelling the CancellationToken that was passed to execute_code_blocks while the deferred pip install of function dependencies is still running; shutting down the event loop or cancelling the surrounding task during the first code execution.
Common situations: User aborts or shuts down an agent session during the first code block (when lazy setup runs), orchestration layers with global timeouts that cancel in-flight tasks, tests cancelling tokens to simulate user aborts.
Related errors
- Pip install timed out
- Pip install failed. {stdout.decode()}, {stderr.decode()}
- The team is already running, it cannot run again until it is
- The group chat is currently running. It must be stopped befo
- The team cannot be loaded while it is running.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/8fe6f0c67d832d05.
Report an issue: GitHub.