Repository navigation
Python: [BREAKING] CodeAct: redact host-tool diagnostics by default #9971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Eduard van Valkenburg (eavanvalkenburg)
merged 3 commits into
microsoft:main
from
eavanvalkenburg:monty-error-diagnostics
Nov 2, 2026
+495
−44
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import threading | ||
| from collections.abc import Callable | ||
| from types import SimpleNamespace | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| from agent_framework import FunctionTool | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def host_error_detail() -> str: | ||
| return "synthetic backend diagnostic" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def failing_host_tool(request: pytest.FixtureRequest, host_error_detail: str) -> FunctionTool: | ||
| def fail() -> str: | ||
| raise ValueError(host_error_detail) | ||
|
|
||
| async def fail_async() -> str: | ||
| await asyncio.sleep(0) | ||
| raise ValueError(host_error_detail) | ||
|
|
||
| return FunctionTool( | ||
| name="failing_host_tool", | ||
| description="Raise a synthetic diagnostic.", | ||
| func=fail_async if request.param else fail, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def cancelled_host_tool() -> FunctionTool: | ||
| async def cancel() -> str: | ||
| raise asyncio.CancelledError | ||
|
|
||
| return FunctionTool(name="cancelled_host_tool", func=cancel) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def lifecycle_sandbox_factory(host_error_detail: str) -> Callable[..., type[Any]]: | ||
| def factory(failure_stage: str, error_type: type[BaseException] = ValueError) -> type[Any]: | ||
| class LifecycleSandbox: | ||
| events: list[tuple[str, int]] = [] | ||
|
|
||
| def __init__(self, **kwargs: Any) -> None: | ||
| self._owner_thread = threading.get_ident() | ||
| self._record("build") | ||
|
|
||
| def _record(self, stage: str) -> None: | ||
| self.events.append((stage, threading.get_ident())) | ||
| if stage == failure_stage: | ||
| raise error_type(host_error_detail) | ||
|
|
||
| def register_tool(self, name: str, callback: Any) -> None: | ||
| self._record("register_tool") | ||
|
|
||
| def allow_domain(self, target: str, methods: Any = None) -> None: | ||
| self._record("allow_domain") | ||
|
|
||
| def run(self, code: str) -> Any: | ||
| self._record("warmup" if code == "None" else "run") | ||
| return SimpleNamespace(success=True, stdout="ok\n", stderr="") | ||
|
|
||
| def snapshot(self) -> object: | ||
| self._record("snapshot") | ||
| return object() | ||
|
|
||
| def restore(self, snapshot: object) -> None: | ||
| self._record("restore") | ||
|
|
||
| def close(self) -> None: | ||
| self._record("close") | ||
|
|
||
| def __del__(self) -> None: | ||
| self.events.append(("drop", threading.get_ident())) | ||
|
|
||
| return LifecycleSandbox | ||
|
|
||
| return factory |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.