You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug: Reflection self-triggers in a loop — same session generates 4 near-identical reflections
Related to #357 (OPENCLAW_EXTENSION_API_PATH workaround).
Summary
After resolving the OPENCLAW_EXTENSION_API_PATH issue from #357, the memory-reflection feature works but enters a self-triggering loop: every time a reflection completes writing, it immediately re-triggers the command:new hook for the same session, producing 4 near-identical reflection documents within ~2 minutes.
All 4 files have different md5 hashes (LLM re-generation produces slight wording variations) but are substantively identical: same session context, same conclusions, same decisions, same lessons.
3. No external trigger
No user messages triggered the re-fires (no Telegram messages, no webchat, no other command:new events in the 22:06–22:09 window besides the reflection hook's own)
No gateway restart occurred during this window (restart happened later at 22:13)
Heartbeat/cron timer arming every 60s does not trigger command:new
The runMemoryReflection hook registered on command:new (line ~3365 in index.ts) has no re-entry guard. After generating a reflection, the hook:
Writes a reflection .md file to memory/reflections/YYYY-MM-DD/
Writes an entry to memory/YYYY-MM-DD.md (daily log)
Stores vectors in LanceDB
Possibly triggers a side-effect (file watcher, session update, or embedded runner side-effect) that causes OpenClaw to re-emit command:new for the same session
The 1-2ms gap between wrote and hook start strongly suggests the re-trigger is synchronous with the hook's own write operations, not an external event.
Suggested fix
Add a session-level re-entry guard to runMemoryReflection:
// At module level or in reflection stateconstreflectionInProgress=newSet<string>();construnMemoryReflection=async(event: any)=>{constsessionKey=typeofevent.sessionKey==="string" ? event.sessionKey : "";// Re-entry guardif(sessionKey&&reflectionInProgress.has(sessionKey)){api.logger.info(`memory-reflection: re-entry detected for ${sessionKey}, skipping`);return;}if(sessionKey)reflectionInProgress.add(sessionKey);try{// ... existing logic ...}finally{if(sessionKey)reflectionInProgress.delete(sessionKey);// ... existing cleanup ...}};
Alternatively, add a cooldown mechanism that prevents reflection from running again for the same session within a configurable window (e.g., 5 minutes).
Impact
Resource waste: 4x the LLM API calls, 4x the LanceDB writes, 4x the disk I/O for every session transition
Cost: Each reflection run consumes tokens. 4 redundant runs = 3x unnecessary cost per session
Data quality: 3 near-duplicate reflection entries per session pollute the memory store and weekly review aggregation
User experience: Reflection output (which may be surfaced to users) becomes noisy with duplicate content
Bug: Reflection self-triggers in a loop — same session generates 4 near-identical reflections
Related to #357 (OPENCLAW_EXTENSION_API_PATH workaround).
Summary
After resolving the
OPENCLAW_EXTENSION_API_PATHissue from #357, thememory-reflectionfeature works but enters a self-triggering loop: every time a reflection completes writing, it immediately re-triggers thecommand:newhook for the same session, producing 4 near-identical reflection documents within ~2 minutes.Environment
OPENCLAW_EXTENSION_API_PATHset per Compatibility issue: legacy openclaw/extension-api runtime loading on newer OpenClaw builds #357 workaroundEvidence
1. Gateway log timeline (from
/tmp/openclaw/openclaw-2026-03-26.log)All 4 reflections share the same
sessionId=dea76b16-f754-4b32-937b-78516085730dandsessionKey=agent:main:telegram:default:direct:667042947:Every single reflection completion is followed by an immediate (1-2ms)
hook startfor the same session.2. Output files
All 4 files have different md5 hashes (LLM re-generation produces slight wording variations) but are substantively identical: same session context, same conclusions, same decisions, same lessons.
3. No external trigger
command:newevents in the 22:06–22:09 window besides the reflection hook's own)command:newReproduction
OPENCLAW_EXTENSION_API_PATHper Compatibility issue: legacy openclaw/extension-api runtime loading on newer OpenClaw builds #357selfImprovement.enabled: true,memoryReflection.enabled: true)/newor let the session naturally transitionRoot cause hypothesis
The
runMemoryReflectionhook registered oncommand:new(line ~3365 inindex.ts) has no re-entry guard. After generating a reflection, the hook:.mdfile tomemory/reflections/YYYY-MM-DD/memory/YYYY-MM-DD.md(daily log)command:newfor the same sessionThe 1-2ms gap between
wroteandhook startstrongly suggests the re-trigger is synchronous with the hook's own write operations, not an external event.Suggested fix
Add a session-level re-entry guard to
runMemoryReflection:Alternatively, add a cooldown mechanism that prevents reflection from running again for the same session within a configurable window (e.g., 5 minutes).
Impact