Skip to content

perf(claude-ops): hook-failure-audit Stop hook reads the whole transcript on every Stop (7 s at 10 MB) #4389

Description

@kyle-sexton

Parent: #4373

Measurement

Harness: melodic-software/dotfiles#873. 22 runs per size, no-op spawn floor S = 20 ms.

transcript hook-failure-audit.sh Stop median processes per fire
50 KB 137 ms 3
2 MB 1,374 ms 3
10 MB 6,977 ms 3

The first Stop of a session is fast (133–191 ms at every size), because that call takes the capped tail -c cold path. Every later Stop scales with transcript size. Weighted by 0.76 Stop fires per turn, this hook alone is 5.3 s per turn at 10 MB. Production OTEL agrees: Stop p50 3.0 s and p95 10.2 s over 7 days, rising from 2.4 s to 7.5 s by session position.

Cause

The per-session cursor stores a line count, and the warm path skips the already-audited lines with mapfile -s $((CURSOR - 1)) LINES <"$TRANSCRIPT". mapfile -s still reads and splits every skipped line in bash. Timed on the same 10 MB transcript on this host: mapfile -s took 11.6 s (10.7 s sys), and tail -c 2000 took 49 ms.

Fix direction

Acceptance

  • Harness median at 10 MB within k × S plus measured work. The target is agreed through /performance:goal before implementing.
  • The process count does not rise.
  • Output is byte-identical on real transcripts, both cold and warm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageNot yet classified. Floor until a type and one priority tier are set.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions