microsoft/autogen · error · ConnectionError
{logs_all}
Error message
{logs_all} What it means
This is the aggregated `logs_all` string raised as ConnectionError when sending a code block to the Azure session endpoint fails with an HTTP error status inside execute_code_blocks. The message contains all accumulated stdout/stderr so far plus the trailing line 'Error while sending code block to endpoint'. Sibling branches raise TimeoutError(logs_all) on timeout and CancelledError(logs_all) on cancellation.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py:492
data = data["properties"]
logs_all += data.get("stderr", "") + data.get("stdout", "")
if "Success" in data["status"]:
if not self._suppress_result_output:
logs_all += str(data["result"])
elif "Failure" in data["status"]:
exitcode = 1
except asyncio.TimeoutError as e:
logs_all += "\n Timeout"
# e.add_note is only in py 3.11+
raise asyncio.TimeoutError(logs_all) from e
except asyncio.CancelledError as e:
logs_all += "\n Cancelled"
# e.add_note is only in py 3.11+
raise asyncio.CancelledError(logs_all) from e
except aiohttp.ClientResponseError as e:
logs_all += "\nError while sending code block to endpoint"
raise ConnectionError(logs_all) from e
return CodeResult(exit_code=exitcode, output=logs_all)
async def restart(self) -> None:
"""(Experimental) Restart the code executor.
Resets the internal state of the executor by generating a new session ID and resetting the setup variables.
This causes the next code execution to reinitialize the environment and re-run any setup code.
"""
self._session_id = str(uuid4())
self._setup_functions_complete = False
self._access_token = None
self._available_packages = None
self._setup_cwd_complete = False
async def start(self) -> None:
"""(Experimental) Start the code executor.
View on GitHub (pinned to 027ecf0a37)
Solutions
- Read the tail of logs_all: it states whether this is an endpoint error, a timeout, or a cancellation; that determines the fix
- For 401/404 causes, call restart() and retry the code block; the new session re-runs setup
- For timeouts, raise the executor's timeout parameter (constructor) or split the workload into smaller blocks
- For oversized payloads, move data via upload_files instead of inlining it in code
Example fix
# before
result = await executor.execute_code_blocks(blocks, ct) # may raise ConnectionError/TimeoutError with logs
# after
try:
result = await executor.execute_code_blocks(blocks, ct)
except ConnectionError as e:
await executor.restart()
result = await executor.execute_code_blocks(blocks, ct)
except asyncio.TimeoutError:
executor = AzureContainerCodeExecutor(timeout=300, ...) # rebuild with longer timeout
result = await executor.execute_code_blocks(blocks, ct) Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try:
result = await executor.execute_code_blocks(blocks, ct)
except asyncio.TimeoutError:
result = await run_with_longer_timeout(blocks) # rebuild executor with larger timeout
except asyncio.CancelledError:
raise # user-initiated cancellation: propagate
except ConnectionError as e:
if "sending code block" in str(e):
await executor.restart()
result = await executor.execute_code_blocks(blocks, ct)
else:
raise Prevention
- Set timeout generously at construction (default 60s is tight for pip/ml workloads)
- Upload data files instead of inlining them in code blocks to avoid payload limits
- Distinguish the three shapes: ConnectionError (endpoint), TimeoutError, CancelledError — each has a different remedy
When it happens
Trigger: Calling execute_code_blocks when the POST to the session's execute API returns 4xx/5xx: expired token (401), stale session id (404), payload too large (code block with huge embedded data), or service errors. Also raised (as TimeoutError with the same logs shape) when execution exceeds the configured timeout, and as CancelledError when the cancellation_token fires.
Common situations: Agents generating very large code blocks (e.g. embedding a DataFrame inline) that exceed request limits; executors held across long agent conversations until the token expires; first-call races where the ACI session is still provisioning.
Related errors
- Functions failed to load: {exec_result.output.strip()}
- Failed to set up Azure container working directory
- Error while getting file list
- Error while uploading files
- Error while downloading files
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/91800e10f6cdf1a5.
Report an issue: GitHub.