Skip to content

Commit dcfd607

Browse files
committed
Make _from_exception a typed dataclass field; revert accidental snapshot changes
- Python: replace dynamic attribute with proper dataclass field (field(default=False, repr=False)) so type-checkers can see it - Revert accidentally committed snapshot modifications for blob_attachments and message_attachments tests
1 parent f84feec commit dcfd607

4 files changed

Lines changed: 6 additions & 12 deletions

File tree

python/copilot/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ async def _execute_tool_and_respond(
948948
# sent via the top-level error param so the CLI formats them with its
949949
# standard "Failed to execute..." message. Deliberate user-returned
950950
# failures send the full structured result to preserve metadata.
951-
if getattr(tool_result, "_from_exception", False):
951+
if tool_result._from_exception:
952952
await self.rpc.tools.handle_pending_tool_call(
953953
SessionToolsHandlePendingToolCallParams(
954954
request_id=request_id,

python/copilot/tools.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import inspect
1111
import json
1212
from collections.abc import Awaitable, Callable
13-
from dataclasses import dataclass
13+
from dataclasses import dataclass, field
1414
from typing import Any, Literal, TypeVar, get_type_hints, overload
1515

1616
from pydantic import BaseModel
@@ -38,6 +38,7 @@ class ToolResult:
3838
binary_results_for_llm: list[ToolBinaryResult] | None = None
3939
session_log: str | None = None
4040
tool_telemetry: dict[str, Any] | None = None
41+
_from_exception: bool = field(default=False, repr=False)
4142

4243

4344
@dataclass
@@ -194,20 +195,16 @@ async def wrapped_handler(invocation: ToolInvocation) -> ToolResult:
194195
except Exception as exc:
195196
# Don't expose detailed error information to the LLM for security reasons.
196197
# The actual error is stored in the 'error' field for debugging.
197-
tr = ToolResult(
198+
return ToolResult(
198199
text_result_for_llm=(
199200
"Invoking this tool produced an error. "
200201
"Detailed information is not available."
201202
),
202203
result_type="failure",
203204
error=str(exc),
204205
tool_telemetry={},
206+
_from_exception=True,
205207
)
206-
# Mark as exception-originated so _execute_tool_and_respond
207-
# sends it via the top-level error param (matching CLI formatting)
208-
# rather than as a structured result.
209-
tr._from_exception = True # type: ignore[attr-defined]
210-
return tr
211208

212209
return Tool(
213210
name=tool_name,

test/snapshots/session_config/should_accept_blob_attachments.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ conversations:
55
- role: system
66
content: ${system}
77
- role: user
8+
content: Describe this image

test/snapshots/session_config/should_accept_message_attachments.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
models:
22
- claude-sonnet-4.5
33
conversations:
4-
- messages:
5-
- role: system
6-
content: ${system}
7-
- role: user
84
- messages:
95
- role: system
106
content: ${system}

0 commit comments

Comments
 (0)