-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(plugin): add timeout protection to auto-recall in openclaw-plugin #750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import { | |
| quickRecallPrecheck, | ||
| resolvePythonCommand, | ||
| prepareLocalPort, | ||
| withTimeout, | ||
| } from "./process-manager.js"; | ||
| import { createMemoryOpenVikingContextEngine } from "./context-engine.js"; | ||
|
|
||
|
|
@@ -430,6 +431,8 @@ const contextEnginePlugin = { | |
|
|
||
| const prependContextParts: string[] = []; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] (non-blocking) The timeout value is hardcoded to 5000ms. Different deployment environments (high-latency networks, slow servers) may require different timeout values. Consider adding a config field like: autoRecallTimeoutMs: Type.Number({
default: 5000,
description: "Timeout for auto-recall in ms"
})Then use |
||
| const AUTO_RECALL_TIMEOUT_MS = 5_000; | ||
|
|
||
| if (cfg.autoRecall && queryText.length >= 5) { | ||
| const precheck = await quickRecallPrecheck(cfg.mode, cfg.baseUrl, cfg.port, localProcess); | ||
| if (!precheck.ok) { | ||
|
|
@@ -438,69 +441,75 @@ const contextEnginePlugin = { | |
| ); | ||
| } else { | ||
| try { | ||
| const candidateLimit = Math.max(cfg.recallLimit * 4, 20); | ||
| const [userSettled, agentSettled] = await Promise.allSettled([ | ||
| client.find(queryText, { | ||
| targetUri: "viking://user/memories", | ||
| limit: candidateLimit, | ||
| scoreThreshold: 0, | ||
| }), | ||
| client.find(queryText, { | ||
| targetUri: "viking://agent/memories", | ||
| limit: candidateLimit, | ||
| scoreThreshold: 0, | ||
| }), | ||
| ]); | ||
|
|
||
| const userResult = userSettled.status === "fulfilled" ? userSettled.value : { memories: [] }; | ||
| const agentResult = agentSettled.status === "fulfilled" ? agentSettled.value : { memories: [] }; | ||
| if (userSettled.status === "rejected") { | ||
| api.logger.warn(`openviking: user memories search failed: ${String(userSettled.reason)}`); | ||
| } | ||
| if (agentSettled.status === "rejected") { | ||
| api.logger.warn(`openviking: agent memories search failed: ${String(agentSettled.reason)}`); | ||
| } | ||
|
|
||
| const allMemories = [...(userResult.memories ?? []), ...(agentResult.memories ?? [])]; | ||
| const uniqueMemories = allMemories.filter((memory, index, self) => | ||
| index === self.findIndex((m) => m.uri === memory.uri) | ||
| ); | ||
| const leafOnly = uniqueMemories.filter((m) => m.level === 2); | ||
| const processed = postProcessMemories(leafOnly, { | ||
| limit: candidateLimit, | ||
| scoreThreshold: cfg.recallScoreThreshold, | ||
| }); | ||
| const memories = pickMemoriesForInjection(processed, cfg.recallLimit, queryText); | ||
|
|
||
| if (memories.length > 0) { | ||
| const memoryLines = await Promise.all( | ||
| memories.map(async (item: FindResultItem) => { | ||
| if (item.level === 2) { | ||
| try { | ||
| const content = await client.read(item.uri); | ||
| if (content && typeof content === "string" && content.trim()) { | ||
| return `- [${item.category ?? "memory"}] ${content.trim()}`; | ||
| await withTimeout( | ||
| (async () => { | ||
| const candidateLimit = Math.max(cfg.recallLimit * 4, 20); | ||
| const [userSettled, agentSettled] = await Promise.allSettled([ | ||
| client.find(queryText, { | ||
| targetUri: "viking://user/memories", | ||
| limit: candidateLimit, | ||
| scoreThreshold: 0, | ||
| }), | ||
| client.find(queryText, { | ||
| targetUri: "viking://agent/memories", | ||
| limit: candidateLimit, | ||
| scoreThreshold: 0, | ||
| }), | ||
| ]); | ||
|
|
||
| const userResult = userSettled.status === "fulfilled" ? userSettled.value : { memories: [] }; | ||
| const agentResult = agentSettled.status === "fulfilled" ? agentSettled.value : { memories: [] }; | ||
| if (userSettled.status === "rejected") { | ||
| api.logger.warn(`openviking: user memories search failed: ${String(userSettled.reason)}`); | ||
| } | ||
| if (agentSettled.status === "rejected") { | ||
| api.logger.warn(`openviking: agent memories search failed: ${String(agentSettled.reason)}`); | ||
| } | ||
|
|
||
| const allMemories = [...(userResult.memories ?? []), ...(agentResult.memories ?? [])]; | ||
| const uniqueMemories = allMemories.filter((memory, index, self) => | ||
| index === self.findIndex((m) => m.uri === memory.uri) | ||
| ); | ||
| const leafOnly = uniqueMemories.filter((m) => m.level === 2); | ||
| const processed = postProcessMemories(leafOnly, { | ||
| limit: candidateLimit, | ||
| scoreThreshold: cfg.recallScoreThreshold, | ||
| }); | ||
| const memories = pickMemoriesForInjection(processed, cfg.recallLimit, queryText); | ||
|
|
||
| if (memories.length > 0) { | ||
| const memoryLines = await Promise.all( | ||
| memories.map(async (item: FindResultItem) => { | ||
| if (item.level === 2) { | ||
| try { | ||
| const content = await client.read(item.uri); | ||
| if (content && typeof content === "string" && content.trim()) { | ||
| return `- [${item.category ?? "memory"}] ${content.trim()}`; | ||
| } | ||
| } catch { | ||
| // fallback to abstract | ||
| } | ||
| } | ||
| } catch { | ||
| // fallback to abstract | ||
| } | ||
| } | ||
| return `- [${item.category ?? "memory"}] ${item.abstract ?? item.uri}`; | ||
| }), | ||
| ); | ||
| const memoryContext = memoryLines.join("\n"); | ||
| api.logger.info(`openviking: injecting ${memories.length} memories into context`); | ||
| api.logger.info( | ||
| `openviking: inject-detail ${toJsonLog({ count: memories.length, memories: summarizeInjectionMemories(memories) })}`, | ||
| ); | ||
| prependContextParts.push( | ||
| "<relevant-memories>\nThe following OpenViking memories may be relevant:\n" + | ||
| `${memoryContext}\n` + | ||
| "</relevant-memories>", | ||
| ); | ||
| } | ||
| return `- [${item.category ?? "memory"}] ${item.abstract ?? item.uri}`; | ||
| }), | ||
| ); | ||
| const memoryContext = memoryLines.join("\n"); | ||
| api.logger.info(`openviking: injecting ${memories.length} memories into context`); | ||
| api.logger.info( | ||
| `openviking: inject-detail ${toJsonLog({ count: memories.length, memories: summarizeInjectionMemories(memories) })}`, | ||
| ); | ||
| prependContextParts.push( | ||
| "<relevant-memories>\nThe following OpenViking memories may be relevant:\n" + | ||
| `${memoryContext}\n` + | ||
| "</relevant-memories>", | ||
| ); | ||
| } | ||
| })(), | ||
| AUTO_RECALL_TIMEOUT_MS, | ||
| `openviking: auto-recall timed out after ${AUTO_RECALL_TIMEOUT_MS}ms`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] (non-blocking) The error message says "failed or timed out" for all errors, even when the error is not caused by timeout. This could be misleading when debugging. Consider checking the error message or type: catch (err) {
const msg = String(err);
const isTimeout = msg.includes('timed out');
api.logger.warn(
`openviking: auto-recall ${isTimeout ? 'timed out' : 'failed'}: ${msg}`
);
} |
||
| ); | ||
| } catch (err) { | ||
| api.logger.warn(`openviking: auto-recall failed: ${String(err)}`); | ||
| api.logger.warn(`openviking: auto-recall failed or timed out: ${String(err)}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Design] (blocking)
PR description claims:
But the actual code only adds a hardcoded local constant
AUTO_RECALL_TIMEOUT_MShere. The config schema (memoryOpenVikingConfigSchema) was not modified, and there is no UI support added.This inconsistency is misleading for reviewers and future maintainers. Please either:
autoRecallTimeoutMsto the config schemaThe constant name also doesn't match:
AUTO_RECALL_TIMEOUT_MSvsDEFAULT_AUTO_RECALL_TIMEOUT_MS.