Skip to content

perf(hooks): tighten STDIN timeout, add try-catch, move pull to background - #275

Open
m0Nst3r873 wants to merge 1 commit into
Tencent:mainfrom
m0Nst3r873:perf/hook-dispatch-optimizations
Open

perf(hooks): tighten STDIN timeout, add try-catch, move pull to background#275
m0Nst3r873 wants to merge 1 commit into
Tencent:mainfrom
m0Nst3r873:perf/hook-dispatch-optimizations

Conversation

@m0Nst3r873

Copy link
Copy Markdown
Collaborator

Summary

Three independent hook dispatch optimizations to improve reliability and responsiveness:

  • STDIN timeout 2s → 1s: Healthy hosts EOF within milliseconds; the 2s timeout was overly generous for the missing-EOF edge case
  • Top-level try-catch in hookDispatchCli: Prevents unexpected errors (dynamic import failures, config parse errors) from crashing the hook process — logs at warn level for diagnosability
  • pullHandler moved to background on session-start: pull does not produce output the host needs to inject, so running it detached avoids blocking session startup on slow git fetches

Changes

  • src/hook-dispatch-cli.ts: Reduce STDIN_READ_TIMEOUT_MS from 2000 to 1000; wrap hookDispatchCli body in try-catch with log.warn
  • src/hook-handlers.ts: Change pullHandler registration from foreground to background: true with LOCAL_AGENT_TIMEOUT_MS

Test plan

  • npx tsc --noEmit — type check passes
  • npx vitest run — 1885 tests pass (143 files), including golden tests
  • npm run build — build succeeds
  • Trigger session-start hook, verify pull runs in background (not blocking session prompt)
  • Simulate hookDispatchCli error, verify warn-level log appears in stderr

Generated with Claude Code

…round

Three independent hook dispatch optimizations:

1. Reduce STDIN read timeout from 2s to 1s — healthy hosts EOF within
   milliseconds; the timeout only guards the missing-EOF edge case.

2. Wrap hookDispatchCli body in try-catch so unexpected errors (dynamic
   import failures, config parse errors) are logged rather than crashing
   the hook process.

3. Move pullHandler to background on session-start — pull does not
   produce output the host injects into the session, so running it
   detached avoids blocking session startup on slow git fetches.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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