fix(plugin): add timeout protection to getClient() in before_prompt_build hook#749
Conversation
…uild hook - Import withTimeout from process-manager.js - Wrap getClient() call with 5-second timeout to prevent indefinite blocking - Gracefully handle timeout by logging warning and skipping recall - Fixes issue where agent would hang if OpenViking service wasn't ready yet Related: volcengine#673 volcengine#748
|
cc @Mijamind719 |
qin-ptr
left a comment
There was a problem hiding this comment.
Review Summary
This is a well-crafted bugfix that addresses a real timing issue: when a user sends a message before the OpenViking service completes initialization, the before_prompt_build hook would hang indefinitely waiting for the client Promise to resolve.
The solution correctly adds timeout protection (5 seconds) to the getClient() call at the hook layer. If the client isn't ready, the hook gracefully skips recall and allows the agent to respond normally.
Key strengths:
- ✅ Problem accurately identified: hook-layer infinite wait, not a deadlock
- ✅ Fix placed at the right layer (hook as consumer, not blocking other call sites)
- ✅ Minimal, surgical change with proper error handling
- ✅ No compatibility concerns
Minor suggestion (non-blocking):
- The 5-second timeout is hardcoded. While sufficient for most environments, consider making it configurable (e.g.,
clientInitTimeoutMs) for users with slower startup times. Not critical — the current behavior (skip first recall, subsequent messages work fine) is acceptable.
Approving for merge.
🤖 I am a bot owned by @qin-ctx.
| const client = await getClient(); | ||
| let client: OpenVikingClient; | ||
| try { | ||
| client = await withTimeout( |
There was a problem hiding this comment.
[Suggestion] (non-blocking)
The 5-second timeout is hardcoded. While this is reasonable for most environments, consider making it configurable (e.g., add a clientInitTimeoutMs config option with a default of 5000ms).
This would help users with slower environments (low-performance machines, large model loading) where service startup may take longer.
That said, the current behavior is acceptable: if timeout occurs, only the first auto-recall is skipped; subsequent messages work fine once the service is ready. Not a blocking issue.
- Add .pr_agent.toml with 15 repo-specific review rules derived from real bug history (PRs volcengine#505, volcengine#728, volcengine#749, volcengine#740/volcengine#745, volcengine#754, volcengine#735, volcengine#767) - Rules structured as WHEN/THEN/BECAUSE for deterministic enforcement - Add 8 custom labels (memory-pipeline, async-change, api-breaking, etc.) - Add ignore patterns for lock files, third_party, build artifacts - Enable score review, TODO scan, split-PR detection, security audit - Configure improve tool with quality threshold and extended mode - Configure describe tool with PR diagrams and semantic file types - Update workflow: ark-code-latest model, checkout step for .pr_agent.toml, move all config from inline YAML to .pr_agent.toml (single source of truth)
…#780) - Add .pr_agent.toml with 15 repo-specific review rules derived from real bug history (PRs #505, #728, #749, #740/#745, #754, #735, #767) - Rules structured as WHEN/THEN/BECAUSE for deterministic enforcement - Add 8 custom labels (memory-pipeline, async-change, api-breaking, etc.) - Add ignore patterns for lock files, third_party, build artifacts - Enable score review, TODO scan, split-PR detection, security audit - Configure improve tool with quality threshold and extended mode - Configure describe tool with PR diagrams and semantic file types - Update workflow: ark-code-latest model, checkout step for .pr_agent.toml, move all config from inline YAML to .pr_agent.toml (single source of truth)
Problem
The
before_prompt_buildhook callsawait getClient()without timeout protection. If the OpenViking client hasn't finished initializing when the hook is triggered, the agent will hang indefinitely waiting for the client Promise to resolve.This happens because:
before_prompt_buildhookstart()function completes OpenViking server startupawait getClient()getClient()waits forclientPromiseto resolveclientPromiseonly resolves afterstart()finishes starting the OpenViking servicestart()can't finishSolution
Wrap
getClient()call withwithTimeout()(5 seconds):Testing
Tested locally with OpenClaw + OpenViking plugin:
Related Issues
auto-recalltimeout but not the initialgetClient()call in hook)