Skip to content

Fix Codex memory recall and async commit reporting#2083

Open
yshishenya wants to merge 4 commits into
volcengine:mainfrom
yshishenya:fix/codex-memory-commit-task-poll
Open

Fix Codex memory recall and async commit reporting#2083
yshishenya wants to merge 4 commits into
volcengine:mainfrom
yshishenya:fix/codex-memory-commit-task-poll

Conversation

@yshishenya
Copy link
Copy Markdown

Summary

  • Tighten Codex auto-recall filtering so vague prompts and internal OpenClaw/Codex hook noise do not inject unrelated memory.
  • Add async commit task polling for Codex PreCompact and SessionStart commits, so hook output reports the actual extraction count instead of the immediate accepted response.
  • Document the new commit poll tuning knobs and add a live auto-recall probe script.

Verification

  • node --check examples/codex-memory-plugin/scripts/commit-task.mjs
  • node --check examples/codex-memory-plugin/scripts/pre-compact-capture.mjs
  • node --check examples/codex-memory-plugin/scripts/session-start-commit.mjs
  • node --check examples/codex-memory-plugin/scripts/config.mjs
  • Live Docker OpenViking v0.3.17 PreCompact regression: pre-compact commit cx-source-task-poll-regression-20260516 is committed; 2 memory item(s) extracted.
  • Live Docker OpenViking v0.3.17 SessionStart regression: OpenViking session cx-session-start-poll-regression-20260516 is committed; 1 memory item extracted.
  • Installed Codex plugin cache regression: pre-compact commit 96603c8c-755d-427a-9584-96bfdc247b65 is committed; 2 memory item(s) extracted.

@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: Tighten auto-recall filtering and add confidence gates

Relevant files:

  • examples/codex-memory-plugin/scripts/auto-recall.mjs
  • examples/codex-memory-plugin/scripts/config.mjs
  • examples/codex-memory-plugin/README.md
  • examples/codex-memory-plugin/scripts/probe-auto-recall.mjs

Sub-PR theme: Add async commit task polling for extraction status reporting

Relevant files:

  • examples/codex-memory-plugin/scripts/commit-task.mjs
  • examples/codex-memory-plugin/scripts/pre-compact-capture.mjs
  • examples/codex-memory-plugin/scripts/session-start-commit.mjs
  • examples/codex-memory-plugin/scripts/config.mjs
  • examples/codex-memory-plugin/README.md
  • examples/codex-memory-plugin/VERIFICATION.md

Sub-PR theme: Add sanitization for captured turns to avoid injecting internal context

Relevant files:

  • examples/codex-memory-plugin/scripts/auto-capture.mjs
  • examples/codex-memory-plugin/scripts/pre-compact-capture.mjs

⚡ Recommended focus areas for review

Code Duplication

The sanitizeCapturedText function is duplicated in both auto-capture.mjs and pre-compact-capture.mjs. This creates maintenance overhead and risks divergent behavior if the function is updated in one place but not the other.

function sanitizeCapturedText(text) {
  let out = String(text || "");
  if (/^\s*You are running as a subagent\b/i.test(out)) return "";
  out = out
    .replace(/<relevant-memories>[\s\S]*?<\/relevant-memories>/gi, "")
    .replace(/<<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>[\s\S]*?<<<END_OPENCLAW_INTERNAL_CONTEXT>>>/g, "")
    .replace(/Conversation context \(untrusted metadata\):\s*```json[\s\S]*?```\s*/gi, "")
    .replace(/\[Inter-session message][\s\S]*?(?=\n\[[a-z]+]:|\n?$)/gi, "")
    .replace(/Full hook output saved to:\s*\S+/gi, "")
    .trim();
  if (/^(?:\[user]:\s*)*$/i.test(out)) return "";
  return out;
}
Code Duplication

The sanitizeCapturedText function is duplicated in both auto-capture.mjs and pre-compact-capture.mjs. This creates maintenance overhead and risks divergent behavior if the function is updated in one place but not the other.

function sanitizeCapturedText(text) {
  let out = String(text || "");
  if (/^\s*You are running as a subagent\b/i.test(out)) return "";
  out = out
    .replace(/<relevant-memories>[\s\S]*?<\/relevant-memories>/gi, "")
    .replace(/<<<BEGIN_OPENCLAW_INTERNAL_CONTEXT>>>[\s\S]*?<<<END_OPENCLAW_INTERNAL_CONTEXT>>>/g, "")
    .replace(/Conversation context \(untrusted metadata\):\s*```json[\s\S]*?```\s*/gi, "")
    .replace(/\[Inter-session message][\s\S]*?(?=\n\[[a-z]+]:|\n?$)/gi, "")
    .replace(/Full hook output saved to:\s*\S+/gi, "")
    .trim();
  if (/^(?:\[user]:\s*)*$/i.test(out)) return "";
  return out;
}

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Add timeout to child process spawn

Add a timeout to the spawned child process in runAutoRecall to prevent hanging
indefinitely. Use a timeout (e.g., 30 seconds) and kill the child process if it
exceeds the timeout.

examples/codex-memory-plugin/scripts/probe-auto-recall.mjs [56-75]

-function runAutoRecall(prompt) {
+function runAutoRecall(prompt, timeoutMs = 30000) {
   return new Promise((resolve, reject) => {
     const child = spawn(process.execPath, [autoRecallPath], {
       env: { ...process.env },
       stdio: ["pipe", "pipe", "pipe"],
     });
     let stdout = "";
     let stderr = "";
+    let timedOut = false;
+
+    const timeout = setTimeout(() => {
+      timedOut = true;
+      child.kill("SIGTERM");
+      reject(new Error(`auto-recall timed out after ${timeoutMs}ms`));
+    }, timeoutMs);
+
     child.stdout.on("data", (chunk) => { stdout += chunk; });
     child.stderr.on("data", (chunk) => { stderr += chunk; });
-    child.on("error", reject);
+    child.on("error", (err) => {
+      if (!timedOut) {
+        clearTimeout(timeout);
+        reject(err);
+      }
+    });
     child.on("close", (code) => {
+      if (timedOut) return;
+      clearTimeout(timeout);
       if (code !== 0) {
         reject(new Error(`auto-recall exited ${code}: ${stderr || stdout}`));
         return;
       }
       resolve(stdout.trim());
     });
     child.stdin.end(JSON.stringify({ prompt }));
   });
 }
Suggestion importance[1-10]: 5

__

Why: Adding a timeout prevents the probe from hanging indefinitely, improving robustness. This is a useful enhancement but not a critical bug fix, so it receives a moderate score.

Low

@yshishenya yshishenya force-pushed the fix/codex-memory-commit-task-poll branch from 127e874 to 13d7b95 Compare May 16, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant