Skip to content

fix(plugin): add timeout protection to getClient() in before_prompt_build hook#749

Merged
qin-ctx merged 1 commit intovolcengine:mainfrom
Meskjei:fix-client-timeout
Mar 19, 2026
Merged

fix(plugin): add timeout protection to getClient() in before_prompt_build hook#749
qin-ctx merged 1 commit intovolcengine:mainfrom
Meskjei:fix-client-timeout

Conversation

@Meskjei
Copy link
Contributor

@Meskjei Meskjei commented Mar 18, 2026

Problem

The before_prompt_build hook calls await 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:

  1. Plugin loads and registers the before_prompt_build hook
  2. User sends a message before start() function completes OpenViking server startup
  3. Hook triggers and calls await getClient()
  4. getClient() waits for clientPromise to resolve
  5. But clientPromise only resolves after start() finishes starting the OpenViking service
  6. Deadlock: hook blocks agent → agent can't complete → start() can't finish

Solution

Wrap getClient() call with withTimeout() (5 seconds):

  • If client initializes in time, proceed normally with memory recall
  • If timeout, log warning and skip recall gracefully
  • Agent continues without blocking

Testing

Tested locally with OpenClaw + OpenViking plugin:

  • Before fix: Agent hangs on first message if OpenViking service not ready
  • After fix: Agent responds normally, recall skipped gracefully if timeout

Related Issues

…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
@qin-ctx
Copy link
Collaborator

qin-ctx commented Mar 19, 2026

cc @Mijamind719

@qin-ctx qin-ctx self-assigned this Mar 19, 2026
Copy link
Contributor

@qin-ptr qin-ptr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@qin-ctx qin-ctx merged commit 17424af into volcengine:main Mar 19, 2026
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 19, 2026
chethanuk added a commit to chethanuk/OpenViking that referenced this pull request Mar 19, 2026
- 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)
qin-ctx pushed a commit that referenced this pull request Mar 19, 2026
…#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants