Skip to content

fix(hooks): atomic flush + hook timing wiring (#1493, #1494)#1496

Merged
JeremyDev87 merged 2 commits into
masterfrom
fix/hooks-stats-race-and-timing-wiring
Apr 12, 2026
Merged

fix(hooks): atomic flush + hook timing wiring (#1493, #1494)#1496
JeremyDev87 merged 2 commits into
masterfrom
fix/hooks-stats-race-and-timing-wiring

Conversation

@JeremyDev87
Copy link
Copy Markdown
Owner

Summary

Test plan

  • TestConcurrentFlush: 8 processes × 100 calls = 800 expected, asserts exact count (fails without race fix, passes with _locked_modify)
  • TestHookTimingWiring: 3 tests — recording, exception resilience, accumulation
  • All 31 tests in test_stats.py pass
  • All 428+ tests in packages/claude-code-plugin/tests/ pass (2 pre-existing failures in test_hud.py unrelated to this PR — buddy face character mismatch)
  • Plugin CI: lint, format:check, typecheck, test:coverage (144/144), circular, build — all green
  • Manual: verify ⏱ PostToolUse:Xms appears in Stop hook summary during a real Claude Code session

Closes #1493
Closes #1494

Replace separate _locked_read() + _locked_write() in flush() with a
single _locked_modify() helper that holds LOCK_EX for the entire
read-modify-write window.  This prevents concurrent PostToolUse
processes from clobbering each other's updates.

Add TestConcurrentFlush regression test (8 procs × 100 calls = 800
expected) that fails without the fix.
- Add hooks/lib/hook_runtime.py with time_hook() context manager that
  records hook elapsed time via SessionStats.record_hook_timing()
- Wire time_hook into all 5 hook scripts: PreToolUse, PostToolUse,
  SessionStart, Stop, UserPromptSubmit
- Delete hooks/lib/hook_timer.py (dead code — per-process in-memory
  model does not work for short-lived hook processes)
- Delete tests/test_hook_timer.py (tests for removed dead code)
- Add TestHookTimingWiring regression tests (3 cases):
  recording, exception resilience, accumulation

The Stop hook summary now surfaces ⏱ timing data:
  [CB] 3m | 12 tools | 0 errors | Bash:5 | ⏱ PostToolUse:42ms
@JeremyDev87 JeremyDev87 added the bug Something isn't working label Apr 12, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
codingbuddy-landing Ready Ready Preview, Comment Apr 12, 2026 4:02am

@JeremyDev87 JeremyDev87 self-assigned this Apr 12, 2026
@JeremyDev87 JeremyDev87 merged commit be6502d into master Apr 12, 2026
29 checks passed
@JeremyDev87 JeremyDev87 deleted the fix/hooks-stats-race-and-timing-wiring branch April 12, 2026 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

1 participant