Skip to content

Commit 67dcdd8

Browse files
nik13claude
andcommitted
fix(claude-cowork): a result with no decision never consumes a reject; page nits (TH-8296)
- Pair a tool_result with its tool_decision only by tool_use_id, else by tool name plus decision_type. A result that carries no decision_type and matches no decision by tool_use_id now pairs with nothing, so an earlier reject keeps its own span instead of being consumed as the oldest same-name decision. Test covers the result with and without an unmatched tool_use_id. - Page: the pairing rule says what happens to such a result; the name filter also rejects tab (pinned by a test); a rejected MCP call's names appear only when tool_decision carries tool_parameters, which Cowork's reference does not list; user.id is on spans only when Cowork sends the account UUID (absent on third-party deployments); the description says "by default". Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bd38439 commit 67dcdd8

3 files changed

Lines changed: 41 additions & 13 deletions

File tree

‎examples/coding-agents/claude-cowork/bridge.py‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,22 @@ def tool_decision(self, p: Prompt, a: Dict[str, Any], t: int, seq: int):
362362
"tool_use_id": a.get("tool_use_id"), "time": t})
363363

364364
def match_decision(self, p: Prompt, name: str, names: Dict[str, str], a: Dict[str, Any], t: int):
365-
"""The tool_decision event for this tool_result, if one is pending."""
365+
"""The tool_decision event for this tool_result, if one is pending: by tool_use_id, else by tool
366+
name and decision_type. A result that carries neither pairs with nothing, so a pending reject
367+
is never consumed by a guess and still gets its own span."""
366368
use_id = a.get("tool_use_id")
367369
if use_id:
368370
for d in p.decisions:
369371
if d["tool_use_id"] == use_id:
370372
return d
371-
same = [d for d in p.decisions
372-
if d["tool_name"] == name and d["time"] <= t
373-
and not (use_id and d["tool_use_id"])
374-
and all(d["names"].get(k) == v for k, v in names.items() if k in d["names"])]
375373
want = a.get("decision_type")
376-
if want: # a rejected call that the agent retried must keep its own reject span
377-
return next((d for d in same if d["decision"] == want), None)
378-
return same[0] if same else None
374+
if not want:
375+
return None
376+
# A rejected call that the agent retried must keep its own reject span.
377+
return next((d for d in p.decisions
378+
if d["tool_name"] == name and d["time"] <= t and d["decision"] == want
379+
and not (use_id and d["tool_use_id"])
380+
and all(d["names"].get(k) == v for k, v in names.items() if k in d["names"])), None)
379381

380382
def tool_result(self, p: Prompt, a: Dict[str, Any], t: int, seq: int):
381383
dur = to_int(a.get("duration_ms")) or 0

‎examples/coding-agents/claude-cowork/tests/test_bridge.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,24 @@ def test_tool_use_id_pairs_decision_and_result(self):
258258
tools = sorted((s["name"], a.get("cowork.decision", "")) for _, s, a in spans if a["fi.span.kind"] == "TOOL")
259259
self.assertEqual(tools, [("Read", ""), ("Read", "reject")])
260260

