Repository navigation
fix(memory-core): retry narrative message reads - #89091
vincentkoc merged 2 commits into
Conversation
There was a problem hiding this comment.
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. |
| 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]); | ||
| } |
| 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, | ||
| }); |
| 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, | ||
| }); |
| 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." }], | ||
| }, | ||
| ], | ||
| }); |
|
Codex review: needs maintainer review before merge. Reviewed June 1, 2026, 12:22 PM ET / 16:22 UTC. Summary 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 follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest 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 changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +38, Tests +87. Total +125 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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 re-review Added copied terminal output in the Real behavior proof section showing |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@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 |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
b5427da to
5e70323
Compare
|
Maintainer verification on current
|
* fix(memory-core): retry narrative message reads * fix(memory-core): wait longer for narrative text
* fix(memory-core): retry narrative message reads * fix(memory-core): wait longer for narrative text
Refs #87306
Summary
Evidence map
extensions/memory-core/src/dreaming-narrative.ts.generateAndAppendDreamNarrative, called by dreaming phase/session orchestration.SubagentSurface.getSessionMessagesAPI; no SDK, provider, persistence schema, config, or dependency change.waitForRunmessage visibility lag; archived-session recovery remains out of scope.Verification
git diff --checkfnm exec --using 22 ./node_modules/.bin/oxfmt --check --threads=1 extensions/memory-core/src/dreaming-narrative.ts extensions/memory-core/src/dreaming-narrative.test.tsfnm 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.tsfnm exec --using 22 node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions-test.tsbuildinfofnm exec --using 22 node scripts/run-vitest.mjs extensions/memory-core/src/dreaming-narrative.test.ts --reporter=verbosefnm exec --using 22 node scripts/changed-lanes.mjs --base upstream/main --head HEAD --jsonOPENCLAW_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-finalReal behavior proof
Behavior addressed:
memory-core: narrative generation produced no textwarnings 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-retryatb5427da73baac07d7b58f6791d7d9db9fa2856a0, Nodev22.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.mdreportedPassed: 1,Failed: 0, andMemory dreaming sweep: passwith details{"promotedTotal":1,"shortTermCount":3,"phaseSignalCount":3,"lightSleep":true,"remSleep":true}. The preserved temp runtime at/tmp/openclaw/openclaw-qa-suite-vF59oCshowedworkspace/DREAMS.mdcontained protocol-note diary entries for light/rem/deep phases,gateway.stdout.logcontainedmemory-core: dream diary entry written for light phase,memory-core: dream diary entry written for rem phase, andmemory-core: dream diary entry written for deep phase, andrg "produced no text|A memory trace surfaced"acrossgateway.stdout.log,gateway.stderr.log, andworkspace/DREAMS.mdreturned 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 textwarning and did not write the synthetic fallback textA memory trace surfaced, but details were unavailable in this run.The touched-file shard also reportedTest Files 1 passed (1)andTests 53 passed (53).What was not tested: live dreaming cron with a real local LLM/Ollama session, broad Testbox, or archived-session recovery.