Skip to content

Add dispatch collect-agent-failures - #309

Merged
thrawn01 merged 6 commits into
mainfrom
thrawn01/eng-871-report-agent-tool-failures-and-denials
Nov 21, 2026
Merged

thrawn01 merged 6 commits into
mainfrom
thrawn01/eng-871-report-agent-tool-failures-and-denials

Conversation

@thrawn01

@thrawn01 thrawn01 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Finding where agents went wrong in the past week means running ~/.claude/retros/pattern-mining/datamine.py by hand. That script lives outside the repo, and nothing tests it. This PR adds the script's tool-failure and denial tables to dispatch as a Go command that needs no AI. It makes the same rows from the same Claude Code transcripts. ENG-872 adds the PR history tables and ENG-873 runs it on a schedule.

Fixes ENG-871

Surfaces

Command dispatch collect-agent-failures [--from TIME] [--to TIME] [--json]

It prints a Markdown report on stdout covering one window of time, by default the last 7 days. The report holds four tables of facts and draws no conclusions:

  • 1. Tool failures. Failed tool calls, grouped when they failed the same way: same tool, same command, and same first error line once paths, numbers and ids are blanked out. Each row has a count, the number of sessions, the repos, when the failure was first and last seen, and one example. A failure seen only once is left out and counted in the line under the table.
  • 1b. Permission denials. Calls that a deny rule, a safety check, the auto-mode classifier or the user refused, grouped the same way.
  • 2a. Subagent permission denials. Each denial a subagent hit, what it did next on the same file, and whether its final report mentions the denial. Rows whose report says nothing about the denial come first.
  • 2b. Files edited 5+ times. Files that one agent or session edited 5 or more times.

Flags and inputs:

  • --to defaults to now, and --from defaults to 7 days before --to. Both take the formats dispatch replay takes. A bare date such as 2026-11-13 means the start of that day in local time.
  • --json prints the same rows as JSON instead of Markdown.
  • It reads transcripts from ~/.claude/projects, or from $CLAUDE_CONFIG_DIR/projects when that variable is set. Bash deny rules come from settings.json and settings.local.json in the same config directory.

Here is the report for a small made-up week. Two go test calls fail the same way, and a deny rule blocks a subagent's git push, which its final report never mentions:

Agent failures from 2026-11-14T00:00:00-06:00 to 2026-11-20T00:00:00-06:00

Read 2 transcript files.

1. Tool failures (1)

signature count sessions repos first_seen last_seen example
Bash | go test | Exit code 1: FAIL github.com<path> <n>s 2 1 shop 2026-11-18T10:00 2026-11-19T09:00 go test ./internal/cart/⏎ => Exit code 1⏎ --- FAIL: TestCart (0.01s)⏎ FAIL github.com/acme/shop/internal/cart 0.1s

Dropped 0 signatures seen once.

1b. Permission denials (1)

signature count sessions repos first_seen last_seen example
rule | Bash | git push 1 1 shop 2026-11-19T11:00 2026-11-19T11:00 git push origin main⏎ => Permission to use Bash with command git push origin main has been denied.

2a. Subagent permission denials (1)

session agent description time kind denied next_action_on_same_file report_names_file report_denial_words report_source
1f2e3d4c agent-a1b2 Push the cart fix 2026-11-19T11:00 rule git push origin main no no last text

2b. Files edited 5+ times by one agent or session (0)

none

--json prints the same rows. The keys come from the script's data.json, plus from, to, skipped_sessions and transcript_files:

{
  "from": "2026-11-14T00:00:00-06:00",
  "to": "2026-11-20T00:00:00-06:00",
  "tool_failures": [ { "signature": "...", "count": 2, "sessions": 1, "repos": "shop", "first_seen": "...", "last_seen": "...", "example": "..." } ],
  "tool_failures_dropped_singletons": { "signatures": 0 },
  "permission_denials": [ ... ],
  "subagent_denials": [ ... ],
  "repeated_edits": [],
  "skipped_sessions": [],
  "transcript_files": 2
}

A transcript the command cannot read prints dispatch: skipped <why> on stderr. The run still exits 0.

Behavior changes

Before this PR, dispatch had no such command, and the tables came only from the Python script. I ran both on the same window, --from 2026-11-13T00:00:00Z --to 2026-11-20T22:02:20Z, over 2,899 real transcript files (3 GB). The 52 tool failure signatures, 20 permission denials, 159 subagent denials and 16 repeated-edit rows matched the script row for row. Sections 1 through 2b of the Markdown matched byte for byte, apart from the footer line below. The run took about 11 seconds.

Concerns and risks

  • I kept the name collect-agent-failures and its flags because the user chose them in chat ("go with collect-agent-failures"). They considered patterns, retro and reflect too, and left reflect free for an AI step under ENG-868.
  • The pattern miner's own sessions are still skipped, as in the script. A session is skipped when any of its lines holds the miner's marker, so a session that only greps for that marker is dropped from every table. The marker is built from two halves in agent_failures.go, so dispatch's source and usage text never contain it. ENG-873 may want a real marker once dispatch runs the miner.
  • These differences from the script are recorded on ENG-871 under "Changes from build". The repo has no design file to update.
    • Each record is filtered by its own time. The script reads the first "timestamp":" on a line, which can be an older time nested in a tool input. On disk, 15 of about 232,000 records have such a nested time.
    • An unreadable transcript is skipped with a line on stderr. The script crashed.
    • The footer reads Dropped N signatures seen once. The script's version added holding N failures, and that number always equalled N. The JSON drops its failures field for the same reason.
    • A non-string toolDenialKind is ignored. All 772 values on disk are strings.
    • A record is read whatever its JSON spacing. Claude Code writes compact JSON, so no current row changes.
    • A # that starts a word begins a comment through the end of its line. The script opened a quote at the apostrophe in # don't, and so lost every command after that comment.
    • The script's summary table is left out. No deliverable asks for it.
  • I kept two script quirks so the rows match, and tests pin both. A program run through a variable, such as "${DISPATCH_BIN:-dispatch}" ask, reads as $, so every worker's dispatch ask failure groups under Bash | $ | …. A subagent id that holds a digit becomes <sha>, not <id>. Fixing either one changes rows and breaks the match with the script.
  • Go's \b matches ASCII only, but Python's also matches other Unicode letters. A placeholder next to a non-ASCII letter, as in über.go, can normalize differently from the script. On the reference week no row differed.
  • The repo column is a guess from the session's directory. It names the repo of a treehouse tree, then a directory under ~/Development, then one under home, then (temp dir). It does not read the repos in dispatch's config, as the script didn't either.
  • No test makes a transcript read fail partway through a file. The code keeps the records read before the error and keeps the skip marker. A reviewer checked this by reading the code, not by running it.
  • The changes for JSON spacing and Bash comments got no review from a sub-agent. Each has a surface test that failed before its fix.
  • Nothing changes for existing commands on merge. The command only reads files.

Reads Claude Code transcripts over a window and prints tool failures grouped
by signature, permission denials, subagent denials with whether the final
report mentions them, and files edited 5+ times, as Markdown or JSON.

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Deep Code Review Agent🐛

Review completed with 2 suggestions.

Reviewed commit: 80921ae

Comment thread internal/agentfailure/command.go Resolved
Comment thread internal/transcript/transcript.go Resolved
@thrawn01
thrawn01 merged commit e37a1fc into main Nov 21, 2026
2 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.

1 participant