261+
def test_result_without_a_decision_does_not_consume_a_reject(self):
262+
# No tool_use_id and no decision_type: the result cannot say which decision it belongs to,
263+
# so it pairs with none and the earlier reject keeps its span.
264+
for result in (rec("tool_result", 3, 3, tool_name="Bash", success="true", duration_ms="100"),
265+
rec("tool_result", 3, 3, tool_name="Bash", success="true", tool_use_id="toolu_9")):
266+
with self.subTest(tool_use_id="tool_use_id" in json.dumps(result)):
267+
self.sink.payloads.clear()
268+
spans = self.mapped(rec("user_prompt", 0, 0),
269+
rec("tool_decision", 1, 1, tool_name="Bash", decision="reject", source="config"),
270+
rec("tool_decision", 2, 2, tool_name="Bash", decision="accept",
271+
source="user_temporary"),
272+
result)
273+
tools = sorted((s["name"], a.get("cowork.decision", "")) for _, s, a in spans
274+
if a["fi.span.kind"] == "TOOL")
275+
self.assertEqual(tools, [("Bash", ""), ("Bash", "reject")])
276+
root = [a for _, s, a in spans if "parentSpanId" not in s][0]
277+
self.assertEqual(root["cowork.tool_calls"], 1)
278+
261279
def test_prompt_error_only_when_the_last_model_request_failed(self):
262280
ok = self.mapped(rec("user_prompt", 0, 0, prompt=P1),
263281
rec("api_error", 1, 1, prompt=P1, status_code="529", error="overloaded_error", attempt="1"),
@@ -319,6 +337,14 @@ def test_tool_parameters_names_only(self):
319337
self.assertEqual(tools["mcp__jira__create_issue"]["cowork.decision"], "reject")
320338
self.assertEqual(tools["mcp__jira__create_issue"]["gen_ai.tool.name"], "mcp__jira__create_issue")
321339

340+
def test_name_filter_is_the_rule_on_the_page(self):
341+
# The page: at most 128 characters and no /, \, @, line break, or tab.
342+
def names(value):
343+
return bridge.tool_names({"tool_parameters": json.dumps({"skill_name": value})})
344+
for bad in ("a/b", "a\\b", "a@b", "a\nb", "a\rb", "a\tb", "x" * 129, ""):
345+
self.assertEqual(names(bad), {}, repr(bad))
346+
self.assertEqual(names("x" * 128), {"cowork.skill_name": "x" * 128})
347+
322348
def test_api_error_text_needs_content_opt_in(self):
323349
err = "rate_limit_error: proxy https://gw.internal/v1 for /Users/alice/project rejected the request"
324350
records = (rec("user_prompt", 0, 0), rec("api_error", 1, 1, status_code="429", error=err))

‎src/pages/docs/integrations/coding-agents/claude-cowork.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Claude Cowork session tracing with Future AGI"
3-
description: "Trace Claude Cowork activity in Future AGI from Cowork's admin OpenTelemetry export: one trace per prompt with model requests, tool calls, approvals, tokens, cost, and errors. Prompt text, tool inputs, file paths, and emails are stripped before Future AGI stores anything."
3+
description: "Trace Claude Cowork activity in Future AGI from Cowork's admin OpenTelemetry export: one trace per prompt with model requests, tool calls, approvals, tokens, cost, and errors. By default, prompt text, tool inputs, file paths, and emails are stripped before Future AGI stores anything."
44
---
55

66
## About
@@ -109,13 +109,13 @@ FI_API_KEY=... FI_SECRET_KEY=... FI_PROJECT_NAME=cowork-e2e fi-docs/examples/cod
109109
| `api_request` | **Cowork model request** (LLM) | model, input tokens (including cache reads and writes), output tokens, cache read and write tokens, `cost_usd` as `gen_ai.cost.total`, duration, speed |
110110
| `api_error` | **Cowork model request**, status `ERROR` | model, HTTP status code, the Anthropic error type (such as `rate_limit_error`) as `error.type` and in the status message, attempt, duration |
111111
| `tool_result` | tool span named after `tool_name`; an MCP call is named `mcp__<server>__<tool>` | success, duration, approval decision and its source, result size, MCP server scope, and from `tool_parameters` only the MCP server and tool names, the skill name, and the subagent type. `success: "false"` marks the span `ERROR` |
112-
| `tool_decision` | tool span, only when the decision is `reject` and no `tool_result` follows for that call | decision and source, and the same names |
112+
| `tool_decision` | tool span, only when the decision is `reject` and no `tool_result` follows for that call | decision and source, and the same names when the event carries `tool_parameters` (Cowork's reference does not list it on `tool_decision`, so a rejected MCP call can show as `mcp_tool`) |
113113

114-
Every span carries `session.id` and `user.id`, so model requests and their cost count under the user in [Users](/docs/observe/features/users). The prompt span also carries the prompt's total tokens as `cowork.prompt.input_tokens` and `cowork.prompt.output_tokens`, and its tool-call count (rejected calls are not counted). Cost is Anthropic's estimate from the event, not your bill.
114+
Every span carries `session.id`, and `user.id` when Cowork sends the account UUID, so model requests and their cost count under the user in [Users](/docs/observe/features/users). Third-party deployments of Claude Desktop send no account UUID, so their spans have no `user.id` and do not appear in Users. The prompt span also carries the prompt's total tokens as `cowork.prompt.input_tokens` and `cowork.prompt.output_tokens`, and its tool-call count (rejected calls are not counted). Cost is Anthropic's estimate from the event, not your bill.
115115

116116
The prompt span is `ERROR` only when its last model request failed. A request that hit a rate limit and that Cowork retried successfully stays `ERROR` on its own model-request span, and the prompt is not marked. A failed tool marks only its tool span.
117117

118-
A `tool_result` is paired with its `tool_decision` by `tool_use_id` when the events carry one, and otherwise by tool name and decision, so a rejected call stays visible when the agent then retries the same tool.
118+
A `tool_result` is paired with its `tool_decision` by `tool_use_id` when the events carry one, and otherwise by tool name and decision, so a rejected call stays visible when the agent then retries the same tool. A `tool_result` that carries no `decision_type` and matches no decision by `tool_use_id` is not paired, so an earlier reject still gets its own span.
119119

120120
Cowork's exporter delivers at least once. The bridge skips a record identical to one it already received for the same prompt, so a re-sent batch does not change the prompt's totals.
121121

@@ -139,7 +139,7 @@ By default the bridge forwards metadata only, whatever Cowork sends. On a first-
139139
| `tool_input` (tool arguments) | dropped | tool span input, as Cowork sends it: shell commands, file paths, URLs, and any email addresses in the arguments |
140140
| `error` on a failed `tool_result` | dropped, status message is `tool failed` | status message, which can name files, paths, and accounts |
141141
| `error` on `api_error` (the API's message) | dropped, status message is the HTTP status and the Anthropic error type, such as `HTTP 429 rate_limit_error` | status message |
142-
| `tool_parameters` (commands, file paths, URLs, MCP server and tool names, skill names) | names only: the values of `mcp_server_name`, `mcp_tool_name`, `skill_name`, and `subagent_type`, and only when the value has at most 128 characters and no `/`, `\`, `@`, or line break. Commands, file paths, URLs, and every other key are dropped | same as default |
142+
| `tool_parameters` (commands, file paths, URLs, MCP server and tool names, skill names) | names only: the values of `mcp_server_name`, `mcp_tool_name`, `skill_name`, and `subagent_type`, and only when the value has at most 128 characters and no `/`, `\`, `@`, line break, or tab. Commands, file paths, URLs, and every other key are dropped | same as default |
143143
| `user.email`, `user.account_id`, the device-level `user.id`, `workspace.host_paths`, `enduser.id`, `process.owner` | dropped (`user.id` in Future AGI is the account UUID) | dropped |
144144

145145
The bridge has no pass-through. A field that is not in the table above or in [What is captured](#what-is-captured) is not forwarded, so a new field Cowork adds later stays out until the bridge maps it. MCP server, tool, and skill names are names your admins or users chose (for example a connector called `gmail`); they are kept so tool spans can be told apart.

0 commit comments

Comments
 (0)