Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 70 additions & 61 deletions examples/openclaw-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
quickRecallPrecheck,
resolvePythonCommand,
prepareLocalPort,
withTimeout,
} from "./process-manager.js";
import { createMemoryOpenVikingContextEngine } from "./context-engine.js";

Expand Down Expand Up @@ -430,6 +431,8 @@ const contextEnginePlugin = {

const prependContextParts: string[] = [];

Copy link
Contributor

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:

"Added DEFAULT_AUTO_RECALL_TIMEOUT_MS (5000ms) to config"
"Added autoRecallTimeoutMs config field with UI support"

But the actual code only adds a hardcoded local constant AUTO_RECALL_TIMEOUT_MS here. 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:

  1. Update the PR description to remove claims about config/UI changes, or
  2. Actually implement the configurable timeout by adding autoRecallTimeoutMs to the config schema

The constant name also doesn't match: AUTO_RECALL_TIMEOUT_MS vs DEFAULT_AUTO_RECALL_TIMEOUT_MS.

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 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 cfg.autoRecallTimeoutMs here instead of the hardcoded constant.

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) {
Expand All @@ -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`,
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 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)}`);
}
}
}
Expand Down