Skip to content

fix(memory): detect unindexed session transcripts in status mode (fixes #97814)#97842

Closed
liuhao1024 wants to merge 2 commits into
openclaw:mainfrom
liuhao1024:fix/memory-status-dirty-detection-for-unindexed-sessions
Closed

fix(memory): detect unindexed session transcripts in status mode (fixes #97814)#97842
liuhao1024 wants to merge 2 commits into
openclaw:mainfrom
liuhao1024:fix/memory-status-dirty-detection-for-unindexed-sessions

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw memory status (plain, without --index) reports dirty=false when unindexed usage-counted session transcripts exist on disk. Operators rely on this command as the primary health check for memory recall — a false-clean signal means session transcripts go unindexed indefinitely, causing silent recall gaps.

The root cause is that the status-mode MemoryManager initialization path skips ensureSessionStartupCatchup(). When purpose === "status", the constructor does not detect whether on-disk session files have corresponding memory_index_sources rows.

Why This Change Was Made

The constructor at extensions/memory-core/src/memory/manager.ts:436 gates ensureSessionStartupCatchup() behind !transient, and transient is true for purpose === "status". This means sessionsDirty is never set during status-mode initialization, so status() at line 1146 always reports dirty: false for the sessions dimension.

PR #82341 added startup catch-up for normal manager startup, but the status-purpose initialization path still bypasses it.

User Impact

  • Operators running openclaw memory status get a false-clean dirty=false signal when unindexed session transcripts exist
  • Memory search silently misses unindexed transcripts until --index or --force is used
  • During incident triage, the false-clean state compounds confusion because the fleet appears healthier than it is

Evidence

Real behavior proof

  • Behavior addressed: openclaw memory status reports dirty=false when unindexed usage-counted session transcripts exist on disk
  • Environment tested: macOS 26.4.1, OpenClaw 2026.6.10 (d21ddd3), Node 22.19+
  • Steps run after the patch: Built from source with pnpm build, ran node openclaw.mjs memory status --json to verify baseline behavior, then ran the memory-core extension test suite to verify the fix
  • Evidence after fix:

Baseline behavior (no sessions source configured on local agent):

$ node openclaw.mjs memory status --json
agent=main dirty=False sources=['memory'] files=0 chunks=0

Test verification (1000/1000 pass, including new sync detection test):

$ pnpm test:extension memory-core
Test Files  65 passed (65)
     Tests  1000 passed (1000)

New test detects unindexed session files synchronously for status mode verifies that detectSessionStartupDirtySync() correctly sets sessionsDirty=true when unindexed session files exist, without triggering background sync.

  • Observed result after fix: The synchronous detection method correctly compares on-disk session files against memory_index_sources rows during status-mode construction. When unindexed files exist, sessionsDirty is set to true and status() reports dirty: true.
  • What was not tested: The local agent (main) does not have sessions configured as a memory source, so the CLI behavior is unchanged on this machine. The fix is verified through the extension test suite which creates a test harness with sessions source configured.

Changes Made

  • extensions/memory-core/src/memory/manager-sync-ops.ts — Added detectSessionStartupDirtySync(): synchronous detection of unindexed session transcripts for status-mode initialization

  • extensions/memory-core/src/memory/manager.ts — Call detectSessionStartupDirtySync() when purpose === "status" in constructor

  • extensions/memory-core/src/memory/manager-sync-ops.startup-catchup.test.ts — Added test for synchronous status-mode detection

  • AI-assisted (Hermes Agent)

@clawsweeper

clawsweeper Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main already fixes the memory status false-clean bug through the merged canonical PR, with a regression test on the real status-purpose manager path. This branch now duplicates that status dirty detection and adds unnecessary memory-host SDK export surface.

Root-cause cluster
Relationship: superseded
Canonical: #97857
Summary: The merged canonical PR fixes the same memory status false-clean bug on current main; this PR is now a duplicate implementation attempt.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the current main implementation from the merged canonical PR and close this branch as superseded by that shipped-to-main path.

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

No for current main: the original false-clean source path is no longer present because status-purpose manager creation awaits the existing session catch-up dirty-file check before status() is read. The old bug remains source-reproducible in pre-fix history and in the linked issue context.

Is this the best way to solve the issue?

No. Current main already uses the cleaner awaited-helper implementation from the merged canonical PR, so this branch's extra synchronous detector and SDK export additions are no longer the best fix.

Security review:

Security review cleared: The diff touches memory-core runtime/tests and memory-host SDK exports only; I found no dependency, CI, secret, package, permission, or supply-chain change.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • zw-xysk: Authored the merged PR that current main uses to fix the status-purpose dirty detection path. (role: canonical fix contributor; confidence: high; commits: 742f0c9f8268, 2212ea0516bd; files: extensions/memory-core/src/memory/manager.ts, extensions/memory-core/src/memory/index.test.ts)
  • giodl73-repo: Authored the earlier startup/CLI session catch-up helper that the merged main fix now reuses for status mode. (role: adjacent fix contributor; confidence: high; commits: 8af2af24a53c; files: extensions/memory-core/src/memory/manager.ts, extensions/memory-core/src/memory/manager-sync-ops.ts, extensions/memory-core/src/memory/manager-sync-ops.startup-catchup.test.ts)
  • jalehman: Recently refactored the accessor-backed transcript corpus and session listing contract that session catch-up depends on. (role: recent area contributor; confidence: high; commits: c24d266b2d09; files: packages/memory-host-sdk/src/host/session-files.ts, packages/memory-host-sdk/src/host/session-transcript-corpus.ts)
  • liuhao1024: Beyond this PR, authored a recent merged memory CLI status session-counting fix in the same operator-facing surface. (role: recent adjacent CLI status contributor; confidence: medium; commits: 6dccb61e567c; files: extensions/memory-core/src/cli.runtime.ts)

Codex review notes: model internal, reasoning high; reviewed against a51b06fd4d37; fix evidence: commit 742f0c9f8268, main fix timestamp 2026-06-30T17:47:43-07:00.

@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. 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 Jun 29, 2026
@liuhao1024 liuhao1024 force-pushed the fix/memory-status-dirty-detection-for-unindexed-sessions branch from 5dfb07b to 0224164 Compare July 2, 2026 11:38
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
Status-mode MemoryManager initialization skipped ensureSessionStartupCatchup(),
causing plain 'memory status' to report dirty=false when unindexed usage-counted
session transcripts existed on disk. Add synchronous detectSessionStartupDirtySync()
that compares on-disk session files against memory_index_sources rows during
status-mode construction, so the dirty flag is accurate without triggering a full sync.

Fixes openclaw#97814
Replace resolveSessionTranscriptsDirForAgent + readdirSync with
listSessionTranscriptCorpusEntriesForAgentSync so the status-mode
dirty check respects configured/fixed custom session stores and
ownership filtering, matching the async startup catch-up path.

Export listSessionTranscriptCorpusEntriesForAgentSync through the
memory-host-sdk and plugin-sdk barrels.
@liuhao1024 liuhao1024 force-pushed the fix/memory-status-dirty-detection-for-unindexed-sessions branch from 0224164 to 7727c4b Compare July 2, 2026 19:10
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jul 2, 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: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant