fix(analytics): read pi's arguments wrapper in tool/file shapes + rollup repair pass (warren-677c) - #967
Merged
Conversation
…lup repair pass (warren-677c)
Pi toolCall blocks wrap args as {"name":"bash","type":"toolCall",
"arguments":{"command":...}}, but PI_TOOL_SHAPE read only
payload.input.command / payload.command and readPathsWith read only
payload.input. In production every pi bash rollup row (10,583/10,583)
landed command=NULL and every pi edit/read/write row (3,944/3,944)
landed empty file_paths, freezing /analytics/behavior mining on stale
claude-code data.
- PI_TOOL_SHAPE.readToolUse falls back to payload.arguments.command
(input > arguments > top-level); tests pin the observed prod payload.
- readPathsWith takes an args-container list: claude-code reads
["input"], pi reads ["input","arguments"].
- repairToolCallRollup (src/runs/tool-calls-backfill.ts) re-extracts
EXISTING rollup rows the boot backfill can never revisit (it only
targets runs with no rollup rows): keyset walk over
ToolCallsRepo.listRunsWithRollup, delete-and-replay per run from
retained events, skipping runs whose events were pruned.
- scripts/repair-tool-calls.ts is the one-off prod entrypoint
(WARREN_DB_URL required, no default; --dry-run counts candidates).
Local check:all: 11/12 gates pass; check:coverage fails only on the
pre-existing warren-4de5 macOS test-order flake (fails identically on
a clean tree).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
jayminwest
added a commit
that referenced
this pull request
Aug 18, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
jayminwest
added a commit
that referenced
this pull request
Aug 18, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pi
toolCallblocks wrap their args as{"name":"bash","type":"toolCall","arguments":{"command":…}}, butPI_TOOL_SHAPE(src/core/tool-shape.ts) read onlypayload.input.command/payload.command, andreadPathsWith(src/core/file-shape.ts) read onlypayload.input. In production every pi bash rollup row (10,583/10,583) landedcommand=NULLand every pi edit/read/write row (3,944/3,944) landed emptyfile_paths—/analytics/behaviorcommand mining has been frozen on Jul 28–31 claude-code data while 311/319 runs are pi (warren-677c).Changes
src/core/tool-shape.ts— pireadToolUsefalls back topayload.arguments.command; precedence isinput>arguments> top-level. Tests pin the exact observed prod payload.src/core/file-shape.ts—readPathsWithnow takes an args-container key list: claude-code reads["input"](arguments dialect stays pi-only), pi reads["input", "arguments"].repairToolCallRollup(src/runs/tool-calls-backfill.ts) — the boot backfill only targets runs with no rollup rows, so mis-extracted rows never re-enter its candidate set. The repair pass keyset-walksToolCallsRepo.listRunsWithRollup, deletes each run's rollup rows, and replays its retained tool events through the same extraction seam the bridge/backfill use. Runs whose events were pruned are skipped, never deleted (the rollup is only derived state while its source survives). Idempotent end to end.scripts/repair-tool-calls.ts— one-off prod entrypoint:WARREN_DB_URLrequired with no default,--dry-runcounts candidate runs.eventscovers 318/319 prod runs, so the corpus is fully repairable.Testing
arguments-wrapper shape for both command and file-path extraction, dialect precedence, and claude-code's non-reading of the pi dialect.listRunsWithRollupkeyset paging +deleteForRun(sqlite + postgres suites).check:all: 11/12 gates pass;check:coveragefails only on the pre-existing warren-4de5 macOS test-order flake (fails identically on a clean tree).Follow-up (not in this PR)
After merge + deploy, run the one-off repair against prod:
WARREN_DB_URL=… bun run scripts/repair-tool-calls.ts(optionally--dry-runfirst), then re-check/analytics/behavior.🤖 Generated with Claude Code