Skip to content

Commit 7d5b4b5

Browse files
committed
refactor(contrib): keep only raw_input/raw_output deepcopy in tracked tool call init
Per review, only the two deepcopy calls in _TrackedToolCall.__init__ are needed; drop the other deepcopy changes, the class docstring note, and tests that depended on them.
1 parent fb74a7f commit 7d5b4b5

3 files changed

Lines changed: 15 additions & 76 deletions

File tree

‎src/acp/contrib/tool_calls.py‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def to_view(self) -> TrackedToolCallView:
100100
status=self.status,
101101
content=tuple(item.model_copy(deep=True) for item in self.content) if self.content else None,
102102
locations=tuple(loc.model_copy(deep=True) for loc in self.locations) if self.locations else None,
103-
raw_input=deepcopy(self.raw_input),
104-
raw_output=deepcopy(self.raw_output),
103+
raw_input=self.raw_input,
104+
raw_output=self.raw_output,
105105
)
106106

107107
def to_tool_call_model(self) -> ToolCallUpdate:
@@ -113,8 +113,8 @@ def to_tool_call_model(self) -> ToolCallUpdate:
113113
status=self.status,
114114
content=_copy_model_list(self.content),
115115
locations=_copy_model_list(self.locations),
116-
raw_input=deepcopy(self.raw_input),
117-
raw_output=deepcopy(self.raw_output),
116+
raw_input=self.raw_input,
117+
raw_output=self.raw_output,
118118
)
119119

120120
def to_start_model(self) -> ToolCallStart:
@@ -129,8 +129,8 @@ def to_start_model(self) -> ToolCallStart:
129129
status=self.status,
130130
content=_copy_model_list(self.content),
131131
locations=_copy_model_list(self.locations),
132-
raw_input=deepcopy(self.raw_input),
133-
raw_output=deepcopy(self.raw_output),
132+
raw_input=self.raw_input,
133+
raw_output=self.raw_output,
134134
)
135135

136136
def update(
@@ -170,11 +170,11 @@ def update(
170170
)
171171
kwargs["locations"] = _copy_model_list(seq_locations)
172172
if raw_input is not UNSET:
173-
self.raw_input = deepcopy(raw_input)
174-
kwargs["rawInput"] = deepcopy(self.raw_input)
173+
self.raw_input = raw_input
174+
kwargs["rawInput"] = raw_input
175175
if raw_output is not UNSET:
176-
self.raw_output = deepcopy(raw_output)
177-
kwargs["raw_output"] = deepcopy(self.raw_output)
176+
self.raw_output = raw_output
177+
kwargs["raw_output"] = raw_output
178178
return ToolCallProgress(session_update="tool_call_update", tool_call_id=self.tool_call_id, **kwargs)
179179

180180
def append_stream_text(
@@ -190,11 +190,7 @@ def append_stream_text(
190190

191191

192192
class ToolCallTracker:
193-
"""Utility for generating ACP tool call updates on the server side.
194-
195-
Raw input/output payloads are copied on entry and export so caller, view,
196-
notification, and permission-request mutations cannot change tracked state.
197-
"""
193+
"""Utility for generating ACP tool call updates on the server side."""
198194

199195
def __init__(self, *, id_factory: Callable[[], str] | None = None) -> None:
200196
self._id_factory = id_factory or (lambda: uuid.uuid4().hex)

‎tests/contrib/test_contrib_permissions.py‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,3 @@ def test_default_permission_options_shape():
116116
options = default_permission_options()
117117
assert len(options) == 3
118118
assert {opt.option_id for opt in options} == {"approve", "approve_for_session", "reject"}
119-
120-
121-
@pytest.mark.asyncio
122-
async def test_permission_request_raw_payloads_are_detached_from_tracker() -> None:
123-
tracker = ToolCallTracker()
124-
tracker.start("external", title="Run", raw_input={"args": ["original"]}, raw_output={"result": ["original"]})
125-
126-
async def requester(request: RequestPermissionRequest) -> RequestPermissionResponse:
127-
assert isinstance(request.tool_call.raw_input, dict)
128-
assert isinstance(request.tool_call.raw_output, dict)
129-
request.tool_call.raw_input["args"].append("request mutation")
130-
request.tool_call.raw_output["result"].append("request mutation")
131-
return RequestPermissionResponse(outcome=AllowedOutcome(option_id="approve", outcome="selected"))
132-
133-
broker = PermissionBroker("session", requester, tracker=tracker)
134-
await broker.request_for("external")
135-
136-
assert tracker.view("external").raw_input == {"args": ["original"]}
137-
assert tracker.view("external").raw_output == {"result": ["original"]}

‎tests/contrib/test_contrib_tool_calls.py‎

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,7 @@ def test_tool_call_tracker_streaming_text_updates_content():
3838

3939

4040
@pytest.mark.parametrize("field", ["raw_input", "raw_output"])
41-
@pytest.mark.parametrize("operation", ["start", "progress"])
42-
def test_tracker_snapshots_incoming_raw_payloads(field: str, operation: str) -> None:
43-
tracker = ToolCallTracker()
44-
payload = {"nested": ["original"]}
45-
if operation == "start":
46-
notification = tracker.start(
47-
"external",
48-
title="Run",
49-
raw_input=payload if field == "raw_input" else None,
50-
raw_output=payload if field == "raw_output" else None,
51-
)
52-
else:
53-
tracker.start("external", title="Run")
54-
notification = tracker.progress(
55-
"external",
56-
raw_input=payload if field == "raw_input" else None,
57-
raw_output=payload if field == "raw_output" else None,
58-
)
59-
60-
payload["nested"].append("caller mutation")
61-
62-
assert getattr(tracker.view("external"), field) == {"nested": ["original"]}
63-
assert getattr(notification, field) == {"nested": ["original"]}
64-
65-
66-
@pytest.mark.parametrize("field", ["raw_input", "raw_output"])
67-
@pytest.mark.parametrize("output", ["start", "progress", "view", "tool_call_model"])
68-
def test_tracker_raw_payload_exports_cannot_mutate_state(field: str, output: str) -> None:
41+
def test_tracker_start_snapshots_incoming_raw_payloads(field: str) -> None:
6942
tracker = ToolCallTracker()
7043
payload = {"nested": ["original"]}
7144
notification = tracker.start(
@@ -74,22 +47,11 @@ def test_tracker_raw_payload_exports_cannot_mutate_state(field: str, output: str
7447
raw_input=payload if field == "raw_input" else None,
7548
raw_output=payload if field == "raw_output" else None,
7649
)
77-
if output == "progress":
78-
exported = tracker.progress(
79-
"external",
80-
raw_input=payload if field == "raw_input" else None,
81-
raw_output=payload if field == "raw_output" else None,
82-
)
83-
elif output == "view":
84-
exported = tracker.view("external")
85-
elif output == "tool_call_model":
86-
exported = tracker.tool_call_model("external")
87-
else:
88-
exported = notification
89-
90-
getattr(exported, field)["nested"].append("consumer mutation")
50+
51+
payload["nested"].append("caller mutation")
9152

9253
assert getattr(tracker.view("external"), field) == {"nested": ["original"]}
54+
assert getattr(notification, field) == {"nested": ["original"]}
9355

9456

9557
@pytest.mark.parametrize("payload", [None, False, 0, "text", ["item"]])

0 commit comments

Comments
 (0)