Skip to content

fix(memory-core): retry narrative message reads - #89091

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
bennewell35:ben/issue-87306-dreaming-narrative-text-retry
Jun 11, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
bennewell35:ben/issue-87306-dreaming-narrative-text-retry

Conversation

@bennewell35

@bennewell35 bennewell35 commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Refs #87306

Summary

  • Retry the narrative session message read after a successful run when the first read has no extractable assistant text.
  • Keep the existing fallback path unchanged after bounded settle attempts: immediate read, then 50 ms, 150 ms, 300 ms, and 750 ms waits.
  • Add fake-timer regression coverage for both delayed assistant-text persistence and the all-attempts-empty fallback path.

Evidence map

  • Changed surface: memory-core dreaming narrative post-run message extraction in extensions/memory-core/src/dreaming-narrative.ts.
  • Entry point and callers: generateAndAppendDreamNarrative, called by dreaming phase/session orchestration.
  • Owner boundary: uses the existing SubagentSurface.getSessionMessages API; no SDK, provider, persistence schema, config, or dependency change.
  • Sibling behavior: timeout, unavailable-model retry, cleanup, detached narrative, and fallback diary paths remain covered by existing tests in the touched file.
  • Scope: this fixes same-run post-waitForRun message visibility lag; archived-session recovery remains out of scope.
  • Security/config: no auth, secrets, trust-boundary, filesystem path, dependency, or config changes.

Verification

  • git diff --check
  • fnm exec --using 22 ./node_modules/.bin/oxfmt --check --threads=1 extensions/memory-core/src/dreaming-narrative.ts extensions/memory-core/src/dreaming-narrative.test.ts
  • fnm exec --using 22 ./node_modules/.bin/oxlint --tsconfig config/tsconfig/oxlint.extensions.json extensions/memory-core/src/dreaming-narrative.ts extensions/memory-core/src/dreaming-narrative.test.ts
  • fnm exec --using 22 node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions-test.tsbuildinfo
  • fnm exec --using 22 node scripts/run-vitest.mjs extensions/memory-core/src/dreaming-narrative.test.ts --reporter=verbose
  • fnm exec --using 22 node scripts/changed-lanes.mjs --base upstream/main --head HEAD --json
  • OPENCLAW_QA_KEEP_TEMP=1 fnm exec --using 22 node scripts/run-node.mjs qa suite --provider-mode mock-openai --scenario memory-dreaming-sweep --concurrency 1 --fast --output-dir .artifacts/qa-e2e/pr-89091-dreaming-proof-final

Real behavior proof

Behavior addressed: memory-core: narrative generation produced no text warnings could fire, and synthetic fallback diary text could be written, when assistant text existed but was not visible on the first post-run session message read.

Real environment tested: Local OpenClaw source checkout on branch ben/issue-87306-dreaming-narrative-text-retry at b5427da73baac07d7b58f6791d7d9db9fa2856a0, Node v22.22.1, macOS local dev machine, using the repo QA suite with qa-channel + qa-lab bus + real gateway child + mock-openai provider.

Exact steps or command run after this patch: Ran the focused file checks listed in Verification, then ran OPENCLAW_QA_KEEP_TEMP=1 fnm exec --using 22 node scripts/run-node.mjs qa suite --provider-mode mock-openai --scenario memory-dreaming-sweep --concurrency 1 --fast --output-dir .artifacts/qa-e2e/pr-89091-dreaming-proof-final.

Evidence after fix: The QA report at .artifacts/qa-e2e/pr-89091-dreaming-proof-final/qa-suite-report.md reported Passed: 1, Failed: 0, and Memory dreaming sweep: pass with details {"promotedTotal":1,"shortTermCount":3,"phaseSignalCount":3,"lightSleep":true,"remSleep":true}. The preserved temp runtime at /tmp/openclaw/openclaw-qa-suite-vF59oC showed workspace/DREAMS.md contained protocol-note diary entries for light/rem/deep phases, gateway.stdout.log contained memory-core: dream diary entry written for light phase, memory-core: dream diary entry written for rem phase, and memory-core: dream diary entry written for deep phase, and rg "produced no text|A memory trace surfaced" across gateway.stdout.log, gateway.stderr.log, and workspace/DREAMS.md returned no matches.

Observed result after fix: The real gateway sweep wrote diary entries for light, rem, and deep phases from assistant text. It did not emit the produced no text warning and did not write the synthetic fallback text A memory trace surfaced, but details were unavailable in this run. The touched-file shard also reported Test Files 1 passed (1) and Tests 53 passed (53).

What was not tested: live dreaming cron with a real local LLM/Ollama session, broad Testbox, or archived-session recovery.

Copilot AI review requested due to automatic review settings June 1, 2026 13:19
@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves reliability of dream narrative generation by retrying session message reads briefly so the final assistant text has time to persist before falling back to synthetic diary text.

Changes:

  • Added a short “settling” retry loop for reading narrative text from session messages.
  • Centralized the session message fetch limit and introduced configurable settle delays.
  • Added a test ensuring delayed assistant output is eventually used instead of fallback text.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
extensions/memory-core/src/dreaming-narrative.ts Adds retry-with-delays logic to re-fetch session messages until assistant narrative content becomes available.
extensions/memory-core/src/dreaming-narrative.test.ts Adds test coverage for the delayed-persistence scenario to prevent premature fallback diary entries.

Comment on lines +365 to +368
for (let attempt = 0; attempt <= NARRATIVE_MESSAGE_SETTLE_DELAYS_MS.length; attempt += 1) {
if (attempt > 0) {
await waitForNarrativeMessagesToSettle(NARRATIVE_MESSAGE_SETTLE_DELAYS_MS[attempt - 1]);
}
Comment on lines +703 to +713
await generateAndAppendDreamNarrative({
subagent,
workspaceDir,
data: {
phase: "light",
snippets: ["The narrative assistant persisted after the run completed."],
},
nowMs: Date.parse("2026-04-05T03:00:00Z"),
timezone: "UTC",
logger,
});
Comment on lines +715 to +723
expect(subagent.getSessionMessages).toHaveBeenCalledTimes(2);
expect(subagent.getSessionMessages).toHaveBeenNthCalledWith(1, {
sessionKey: expect.stringContaining("dreaming-narrative-light-"),
limit: 5,
});
expect(subagent.getSessionMessages).toHaveBeenNthCalledWith(2, {
sessionKey: expect.stringContaining("dreaming-narrative-light-"),
limit: 5,
});
Comment on lines +685 to +700
it("waits for persisted assistant text before falling back", async () => {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-narrative-");
const subagent = createMockSubagent("");
subagent.getSessionMessages
.mockResolvedValueOnce({
messages: [{ role: "user", content: "prompt" }],
})
.mockResolvedValueOnce({
messages: [
{ role: "user", content: "prompt" },
{
role: "assistant",
content: [{ type: "text", text: "The delayed diary text finally settled." }],
},
],
});
@clawsweeper

clawsweeper Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 1, 2026, 12:22 PM ET / 16:22 UTC.

Summary
The PR retries memory-core Dream Diary session-message reads after a successful narrative run before writing fallback text, with fake-timer regression coverage.

PR surface: Source +38, Tests +87. Total +125 across 2 files.

Reproducibility: yes. The linked report gives concrete local LLM/Ollama cron reproduction steps, and current main's source performs a single immediate session read before fallback; I did not rerun that live environment here.

Review metrics: none identified.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] Residual proof gap: the supplied real-gateway proof uses mock-openai rather than the reporter's live local LLM/Ollama cron environment, so maintainers may still want one live local LLM smoke before merge.

Maintainer options:

  1. Decide the mitigation before merge
    Land the bounded memory-core retry with the added regression coverage; optional live local LLM proof can reduce residual uncertainty but no automated code repair is needed.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No ClawSweeper repair is indicated; the remaining action is a maintainer merge decision, optionally after live local LLM smoke proof.

Security
Cleared: The diff only changes memory-core read timing and tests; it does not touch auth, secrets, dependencies, workflows, package resolution, or a trust boundary.

Review details

Best possible solution:

Land the bounded memory-core retry with the added regression coverage; optional live local LLM proof can reduce residual uncertainty but no automated code repair is needed.

Do we have a high-confidence way to reproduce the issue?

Yes. The linked report gives concrete local LLM/Ollama cron reproduction steps, and current main's source performs a single immediate session read before fallback; I did not rerun that live environment here.

Is this the best way to solve the issue?

Yes. The PR is the narrowest maintainable fix for the plugin-owned path because it preserves the existing fallback and SDK API while retrying the same session reader; changing agent.wait into a persistence barrier would be broader and riskier for this symptom.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against c053b9029015.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix real gateway QA output with preserved logs showing diary writes and no fallback warning/text; mock-openai leaves only a live local LLM residual, not a missing-proof gate.

Label justifications:

  • P2: This is a normal-priority memory-core bug fix for misleading Dream Diary fallback warnings with limited blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body supplies after-fix real gateway QA output with preserved logs showing diary writes and no fallback warning/text; mock-openai leaves only a live local LLM residual, not a missing-proof gate.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix real gateway QA output with preserved logs showing diary writes and no fallback warning/text; mock-openai leaves only a live local LLM residual, not a missing-proof gate.
Evidence reviewed

PR surface:

Source +38, Tests +87. Total +125 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 42 4 +38
Tests 1 87 0 +87
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 129 4 +125

What I checked:

Likely related people:

  • vincentkoc: Recent history shows multiple memory-core Dream Diary and SDK-seam changes, including current compact-root blame and the dreaming narrative SDK seam update. (role: recent area contributor; confidence: high; commits: c0e49a2c5253, b78713a36391, 8a4a63ca076e; files: extensions/memory-core/src/dreaming-narrative.ts, extensions/memory-core/src/dreaming-phases.ts)
  • steipete: History and shortlog show substantial memory-core/dreaming and test stewardship across the central files and adjacent release/test work. (role: heavy adjacent contributor; confidence: medium; commits: e93216080aa1, ac12b0701b5b, 3417dbabf43e; files: extensions/memory-core/src/dreaming-narrative.ts, extensions/memory-core/src/dreaming-phases.ts, src/gateway/server-plugins.ts)
  • mbelinky: History shows bounded Dream Diary behavior work, including narrative idempotency and request-scoped fallback/backfill changes near this path. (role: feature-history contributor; confidence: medium; commits: bed53c77aa2a, 46f8c4dfd5f9, dbf5960bd96a; files: extensions/memory-core/src/dreaming-narrative.ts, extensions/memory-core/src/dreaming-phases.ts)
  • CodeForgeNet: The gateway subagent runtime path used by memory-core was recently adjusted to always send idempotency keys and has adjacent tests for the same plugin subagent surface. (role: adjacent gateway subagent contributor; confidence: medium; commits: 10cd000f6085; files: src/gateway/server-plugins.ts, src/gateway/server-plugins.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 1, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 1, 2026
@bennewell35

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added copied terminal output in the Real behavior proof section showing session_reads=2, delayed assistant text written, no produced no text warning, and no fallback diary text.

@clawsweeper

clawsweeper Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added the P2 Normal backlog priority with limited blast radius. label Jun 1, 2026
@bennewell35

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated after the real QA lane showed the original 500 ms settle window was still too short for REM/deep narratives. The patch now uses an immediate read plus four bounded settle reads, adds the all-attempts-empty fallback regression test, and the PR body includes the final real-gateway memory-dreaming-sweep proof showing light/rem/deep diary writes with no fallback warning or synthetic fallback text.

@clawsweeper

clawsweeper Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 1, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label Jun 1, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label Jun 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. proof: supplied External PR includes structured after-fix real behavior proof. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 1, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 1, 2026
@vincentkoc vincentkoc self-assigned this Jun 11, 2026
@vincentkoc
vincentkoc force-pushed the ben/issue-87306-dreaming-narrative-text-retry branch from b5427da to 5e70323 Compare June 11, 2026 11:35
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer verification on current main:

  • Reproduced the successful run/message visibility race and confirmed the bounded settle loop observes delayed assistant text before falling back.
  • The retry budget remains bounded (immediate read plus 50/150/300/750 ms), only runs after a successful narrative run, and preserves the existing synthetic fallback when text never appears.
  • node scripts/run-vitest.mjs extensions/memory-core/src/dreaming-narrative.test.ts — 53 passed.
  • Autoreview clean, no accepted/actionable findings.

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 11, 2026
@vincentkoc
vincentkoc merged commit cdb55b3 into openclaw:main Jun 11, 2026
155 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 12, 2026
* fix(memory-core): retry narrative message reads

* fix(memory-core): wait longer for narrative text
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Jun 17, 2026
* fix(memory-core): retry narrative message reads

* fix(memory-core): wait longer for narrative text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants