Skip to content

Make capture hooks async to eliminate 6s+ blocking per turn#45

Draft
kaghni wants to merge 1 commit intomainfrom
fix/async-capture-hooks
Draft

Make capture hooks async to eliminate 6s+ blocking per turn#45
kaghni wants to merge 1 commit intomainfrom
fix/async-capture-hooks

Conversation

@kaghni
Copy link
Copy Markdown
Collaborator

@kaghni kaghni commented Apr 13, 2026

Summary

  • UserPromptSubmit: blocking → async (was adding 5.5s wait before Claude responds)
  • Stop: blocking → async (was adding 3.3s wait after Claude responds)

Root cause

DB INSERT takes ~3s server-side (execution_time_ms: 2820). Each capture hook does one INSERT.
With 2 blocking capture hooks per turn, user waited ~6-9s of pure overhead.

Impact

Metric Before After
User-perceived latency per turn ~9s overhead ~0.1s
UserPromptSubmit 5.5s blocking background
Stop 3.3s blocking background
PreToolUse 32ms 94ms (unchanged)

Test plan

  • claude --plugin-dir /tmp/hivemind-perf/claude-code — send "hi", should respond instantly
  • Check ~/.deeplake/hook-debug.log with DEEPLAKE_DEBUG=1 — captures still logged
  • Verify session data still appears in DeepLake after conversation

🤖 Generated with Claude Code

DB INSERT takes ~3s per call (server-side). UserPromptSubmit and Stop
were blocking, adding ~6s latency per turn. Now async — capture runs
in background while Claude responds immediately.

Before: ~9s overhead per turn (UserPromptSubmit 5.5s + Stop 3.3s)
After: ~0.1s overhead (only PreToolUse is blocking at 94ms)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Apr 13, 2026

Claude finished @kaghni's task in 1m 12s —— View job


Reviewed the diff. No significant issues found — the change correctly extends the existing async: true pattern (already in use on PostToolUse and SubagentStop) to UserPromptSubmit and Stop. Since capture.js is write-only (no stdout injection), making these hooks async is safe.

@kaghni kaghni marked this pull request as draft April 14, 2026 20:21
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