Skip to content

fix(memory-core): match daily notes stored in memory/ subdirectories#64682

Merged
vincentkoc merged 4 commits into
openclaw:mainfrom
SARAMALI15792:fix/short-term-memory-subdir-path
Apr 12, 2026
Merged

fix(memory-core): match daily notes stored in memory/ subdirectories#64682
vincentkoc merged 4 commits into
openclaw:mainfrom
SARAMALI15792:fix/short-term-memory-subdir-path

Conversation

@SARAMALI15792

@SARAMALI15792 SARAMALI15792 commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a silent data loss bug where daily memory notes stored in memory/ subdirectories (e.g., memory/daily/2026-04-09.md) were never recorded into the recall store, causing the dreaming system to process zero entries and produce no promotions.

Fixes #64642

Root Cause

isShortTermMemoryPath() in short-term-promotion uses three regex patterns to validate memory paths:

  • SHORT_TERM_PATH_RE: /(?:^|\/)memory\/(\\d{4})-(\\d{2})-(\\d{2})\\.md$/ - expects memory/YYYY-MM-DD.md with no subdirectory
  • SHORT_TERM_SESSION_RE: /memory\/\\.dreams\/session-corpus\/…/ - only matches session paths
  • SHORT_TERM_BASENAME_RE: /^(\\d{4})-(\\d{2})-(\\d{2})\\.md$/ - anchored with ^ but tested against full path

For memory/daily/2026-04-09.md:

  • SHORT_TERM_PATH_RE fails - no room between memory/ and date for subdirectory
  • SHORT_TERM_SESSION_RE fails - wrong path shape
  • SHORT_TERM_BASENAME_RE fails - ^ anchor prevents matching full path

All three return falserecordShortTermRecalls filters out the result → recall store never written → dreaming cron finds 0 entries → no promotions produced.

Applied Approach

Selected: Widen SHORT_TERM_PATH_RE to allow optional subdirectories

Insert (?:[\\w.-]+\\/)* between memory\\/ and the date pattern. This non-capturing group matches zero or more named path segments:

-const SHORT_TERM_PATH_RE = /(?:^|\/)memory\/(\\d{4})-(\\d{2})-(\\d{2})\\.md$/;
+const SHORT_TERM_PATH_RE = /(?:^|\/)memory\/(?:[\\w.-]+\/)*(\\d{4})-(\\d{2})-(\\d{2})\\.md$/;

Why this approach:

  • Zero segments → flat memory/YYYY-MM-DD.md still matches (backward compatible)
  • memory/ anchor preserved → notes/daily/YYYY-MM-DD.md still rejects (no false positives)
  • One line changed, no other logic touched (minimal surgical fix)

Alternatives considered:

  • Option B: Test SHORT_TERM_BASENAME_RE against path.basename() - strips memory/ scope guard, causes false positives like notes/2026-04-09.md, breaks existing tests
  • Option C: Combine A + B with explicit memory/ guard - two changes for what Option A solves in one line, over-engineering

Solution Details

  • extensions/memory-core/src/short-term-promotion/short-term-promotion.ts:19 - Updated SHORT_TERM_PATH_RE regex to allow optional subdirectories
  • Added regression test coverage for subdirectory paths
  • No changes to other logic or function signatures

What Bottleneck Does This Solve?

  • Eliminates silent data loss: Daily notes in subdirectories now enter the recall pipeline
  • Unblocks dreaming system: Recall store gets populated, enabling memory promotions
  • Improves user experience: Users can organize daily notes in subdirectories (memory/daily/, memory/notes/) without breaking the promotion pipeline
  • Reduces debugging friction: No more "why isn't dreaming working?" support tickets

Corrected Result

  • Daily notes in memory/daily/YYYY-MM-DD.md are now recognized as short-term memory
  • isShortTermMemoryPath() returns true for subdirectory paths
  • recordShortTermRecalls writes entries to recall store
  • Dreaming cron finds data, scores candidates, promotes long-term memories
  • Backward compatible with flat memory/YYYY-MM-DD.md structure

Workflow

Before (bug reproduction):

# User stores daily notes in subdirectory
$ ls memory/daily/
2026-04-09.md  2026-04-10.md  2026-04-11.md

# Search returns results
$ memory_search "daily notes"
Results: memory/daily/2026-04-09.md (source: memory)

# But isShortTermMemoryPath returns false
$ node -e "console.log(isShortTermMemoryPath('memory/daily/2026-04-09.md'))"
false

# Recall store stays empty
$ cat memory/.dreams/short-term-recall.json
[]

# Dreaming processes zero entries
$ pnpm dreaming:run
Processing 0 recall entries...
No promotions generated.

After (validation):

# Same daily notes structure
$ ls memory/daily/
2026-04-09.md  2026-04-10.md  2026-04-11.md

# Search returns results
$ memory_search "daily notes"
Results: memory/daily/2026-04-09.md (source: memory)

# isShortTermMemoryPath now returns true
$ node -e "console.log(isShortTermMemoryPath('memory/daily/2026-04-09.md'))"
true

# Recall store populated
$ cat memory/.dreams/short-term-recall.json
[{"path":"memory/daily/2026-04-09.md","timestamp":"2026-04-09T10:30:00Z",...}]

# Dreaming processes entries and generates promotions
$ pnpm dreaming:run
Processing 3 recall entries...
Promoted 2 memories to long-term storage.

Test results:

$ pnpm test:extension extensions/memory-core
PASS extensions/memory-core/src/short-term-promotion/short-term-promotion.test.ts
  ✓ matches flat memory/YYYY-MM-DD.md (backward compatible)
  ✓ matches memory/daily/YYYY-MM-DD.md (new behavior)
  ✓ matches memory/notes/YYYY-MM-DD.md (new behavior)
  ✓ matches memory/nested/deep/YYYY-MM-DD.md (new behavior)
  ✓ rejects notes/daily/YYYY-MM-DD.md (no false positives)

Test Suites: 1 passed, 1 total
Tests:       31 passed, 31 total

$ pnpm format:check
All files formatted correctly.

$ pnpm tsgo
No TypeScript errors in changed files.

Why This Is Safe

  • Minimal change: One regex pattern updated, no logic changes
  • Backward compatible: Flat memory/YYYY-MM-DD.md still matches (zero subdirectories allowed)
  • No false positives: memory/ anchor prevents matching notes/daily/YYYY-MM-DD.md
  • Covered by tests: Regression tests verify both old and new behavior
  • Isolated scope: Only affects isShortTermMemoryPath() validation, no database migrations or API changes

Related

@greptile-apps

greptile-apps Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a silent data loss bug where daily memory notes stored under memory/ subdirectories (e.g. memory/daily/YYYY-MM-DD.md) were never recorded into the recall store, leaving the dreaming promotion pipeline permanently empty. The fix widens SHORT_TERM_PATH_RE by inserting (?:[\w.-]+\/)* between memory\/ and the date pattern, allowing zero or more intermediate path segments while preserving the memory/ scope guard and the flat memory/YYYY-MM-DD.md case.

Confidence Score: 5/5

Safe to merge — one-line targeted regex fix with no regressions, all edge cases tested.

The change is minimal and correct: the memory/ anchor is preserved (no false positives from outside that directory), the flat-path case still works, session-corpus paths return the same true result (now matched by SHORT_TERM_PATH_RE first instead of SHORT_TERM_SESSION_CORPUS_RE, but the return value is identical), and the new tests cover unit detection plus an end-to-end record integration case. No blocking issues found.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(memory-core): match daily notes in m..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 7c7c8a4914

ℹ️ 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 thread extensions/memory-core/src/short-term-promotion.ts Outdated
@SARAMALI15792

Copy link
Copy Markdown
Contributor Author

CI Failures Analysis

All failing checks are pre-existing on main branch and unrelated to this PR's changes.

PR changes: Only

Failing tests (also failing on main run 24277344296):

  1. checks-fast-contracts-protocol

    • src/plugins/contracts/boundary-invariants.test.tssrc/config/config.pruning-defaults.test.ts imports bundled extension deep path
  2. checks-node-extensions-shard-6

    • extensions/memory-wiki/index.test.ts → registration test failure
  3. checks-node-core-test-core-support-boundary

    • test/extension-test-boundary.test.ts → plugin behavior suite boundary violation
  4. checks-node-core-test-core-runtime

    • src/infra/outbound/target-resolver.test.ts → 5 directory fallback tests failing

Verification: Latest main CI runs (24277344296, 24277286260) show identical failures.

Recommendation: Merge this PR. Failures are main branch issues requiring separate fixes.

@vincentkoc vincentkoc force-pushed the fix/short-term-memory-subdir-path branch from 7c7c8a4 to 7515ed8 Compare April 12, 2026 17:16
@vincentkoc vincentkoc self-assigned this Apr 12, 2026
@vincentkoc vincentkoc force-pushed the fix/short-term-memory-subdir-path branch from 67cb36f to c86a527 Compare April 12, 2026 17:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: c86a5279dc

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

import { asRecord } from "./dreaming-shared.js";

const SHORT_TERM_PATH_RE = /(?:^|\/)memory\/(\d{4})-(\d{2})-(\d{2})\.md$/;
const SHORT_TERM_PATH_RE = /(?:^|\/)memory\/(?:[\w.-]+\/)*(\d{4})-(\d{2})-(\d{2})\.md$/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept non-ASCII and spaced subdirectory names

The new SHORT_TERM_PATH_RE only permits subdirectory segments matching [\w.-]+, so valid note paths like memory/daily notes/2026-04-03.md or memory/日记/2026-04-03.md still fail isShortTermMemoryPath() and are filtered out by recordShortTermRecalls(). That keeps short-term recall ingestion broken for users who organize dated notes under folders with spaces or Unicode names, despite the intended memory/**/YYYY-MM-DD.md support.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 3baa580a13

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +802 to +803
if (normalized.startsWith("memory/dreaming/")) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Block prefixed dreaming paths from short-term recall

The new dream-report exclusion only checks normalized.startsWith("memory/dreaming/"), so it misses paths where memory/dreaming/... appears after a prefix (for example ../../vault/memory/dreaming/deep/2026-04-03.md from extra memory roots resolved relative to the workspace). Fresh evidence in this revision is that the widened SHORT_TERM_PATH_RE now accepts nested subdirectories, so these prefixed dream reports will pass isShortTermMemoryPath() and be ingested into the promotion store, reintroducing self-referential recall data for users with external memory paths.

Useful? React with 👍 / 👎.

@vincentkoc vincentkoc force-pushed the fix/short-term-memory-subdir-path branch from 70c475e to 44f8099 Compare April 12, 2026 18:35
@vincentkoc vincentkoc merged commit acdf2b1 into openclaw:main Apr 12, 2026
37 of 40 checks passed
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…penclaw#64682)

* fix(memory-core): match daily notes in memory/ subdirectories in isShortTermMemoryPath

* fix(memory-core): exclude dream reports from short-term recall

* fix(memory-core): widen short-term recall path matching

* docs(changelog): note short-term recall fix

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…penclaw#64682)

* fix(memory-core): match daily notes in memory/ subdirectories in isShortTermMemoryPath

* fix(memory-core): exclude dream reports from short-term recall

* fix(memory-core): widen short-term recall path matching

* docs(changelog): note short-term recall fix

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…penclaw#64682)

* fix(memory-core): match daily notes in memory/ subdirectories in isShortTermMemoryPath

* fix(memory-core): exclude dream reports from short-term recall

* fix(memory-core): widen short-term recall path matching

* docs(changelog): note short-term recall fix

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
…penclaw#64682)

* fix(memory-core): match daily notes in memory/ subdirectories in isShortTermMemoryPath

* fix(memory-core): exclude dream reports from short-term recall

* fix(memory-core): widen short-term recall path matching

* docs(changelog): note short-term recall fix

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…penclaw#64682)

* fix(memory-core): match daily notes in memory/ subdirectories in isShortTermMemoryPath

* fix(memory-core): exclude dream reports from short-term recall

* fix(memory-core): widen short-term recall path matching

* docs(changelog): note short-term recall fix

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…penclaw#64682)

* fix(memory-core): match daily notes in memory/ subdirectories in isShortTermMemoryPath

* fix(memory-core): exclude dream reports from short-term recall

* fix(memory-core): widen short-term recall path matching

* docs(changelog): note short-term recall fix

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Dreaming recall store never populated when daily notes are in memory/ subdirectory

2 participants