Skip to content

fix(memory-openviking): share pending clientPromise across dual-context registrations#681

Merged
qin-ctx merged 1 commit intovolcengine:mainfrom
Boshoff93:fix/memory-openviking-dual-context-pending-promise
Mar 17, 2026
Merged

fix(memory-openviking): share pending clientPromise across dual-context registrations#681
qin-ctx merged 1 commit intovolcengine:mainfrom
Boshoff93:fix/memory-openviking-dual-context-pending-promise

Conversation

@Boshoff93
Copy link
Copy Markdown
Contributor

Problem

OpenClaw loads the memory-openviking plugin in two separate contexts ([gateway] and [plugins]), each calling register() independently. Each call creates its own local clientPromise. However, start() only runs in one context — leaving the other context's promise permanently pending.

This causes the before_agent_start hook to hang forever on await getClient() whenever hookAgentId is set (i.e. always in a standard gateway deployment), because the hook runs in the context whose clientPromise was never resolved.

Symptoms:

  • Bot receives message, typing indicator starts, never gets a response
  • Gateway log shows running before_agent_start (1 handlers, sequential) with nothing after
  • autoRecall and autoCapture appear completely broken

Fix

Introduce a module-level localClientPendingPromises map in client.ts:

  • register() checks the map first. If an entry exists, it shares that promise instead of creating a new pending one.
  • start() atomically claims the entry (deletes it from the map) — only the first start() call spawns the process and resolves the shared promise. Subsequent start() calls fall through to await getClient() which waits for the spawner.
  • stop() clears the map entry to prevent stale promises persisting across hot-reloads.

Test plan

  • Send a message via Telegram with autoRecall: true — confirm autoRecall done appears in logs within ~2 seconds
  • Restart gateway — confirm subsequent messages still work (no stale promise from previous run)
  • Confirm before_agent_start hook no longer hangs indefinitely

🤖 Generated with Claude Code

…xt registrations

OpenClaw loads the plugin in two separate contexts ([gateway] and [plugins]),
each calling register() and creating its own pending clientPromise. However,
start() only runs in one context, leaving the other context's promise permanently
pending — causing the before_agent_start hook to hang forever on await getClient().

Fix by introducing a module-level localClientPendingPromises map in client.ts.
All registrations share the same pending promise via this map. The first start()
call to run claims the entry (deletes it from the map) and spawns the process,
resolving the shared promise for all registrations. Subsequent start() calls fall
through to await getClient() which waits for the spawner to resolve. The stop()
service clears the map entry to prevent stale promises across hot-reloads.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Wiehan Boshoff seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@qin-ctx qin-ctx merged commit 5416c81 into volcengine:main Mar 17, 2026
1 check was pending
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 17, 2026
qin-ctx added a commit that referenced this pull request Mar 19, 2026
PR #662 renamed the plugin directory and rewrote index.ts from a stale
branch base, silently dropping two merged bug fixes:

- #681: share pending clientPromise across dual-context registrations
  to prevent before_agent_start hook from hanging forever
- #688: wrap auto-recall search in withTimeout(5s) to prevent indefinite
  agent hang when OpenViking search API is slow or unresponsive
chenjw pushed a commit that referenced this pull request Mar 19, 2026
…rge (#779)

PR #662 renamed the plugin directory and rewrote index.ts from a stale
branch base, silently dropping two merged bug fixes:

- #681: share pending clientPromise across dual-context registrations
  to prevent before_agent_start hook from hanging forever
- #688: wrap auto-recall search in withTimeout(5s) to prevent indefinite
  agent hang when OpenViking search API is slow or unresponsive
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