Skip to content

fix(executions): make tool_calls a summary, not a copy of the transcript (#1741) - #1742

Merged
vybe merged 2 commits into
devfrom
fix/1741-tool-calls-summary
Jul 27, 2026
Merged

vybe merged 2 commits into
devfrom
fix/1741-tool-calls-summary

Conversation

@dolho

@dolho dolho commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Related to #1741.

The bug

apply_result assigned tool_calls_json = execution_log_json — the entire Claude Code stream-json transcript, verbatim, into a column named tool_calls. Verified byte-identical on a live run (23,438 chars each).

before after
tool_call_total for a run that made 4 tool calls 0 4
execution-detail "Tool Calls" panel empty 4 rows
copy survives execution_log retention yes, ~60 days no
transcript stored twice yes no

The metric didn't fail loudly — it reported the fact "this schedule uses no tools". Tool uses are nested inside assistant events' 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/chat returns execution_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/task returns only raw_messages. So apply_result genuinely had nothing else to store — this wasn't a wrong-variable typo.

Teaching /api/task to send the simplified log would need a base-image rebuild and leave a mixed-fleet window where old agents still write transcripts. Deriving it in services/tool_call_summary.py works on every agent image immediately.

Honest trade-off: success and duration_ms come from the agent's own tracking and cannot be reconstructed from the transcript. Both render behind v-if in the UI, so they degrade to "not shown" rather than wrong. Having /api/task also send execution_log_simplified would restore them — clean follow-up, not required for correctness.

Retention

prune_execution_logs now nulls tool_calls alongside execution_log.

The predicate also had to widen: gating on execution_log IS NOT NULL alone 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

[Cleanup] Converted legacy tool_calls on 34 executions to the summary shape (#1741)

Daily watermelon watch   executions=1  tool_call_total=4   (was 0)
Cron fire probe          executions=1  tool_call_total=0   (used no tools — a TRUE zero)

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 report MCP 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

…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]>
@github-actions

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

@vybe

vybe commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

/validate-pr: REQUEST CHANGES — real regression, not the CI flake.

The regression-diff failure survived a rerun and is deterministic across all three seeds:

  • test_1083_apply_result.TestSuccessGolden::test_success_won_writes_full_row — fails under HEAD in seeds 12345/67890/99999, passes under BASE.

The tool_calls-summary change appears to break the #1083 apply_result golden contract (that test pins the full row a CAS-won SUCCESS terminal writes, presumably including tool_calls carrying the old verbatim shape). Either the golden needs updating to the new summary shape, or apply_result's writer path was missed by the summarization and now diverges from the sync path — please determine which before re-requesting review.

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 vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@vybe
vybe merged commit da9d8ca into dev Jul 27, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants