Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

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

Meskjei17424afad66c
diff --git a/examples/openclaw-plugin/index.ts b/examples/openclaw-plugin/index.ts
index 2d773a590..9138ce34a 100644
--- a/examples/openclaw-plugin/index.ts
+++ b/examples/openclaw-plugin/index.ts
@@ -22,6 +22,7 @@ import {
IS_WIN,
waitForHealth,
quickRecallPrecheck,
+ withTimeout,
resolvePythonCommand,
prepareLocalPort,
} from "./process-manager.js";
@@ -414,7 +415,17 @@ const contextEnginePlugin = {
const hookSessionId = ctx?.sessionId ?? ctx?.sessionKey ?? "";
const resolvedAgentId = resolveAgentId(hookSessionId);
- const client = await getClient();
+ let client: OpenVikingClient;
+ try {
+ client = await withTimeout(
+ getClient(),
+ 5000,
+ "openviking: client initialization timeout (OpenViking service not ready yet)"
+ );
+ } catch (err) {
+ api.logger.warn?.(`openviking: failed to get client: ${String(err)}`);
+ return;
+ }
if (resolvedAgentId && client.getAgentId() !== resolvedAgentId) {
client.setAgentId(resolvedAgentId);
api.logger.info(`openviking: switched to agentId=${resolvedAgentId} for before_prompt_build`);