Skip to content

Fix OpenClaw plugin recall assembly#1676

Open
EasionF wants to merge 1 commit intovolcengine:mainfrom
EasionF:fix-openclaw-plugin-recall-assembly
Open

Fix OpenClaw plugin recall assembly#1676
EasionF wants to merge 1 commit intovolcengine:mainfrom
EasionF:fix-openclaw-plugin-recall-assembly

Conversation

@EasionF
Copy link
Copy Markdown

@EasionF EasionF commented Apr 24, 2026

Fix OpenClaw plugin recall assembly

Summary

This patch changes the OpenViking OpenClaw plugin recall path so context-engine mode no longer injects recalled memories through before_prompt_build / prependContext.

Instead, auto-recall is owned by assemble() and added as a short internal context message alongside archive/session context. The recall payload is also shortened and filtered before injection.

Problem

The previous plugin path could inject recalled memory as plain text during before_prompt_build. In string-content model pipelines this can surface raw recall context in the final prompt/answer, increase prompt pollution, and duplicate recall work even when the context engine owns assembly.

Changes

  • Skip before_prompt_build recall injection whenever a context engine is registered.
    • Move recall lookup into context-engine assemble().
    • Inject only short, normalized recall facts into assembled context messages.
    • Prefer abstract recall by default when the option is not explicitly configured.
    • Filter instruction-like preference memories unless the query is asking for preferences.
    • Update focused unit tests for context-engine assembly and normal plugin flow.

Validation

Focused plugin tests passed:

npm test -- --run tests/ut/context-engine-assemble.test.ts tests/ut/plugin-normal-flow-real-

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 24, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🏅 Score: 85
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: Move recall into context-engine assemble()

Relevant files:

  • examples/openclaw-plugin/context-engine.ts
  • examples/openclaw-plugin/tests/ut/context-engine-assemble.test.ts

Sub-PR theme: Skip before_prompt_build recall when context engine is registered

Relevant files:

  • examples/openclaw-plugin/index.ts
  • examples/openclaw-plugin/tests/ut/plugin-normal-flow-real-server.test.ts

Sub-PR theme: Filter instructional preferences and adjust recallPreferAbstract default

Relevant files:

  • examples/openclaw-plugin/memory-ranking.ts
  • examples/openclaw-plugin/config.ts

⚡ Recommended focus areas for review

Unused scoreThreshold parameter in pickMemoriesForInjection

The pickMemoriesForInjection function still accepts a scoreThreshold parameter but no longer uses it to filter memories, which may lead to lower-scoring memories being included unexpectedly.

export function pickMemoriesForInjection(
  items: FindResultItem[],
  limit: number,
  queryText: string,
  scoreThreshold: number = 0,
): FindResultItem[] {
  if (items.length === 0 || limit <= 0) {
    return [];
  }

  const query = buildRecallQueryProfile(queryText);
  const filteredItems = query.wantsPreference
    ? items
    : items.filter((item) => !isInstructionLikePreference(item));
  const candidateItems = filteredItems.length > 0 ? filteredItems : items;
  const sorted = [...candidateItems].sort((a, b) => rankForInjection(b, query) - rankForInjection(a, query));
Garbled comment (encoding issue)

Line 1058 contains a garbled Chinese comment due to encoding mismatch.

// 鍚堝苟涓や釜浣嶇疆鐨勭粨鏋滐紝鍘婚噸

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Add timeout to API calls in assemble recall

Add timeout logic to the client.find() and client.read() calls in the assemble
recall path, similar to the AUTO_RECALL_TIMEOUT_MS pattern used in the plugin's
before_prompt_build hook, to improve API resilience.

examples/openclaw-plugin/context-engine.ts [796-806]

+// Add a timeout helper at the top of the file or use a shared utility
+function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {
+  return Promise.race([
+    promise,
+    new Promise<never>((_, reject) => setTimeout(() => reject(new Error(message)), ms)),
+  ]);
+}
+
+// Then use it in buildAssembleRecallFacts:
 const [userSettled, agentSettled] = await Promise.allSettled([
-  client.find(queryText, {
-    targetUri: "viking://user/memories",
-    limit: candidateLimit,
-    scoreThreshold: 0,
-  }, agentId),
-  client.find(queryText, {
-    targetUri: "viking://agent/memories",
-    limit: candidateLimit,
-    scoreThreshold: 0,
-  }, agentId),
+  withTimeout(
+    client.find(queryText, { targetUri: "viking://user/memories", limit: candidateLimit, scoreThreshold: 0 }, agentId),
+    AUTO_RECALL_TIMEOUT_MS,
+    "openviking: assemble user memories search timeout",
+  ),
+  withTimeout(
+    client.find(queryText, { targetUri: "viking://agent/memories", limit: candidateLimit, scoreThreshold: 0 }, agentId),
+    AUTO_RECALL_TIMEOUT_MS,
+    "openviking: assemble agent memories search timeout",
+  ),
 ]);
Suggestion importance[1-10]: 6

__

Why: The suggestion adds timeout logic to client.find() calls in the assemble recall path, aligning with the existing timeout pattern in before_prompt_build and improving API resilience. It's a useful robustness improvement.

Low

@EasionF EasionF force-pushed the fix-openclaw-plugin-recall-assembly branch from 91a9658 to 1940048 Compare April 24, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants