openclaw - ✅(Solved) Fix [Bug]: Dreaming sweep re-triggers on every heartbeat instead of once per cron schedule [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#65705Fetched 2026-04-14 05:40:45
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
1
Timeline (top)
closed ×1commented ×1cross-referenced ×1labeled ×1
  • What happens: The openclaw_memory_core_short_te rm_promotion_dream system event fires at 3am via cron, but the before_agent_reply hook re-detects it on every subsequent
    heartbeat, running a full sweep every ~30 minutes indefinitely
  • Evidence: 84 sweeps since April 10, gateway log shows dreaming promotion complete every ~30 minutes 24/7
  • Impact: 246 dream diary subagent sessions spawned in 2 days across 3 workspaces (main, researcher, reviewer), 6 diary entries per sweep
  • Version: OpenClaw 2026.2.9

Root Cause

  • What happens: The openclaw_memory_core_short_te rm_promotion_dream system event fires at 3am via cron, but the before_agent_reply hook re-detects it on every subsequent
    heartbeat, running a full sweep every ~30 minutes indefinitely
  • Evidence: 84 sweeps since April 10, gateway log shows dreaming promotion complete every ~30 minutes 24/7
  • Impact: 246 dream diary subagent sessions spawned in 2 days across 3 workspaces (main, researcher, reviewer), 6 diary entries per sweep
  • Version: OpenClaw 2026.2.9

Fix Action

Fixed

PR fix notes

PR #66139: fix(memory-core): run Dreaming once per cron schedule

Description (problem / solution / changelog)

Summary

  • Problem: managed Dreaming could re-trigger on later heartbeat turns even after the cron event had already been consumed.
  • Why it matters: this creates repeated empty Dreaming-related sessions and extra sweep churn instead of running once per schedule.
  • What changed: gate the Dreaming heartbeat trigger on a real pending queued cron:* Dreaming system event, with isolated-heartbeat fallback to the base session queue.
  • What did NOT change (scope boundary): this does not broaden into the separate cron-service-unavailable reconciliation issue.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #65705
  • Related #65652
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: the before_agent_reply Dreaming hook treated the rendered heartbeat prompt text as the trigger source, so the same Dreaming token could be re-detected on later heartbeats even after the original cron event had already been handled.
  • Missing detection / guardrail: the trigger path did not verify that a live queued Dreaming cron:* system event still existed for the session being processed.
  • Contributing context (if known): isolated heartbeat runs use a sibling :heartbeat session while cron events stay queued on the base session.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/memory-core/src/dreaming.test.ts
  • Scenario the test should lock in: stale Dreaming token text without a pending cron event must not retrigger; isolated heartbeat sessions must still honor the base-session queued cron event.
  • Why this is the smallest reliable guardrail: the bug lives at the plugin hook plus session-queue seam, not in the cron expression math itself.
  • Existing test that already covers this (if any): src/infra/heartbeat-runner.ghost-reminder.test.ts already covers the core queue-drain contract for cron-tagged system events.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Dreaming now runs once per cron schedule instead of replaying on subsequent ordinary heartbeats after the scheduled event has already been consumed.

Diagram (if applicable)

Before:
[cron fires] -> [heartbeat prompt includes Dreaming token] -> [Dreaming runs]
[next heartbeat still contains replayed token text] -> [Dreaming runs again]

After:
[cron fires] -> [queued Dreaming cron event exists] -> [Dreaming runs once]
[next heartbeat without queued cron event] -> [no Dreaming replay]

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: local repo worktree
  • Model/provider: N/A
  • Integration/channel (if any): heartbeat / cron / memory-core Dreaming
  • Relevant config (redacted): memory-core Dreaming enabled with managed cron schedule; isolated heartbeat path also exercised

Steps

  1. Queue a managed Dreaming cron system event for the main session.
  2. Run a heartbeat that contains the Dreaming token and let the Dreaming hook handle it.
  3. Run a later heartbeat with the same token text but without a pending queued cron event.

Expected

  • Dreaming runs only for the heartbeat backed by the queued cron event.
  • Later heartbeats do not retrigger unless a new cron event is actually pending.

Actual

  • Before the fix, later heartbeats could retrigger Dreaming from stale/replayed token text alone.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: targeted Dreaming regression tests, isolated-heartbeat queue behavior, and core cron-event drain behavior.
  • Edge cases checked: base-session queued cron events for isolated :heartbeat runs; replay-shaped stale prompt text without a pending event.
  • What you did not verify: a full live gateway reproduce-before / verify-after run on this machine.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Risks and Mitigations

  • Risk: a future synthetic before_agent_reply caller that omits sessionKey would suppress Dreaming instead of triggering it.
    • Mitigation: current production wiring passes sessionKey, and suppression is safer than replay.

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • extensions/memory-core/src/dreaming.test.ts (modified, +132/-3)
  • extensions/memory-core/src/dreaming.ts (modified, +37/-0)
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

  • What happens: The openclaw_memory_core_short_te rm_promotion_dream system event fires at 3am via cron, but the before_agent_reply hook re-detects it on every subsequent
    heartbeat, running a full sweep every ~30 minutes indefinitely
  • Evidence: 84 sweeps since April 10, gateway log shows dreaming promotion complete every ~30 minutes 24/7
  • Impact: 246 dream diary subagent sessions spawned in 2 days across 3 workspaces (main, researcher, reviewer), 6 diary entries per sweep
  • Version: OpenClaw 2026.2.9

Steps to reproduce

set dreaming.enabled: true

Expected behavior

Dream sequence runs once per cron schedule

Actual behavior

multiple sweeps across every heartbeat

OpenClaw version

2026.2.9

Operating system

macos 26.4.1

Install method

npm global

Model

codex-gpt-5.3-codex

Provider / routing chain

openclaw -> codex

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The before_agent_reply hook likely needs to be modified to prevent re-detection of the __openclaw_memory_core_short_term_promotion_dream__ system event on every heartbeat.

Guidance

  • Review the before_agent_reply hook implementation to understand why it's re-detecting the system event on every heartbeat, potentially causing an infinite loop of sweeps.
  • Investigate the event detection logic to determine if there's a way to mark the event as "handled" or "processed" after the initial sweep, preventing subsequent re-detections.
  • Consider adding a flag or cache to track whether the dream sequence has already run for a given cron schedule, allowing the hook to skip re-detection if the flag is set.
  • Examine the cron schedule configuration to ensure it's correctly set up to run the dream sequence only once at 3am, and not triggering the hook on every heartbeat.

Example

No code snippet can be provided without more context on the before_agent_reply hook implementation.

Notes

The issue seems to be related to the interaction between the cron schedule, the before_agent_reply hook, and the event detection logic. Without more information on the specific implementation, it's challenging to provide a definitive fix.

Recommendation

Apply a workaround by modifying the before_agent_reply hook to prevent re-detection of the system event, as this is the most likely cause of the issue. This will help mitigate the problem until a more permanent solution can be found.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Dream sequence runs once per cron schedule

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Dreaming sweep re-triggers on every heartbeat instead of once per cron schedule [1 pull requests, 1 comments, 2 participants]