Repository navigation
fix(executions): make tool_calls a summary, not a copy of the transcript (#1741) - #1742
Conversation
…ipt (#1741) apply_result assigned `tool_calls_json = execution_log_json` — the entire Claude Code stream-json transcript, verbatim, into a column named `tool_calls`. Three consequences, all observed on a live scheduled run: 1. Every consumer looks for {"tool": …} / {"name": …} entries, but tool uses are nested inside assistant events' message.content. get_agent_schedules_summary counted 0 of 30 entries for a run that made 4 real tool calls, and the execution-detail "Tool Calls" panel (which filters type === 'tool_use') rendered empty. A confident wrong number, not a blank. 2. prune_execution_logs nulls only execution_log, so the copy outlived the transcript it duplicates by the gap between the log window (30d) and the row window (90d) — a retention control silently bypassed by a column whose name gives no hint it holds the transcript. 3. Every execution stored its transcript twice (23 KB for a trivial run). The chat path was already right because /api/chat returns execution_log_simplified. /api/task does not — it sends only raw_messages — so apply_result had nothing else to store. Rather than teach /api/task to send the simplified log (which would need a base-image rebuild and a mixed-fleet window), derive the summary backend-side in services/tool_call_summary.py: it works on every agent image immediately. The trade-off is the two agent-side fields that cannot be reconstructed, success and duration_ms; both render conditionally in the UI, so they degrade to "not shown" rather than wrong. Having /api/task send execution_log_simplified would restore them and is a clean follow-up. Retention now nulls tool_calls alongside execution_log, and the prune predicate no longer gates on `execution_log IS NOT NULL` alone — that would permanently strand the copies on rows a previous sweep already nulled, which are exactly the rows where the copy most obviously outlived what it duplicates. Existing rows are converted in place by an idempotent, bounded pass in the cleanup sweep. Non-destructive: the transcript stays in execution_log, so a bad conversion loses nothing recoverable. Verified end to end on a live instance: the sweep converted 34 historical executions, and the schedule that made 4 tool calls now reports 4 (was 0) while a schedule instructed to use no tools still reports 0 — zero now means zero. Found by dogfooding: a scheduled agent that demonstrably used WebFetch and the report MCP tool showed "0 tool calls" in the Schedules performance panel. Related to #1741 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Resolve by running |
|
/validate-pr: REQUEST CHANGES — real regression, not the CI flake. The regression-diff failure survived a rerun and is deterministic across all three seeds:
The tool_calls-summary change appears to break the #1083 Holding this out of the 0.8.5 payload until green. (The earlier 25-min hung-job failures on this and sibling PRs were flakes — reruns cleared #1734/#1735 — but this one is real.) |
…golden - cleanup_service.py: keep BOTH appended sweeps (#1741 legacy tool_calls converter from this branch, #1745 orphaned-key revoker from dev) in the report dataclass, its dict shape, and the sweep body. - test_1083_apply_result.py: the SUCCESS golden pinned the pre-#1741 bug verbatim (execution_log == tool_calls). It now asserts the derived summary shape while execution_log keeps the raw transcript — this was the single regression-diff failure on this PR. Co-Authored-By: Claude Fable 5 <[email protected]>
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr: closing keyword ✅ (Fixes #1741, P2/type-bug), security greps clean, no schema change, CI full pytest matrix ×3 seeds + regression diff green, touched unit files re-run locally (48 passed). Design notes: retention coupling shares the prune predicate with the #1644 guard by construction ✅. One non-blocking observation: the backfill rescans from the lowest id each cycle and converted rows stay in the candidate set, so on a busy install conversion can stall beyond the first max_rows id-ordered rows — self-limiting, since the widened prune predicate nulls legacy blobs once they age past the log window. Operators on busy installs may see a one-time #1644 retention-guard ack prompt after merge (the widened predicate legitimately enlarges the candidate set).
Related to #1741.
The bug
apply_resultassignedtool_calls_json = execution_log_json— the entire Claude Code stream-json transcript, verbatim, into a column namedtool_calls. Verified byte-identical on a live run (23,438 chars each).tool_call_totalfor a run that made 4 tool callsexecution_logretentionThe metric didn't fail loudly — it reported the fact "this schedule uses no tools". Tool uses are nested inside
assistantevents'message.content, and the rollup scanned only top level: 0 of 30 entries matched.Why derive it backend-side
The chat path was already correct:
/api/chatreturnsexecution_log_simplified({type, tool, input, success, duration_ms}) — which is exactly the shape both the analytics parser (entry.get("name") or entry.get("tool")) and the UI (filter(c => c.type === 'tool_use')) expect./api/taskreturns onlyraw_messages. Soapply_resultgenuinely had nothing else to store — this wasn't a wrong-variable typo.Teaching
/api/taskto send the simplified log would need a base-image rebuild and leave a mixed-fleet window where old agents still write transcripts. Deriving it inservices/tool_call_summary.pyworks on every agent image immediately.Honest trade-off:
successandduration_mscome from the agent's own tracking and cannot be reconstructed from the transcript. Both render behindv-ifin the UI, so they degrade to "not shown" rather than wrong. Having/api/taskalso sendexecution_log_simplifiedwould restore them — clean follow-up, not required for correctness.Retention
prune_execution_logsnow nullstool_callsalongsideexecution_log.The predicate also had to widen: gating on
execution_log IS NOT NULLalone would permanently strand the copies on rows a previous sweep already nulled — precisely the rows where the copy most obviously outlived what it duplicates. Predicate and #1644 blast-radius guard stay in sync by construction (they share_execution_log_prune_predicate).Existing rows
An idempotent, bounded pass in the cleanup sweep rewrites legacy blobs in place. Non-destructive — the transcript remains in
execution_log, so a bad conversion loses nothing recoverable. Classified in the #1082 update-site inventory as a non-status writer (that guard caught the new site, as designed).Verified end to end on a live instance
The second row is the control: a schedule explicitly told not to use tools still reports 0, so the fix didn't just turn every zero into a number.
Recovered from the real bugged row:
['ToolSearch', 'WebFetch', 'ToolSearch', 'mcp__trinity__report'].Tests
tests/unit/test_1741_tool_call_summary.py— 15 passed. Extraction from the real nested shape (including a test asserting the old scan returns 0 on the same input), pass-through of already-simplified entries, malformed input never raising, bounds on count and input size, idempotent conversion, and two guards pinning the retention coupling.Suite: 262 passed across retention/cleanup/schedule. Three failures, two pre-existing on clean
origin/dev(test_1474_read_boundary_z,test_1472_schedule_validation— local tz/bcrypt env), and the third was the #1082 inventory tripwire firing on my new update site, now classified.How it was found
Dogfooding — built a scheduled agent that monitors a news page daily. It demonstrably used WebFetch and the
reportMCP tool; the Schedules performance panel said 0 tool calls. Pulling that thread found the shared blob and the retention hole behind it.🤖 Generated with Claude Code
Fixes #1741