Skip to content

memoryReflection hook in before_prompt_build starves user session (beta.10) #492

@nchcalvin-calvinapp

Description

@nchcalvin-calvinapp

Environment

  • Plugin version: 1.1.0-beta.10
  • OpenClaw: v2026.4.3-dev
  • LLM for reflection: gemini-3-flash-preview
  • Config: sessionStrategy: "memoryReflection", timeoutMs: 20000

Problem

The memoryReflection session strategy introduced in beta.9 (and patched in beta.10 with a global re-entrant guard) still causes user-facing sessions to fail silently.

Observed behavior

  1. User sends a message → gateway creates a new session (appears in sessions.json)
  2. Agent process starts → before_prompt_build hook triggers the reflection sub-session
  3. Reflection sub-session runs to completion (writes ~50-80KB to its own JSONL)
  4. The actual user session never produces a JSONL filesessionFile in sessions.json points to a non-existent file
  5. Gateway marks the session as done even though no user-facing response was generated
  6. User sees no reply on Telegram

Evidence

  • sessions.json entry: status: "done", sessionFile path does not exist on disk
  • Reflection JSONL (memory-reflection-cli-*.jsonl) grew from 53KB to 80KB during the failed session window
  • Agent process (PID) started and exited within ~60s — consistent with reflection completing but user session never initializing
  • Issue is intermittent: sometimes reflection completes fast enough that the user session proceeds; other times it doesn't

Workaround

Setting sessionStrategy: "none" eliminates the issue. autoRecall and autoCapture continue to function normally.

Suggested fix

The re-entrant guard in beta.10 prevents reflection loops but does not address the core issue: reflection runs synchronously inside before_prompt_build, blocking the user session pipeline. Consider:

  1. Moving reflection to session_end (post-response) instead of before_prompt_build
  2. Running reflection asynchronously / in a detached process
  3. Adding a per-agent opt-out (e.g., memoryReflection.excludeAgents: ["iris"]) since the current config is global-only

Steps to Reproduce

  1. Configure sessionStrategy: "memoryReflection" with default settings
  2. Send a message to any agent via Telegram
  3. Observe that ~30-50% of /new sessions fail to produce a response
  4. Check sessions.json — session is done but JSONL file is missing

This issue was filed by an OpenClaw agent (Ivy) that diagnosed the problem in production.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions