Skip to content

fix(memory-core): denoise dreaming wrappers and promote grounded REM truths - #71837

Closed
vicenteliu wants to merge 3 commits into
openclaw:release/2026.4.23from
vicenteliu:fix/dreaming-denoise-grounded-deep-promotion
Closed

vicenteliu wants to merge 3 commits into
openclaw:release/2026.4.23from
vicenteliu:fix/dreaming-denoise-grounded-deep-promotion

Conversation

@vicenteliu

Copy link
Copy Markdown

Summary

This PR finishes the second half of the Dreaming denoise work and unblocks deep promotion.

It does three things:

  • strips wrapper/prompt scaffolding earlier during session text extraction
  • suppresses meta-language in REM (assistant, report, candidate, etc.) while biasing toward project-grade truths
  • feeds REM candidate truths back into grounded short-term candidates so deep promotion can actually pass

What changed

A. Strip session wrapper pollution earlier

Filtered from session extraction / corpus ingestion:

  • <relevant-memories>...</relevant-memories>
  • cron task envelopes
  • Current time:
  • NO_REPLY / SKIPPED
  • startup/reset bootstrap text
  • async exec receipts (System (untrusted): ...)

B. Denoise REM themes and truths

Added REM-side filtering for:

  • meta snippets
  • meta tags
  • direct Assistant: / User: transcript lines

Added positive REM bias for project-like signals:

  • decision
  • policy
  • workflow
  • plan
  • cadence
  • project
  • publish
  • strategy

Added negative suppression for engineering-noise terms:

  • build
  • plugin
  • warning
  • smoke
  • patch
  • fix
  • debug
  • test

C. Unblock deep promotion

Previously REM could produce better output, but deep still stayed at 0 because the candidate pipeline did not treat REM truths as strong enough promotion signals.

This PR:

  • records REM candidate truths as grounded short-term candidates
  • increases their effective signal strength
  • lets grounded + phase reinforcement count toward deep gating/diversity
  • adds grounded boost in ranking

Validation

Observed progression during rebuild validation:

  • session-corpus noise dropped substantially
  • REM stopped being dominated by assistant/user/report
  • REM started surfacing project-grade truths
  • deep promotion moved from passingCount=0 to passingCount=3

Example passing candidates after the final rebuild included:

  • Operation_Undock narrative positioning
  • Plot_Engine / OpenClaw Docker isolation status
  • gog gmail guardrail decision

Tests

Added or updated coverage for:

  • wrapper stripping in session extraction
  • concept-tag meta stopwords
  • REM preview filtering
  • transcript-line exclusion from lasting truths
  • deep gating with reinforced grounded candidates

Notes

  • Full Vitest runs were expensive in this workspace and repeatedly hit plugin timing / process kill limits, so validation here relied on focused smoke checks plus repeated rebuild verification against real dreaming artifacts.

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core agents Agent runtime and tooling size: L labels Apr 25, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Apr 25, 2026
@greptile-apps

greptile-apps Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR completes the second half of Dreaming denoise work across three areas: (1) session corpus scaffolding is stripped earlier during text extraction, (2) REM dreaming applies meta-tag and snippet filtering with positive/negative signal biases, and (3) REM candidate truths are fed back into the grounded short-term candidate pipeline to unblock deep promotion. The logic is well-structured and the new test coverage exercises the key filtering and gating scenarios.

Confidence Score: 4/5

Safe to merge; both findings are non-blocking style and design concerns with no runtime impact.

No P0 or P1 issues found. The two P2 findings are a redundant double-normalization call and a hardcoded signal count that may under-differentiate candidate quality, but neither causes incorrect behavior today. Score stays at 4 per P2-only ceiling.

extensions/memory-core/src/dreaming-phases.ts (signalCount hardcoding); src/memory-host-sdk/host/session-files.ts and packages/memory-host-sdk/src/host/session-files.ts (double normalization in extractSessionText)

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/memory-host-sdk/host/session-files.ts
Line: 338-341

Comment:
**Redundant double normalization in `extractSessionText`**

`stripSessionScaffolding` already calls `normalizeSessionText` internally before returning, so the `normalizeSessionText(stripped)` call here is redundant. `normalizeSessionText` is idempotent (collapses whitespace + trims), so there's no correctness issue, but the extra call is misleading — it implies `stripSessionScaffolding` returns un-normalized text. The same pattern exists in `packages/memory-host-sdk/src/host/session-files.ts` at the equivalent line.

```suggestion
  const stripped = stripSessionScaffolding(rawText, role);
  return stripped ? stripped : null;
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/memory-core/src/dreaming-phases.ts
Line: 1853

Comment:
**Hardcoded `signalCount: 3` ignores per-entry confidence**

Every REM candidate is recorded with the same fixed `signalCount: 3` regardless of its computed `calculateCandidateTruthConfidence(entry)` value. A candidate with confidence 0.46 (barely over the 0.45 threshold) receives the same grounded signal boost as one with confidence 0.95. If `recordGroundedShortTermCandidates` uses this count to increment `groundedCount`, weaker candidates gain the same effective weight as strong ones, which could allow marginally-passing truths to clear the deep gate as easily as high-confidence ones. Consider scaling `signalCount` proportionally to the computed score (e.g. `Math.round(1 + score * 2)`) or at least clamping to a lower floor for low-confidence candidates.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(memory-core): denoise dreaming wrapp..." | Re-trigger Greptile

Comment on lines 338 to +341
if (rawText === null) {
return null;
}
const stripped = stripInboundMetadataForUserRole(rawText, role);
const stripped = stripSessionScaffolding(rawText, role);

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.

P2 Redundant double normalization in extractSessionText

stripSessionScaffolding already calls normalizeSessionText internally before returning, so the normalizeSessionText(stripped) call here is redundant. normalizeSessionText is idempotent (collapses whitespace + trims), so there's no correctness issue, but the extra call is misleading — it implies stripSessionScaffolding returns un-normalized text. The same pattern exists in packages/memory-host-sdk/src/host/session-files.ts at the equivalent line.

Suggested change
if (rawText === null) {
return null;
}
const stripped = stripInboundMetadataForUserRole(rawText, role);
const stripped = stripSessionScaffolding(rawText, role);
const stripped = stripSessionScaffolding(rawText, role);
return stripped ? stripped : null;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/memory-host-sdk/host/session-files.ts
Line: 338-341

Comment:
**Redundant double normalization in `extractSessionText`**

`stripSessionScaffolding` already calls `normalizeSessionText` internally before returning, so the `normalizeSessionText(stripped)` call here is redundant. `normalizeSessionText` is idempotent (collapses whitespace + trims), so there's no correctness issue, but the extra call is misleading — it implies `stripSessionScaffolding` returns un-normalized text. The same pattern exists in `packages/memory-host-sdk/src/host/session-files.ts` at the equivalent line.

```suggestion
  const stripped = stripSessionScaffolding(rawText, role);
  return stripped ? stripped : null;
```

How can I resolve this? If you propose a fix, please make it concise.

endLine: entry.endLine,
snippet: entry.snippet,
score: calculateCandidateTruthConfidence(entry),
signalCount: 3,

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.

P2 Hardcoded signalCount: 3 ignores per-entry confidence

Every REM candidate is recorded with the same fixed signalCount: 3 regardless of its computed calculateCandidateTruthConfidence(entry) value. A candidate with confidence 0.46 (barely over the 0.45 threshold) receives the same grounded signal boost as one with confidence 0.95. If recordGroundedShortTermCandidates uses this count to increment groundedCount, weaker candidates gain the same effective weight as strong ones, which could allow marginally-passing truths to clear the deep gate as easily as high-confidence ones. Consider scaling signalCount proportionally to the computed score (e.g. Math.round(1 + score * 2)) or at least clamping to a lower floor for low-confidence candidates.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/memory-core/src/dreaming-phases.ts
Line: 1853

Comment:
**Hardcoded `signalCount: 3` ignores per-entry confidence**

Every REM candidate is recorded with the same fixed `signalCount: 3` regardless of its computed `calculateCandidateTruthConfidence(entry)` value. A candidate with confidence 0.46 (barely over the 0.45 threshold) receives the same grounded signal boost as one with confidence 0.95. If `recordGroundedShortTermCandidates` uses this count to increment `groundedCount`, weaker candidates gain the same effective weight as strong ones, which could allow marginally-passing truths to clear the deep gate as easily as high-confidence ones. Consider scaling `signalCount` proportionally to the computed score (e.g. `Math.round(1 + score * 2)`) or at least clamping to a lower floor for low-confidence candidates.

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac97488d17

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1854 to +1855
query: `__dreaming_rem__:${remDayBucket}`,
dayBucket: remDayBucket,

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.

P2 Badge Use stable REM query IDs for grounded candidate writes

The REM grounding path now writes candidates with a day-suffixed query key (__dreaming_rem__:${remDayBucket}), and recordGroundedShortTermCandidates hashes that query into queryHashes. If the same candidate is selected across multiple days, this creates a new synthetic query hash per day and inflates uniqueQueries/context diversity in rankShortTermPromotionCandidates, so entries can satisfy diversity gates without truly distinct recall contexts. Since deduping is already day-scoped via dayBucket, the query ID should stay stable across days.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep this PR open: current main does not implement the central REM-grounding change, and no merged or safe open replacement supersedes it. The branch is not merge-ready because real behavior proof is missing and the patch changes deep-promotion gates plus persisted grounded state in ways that need repair or explicit maintainer approval.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Yes for the PR-introduced concerns: source inspection shows phase hits being counted as gate/diversity inputs and REM candidates writing fixed, day-keyed grounded state. I did not live-reproduce the original Dreaming rebuild behavior in this read-only review.

Is this the best way to solve the issue?

No as submitted. The denoise direction is useful, but gate semantics, REM grounding identity/weight, current-main refresh, and real rebuild proof need repair or explicit approval before this is the best maintainable solution.

Security review:

Security review cleared: The diff is memory-core TypeScript and tests only; it does not change dependencies, workflows, lockfiles, secrets, packaging, permissions, or external code execution surfaces.

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-04-25T23:57:52Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • jalehman: Recent main history routes Dreaming corpus through session-corpus metadata and refactors transcript corpus access near this PR's ingestion boundary. (role: recent area contributor; confidence: medium; commits: da50a450d271, c24d266b2d09; files: extensions/memory-core/src/dreaming-phases.ts, packages/memory-host-sdk/src/host/session-files.ts)
  • vincentkoc: Recent history shows work on memory-core promotion hot paths, workspace key normalization, and session transcript path handling. (role: recent adjacent contributor; confidence: medium; commits: abd8a46b0a52, 7668ef2d3596, b3b5b08e67a2; files: extensions/memory-core/src/short-term-promotion.ts, extensions/memory-core/src/dreaming-phases.ts, packages/memory-host-sdk/src/host/session-files.ts)
  • SebTardif: History ties SebTardif to the REM light-staging behavior that the PR's REM grounding path builds on. (role: REM staging contributor; confidence: medium; commits: 8b42771aabd2; files: extensions/memory-core/src/dreaming-phases.ts, extensions/memory-core/src/short-term-promotion.ts)
  • steipete: Recent history shows memory-core dreams storage and broader state migration work touching the same persisted Dreaming and promotion surfaces. (role: recent state/storage contributor; confidence: medium; commits: 3f5e00184431, 538d36eaaaa6; files: extensions/memory-core/src/short-term-promotion.ts, extensions/memory-core/src/dreaming-phases.ts, packages/memory-host-sdk/src/host/session-files.ts)

Codex review notes: model internal, reasoning high; reviewed against 4fc504d321b6.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@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: sufficient ClawSweeper judged the real behavior proof convincing. labels May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 14, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 14, 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. P2 Normal backlog priority with limited blast radius. labels May 20, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@RomneyDa

Copy link
Copy Markdown
Member

Heads up: this PR needs to be updated against current main before the new required Dependency Guard check can pass.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 14, 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. 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 17, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 18, 2026
@clawsweeper

clawsweeper Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 26, 2026
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants