Bug Report: shouldSyncSessions skips session data during full reindex triggered by session-start
Summary
When a full reindex is triggered during a session-start sync (e.g., due to model mismatch after gateway restart), session transcript data is silently dropped from the index. The metadata still reports sources: ["memory", "sessions"], masking the data loss.
Version
OpenClaw 2026.3.8 (3caab92)
Steps to Reproduce
- Configure an agent with
experimental.sessionMemory: true and sources: ["memory", "sessions"]
- Create a state where the agent's index metadata differs from the resolved config (e.g., embedding model mismatch — DB has
text-embedding-3-small, config resolves to text-embedding-3-large)
- Restart the gateway
- Send a message to the agent (triggers
warmSession → sync({ reason: "session-start" }))
Expected Behavior
The full reindex should include both memory files AND session transcripts, since the agent is configured with sources: ["memory", "sessions"].
Actual Behavior
The full reindex only syncs memory files. Session transcript data is dropped from the new index database. The index metadata still reports sources: ["memory", "sessions"], hiding the regression.
Root Cause
In src/memory/manager-sync-ops.ts, the shouldSyncSessions method has a priority bug:
shouldSyncSessions(params, needsFullReindex = false) {
if (!this.sources.has("sessions")) return false;
if (params?.force) return true;
const reason = params?.reason;
if (reason === "session-start" || reason === "watch") return false; // ← returns before checking needsFullReindex
if (needsFullReindex) return true;
return this.sessionsDirty && this.sessionsDirtyFiles.size > 0;
}
The session-start early return (line 4) fires before the needsFullReindex check (line 5). This means when a full reindex is needed but triggered by a session starting, sessions are skipped.
The call chain:
warmSession() → sync({ reason: "session-start" })
sync() detects needsFullReindex = true (model/provider/config mismatch)
- Calls
runSafeReindex({ reason: "session-start" })
runSafeReindex calls shouldSyncSessions({ reason: "session-start" }, true)
- Returns
false because session-start short-circuits before needsFullReindex is checked
- New database is built with only memory files
writeMeta() writes sources: ["memory", "sessions"] from config — masking the loss
Suggested Fix
Reorder the checks so needsFullReindex takes priority over the incremental-sync skip:
shouldSyncSessions(params, needsFullReindex = false) {
if (!this.sources.has("sessions")) return false;
if (params?.force) return true;
if (needsFullReindex) return true; // ← moved before session-start check
const reason = params?.reason;
if (reason === "session-start" || reason === "watch") return false;
return this.sessionsDirty && this.sessionsDirtyFiles.size > 0;
}
The session-start / watch skip is correct for incremental syncs (don't burn resources on every session start), but should not apply when a full reindex is required — full reindexes need all data or the new database is incomplete.
Conditions That Trigger needsFullReindex
Any of these being true during a session-start sync will cause session data loss:
!meta — no metadata in DB
meta.model !== provider.model — embedding model change
meta.provider !== provider.id — embedding provider change
meta.providerKey !== providerKey — API key rotation
metaSourcesDiffer(meta, configuredSources) — sources config change
meta.chunkTokens !== settings.chunking.tokens — chunk size change
meta.chunkOverlap !== settings.chunking.overlap — chunk overlap change
vectorReady && !meta?.vectorDims — vector extension loaded after initial build
Impact
In our deployment (15 agents), this bug has caused recurring session data loss across 3 separate incidents over 3 days. Each time, manual openclaw memory index --force (which bypasses the bug via force: true) fixes it, but the regression returns after the next gateway restart because the underlying trigger conditions persist.
File Reference
dist/manager-Ch8Hmvy3.js — shouldSyncSessions method (corresponds to src/memory/manager-sync-ops.ts in source)
Bug Report:
shouldSyncSessionsskips session data during full reindex triggered bysession-startSummary
When a full reindex is triggered during a
session-startsync (e.g., due to model mismatch after gateway restart), session transcript data is silently dropped from the index. The metadata still reportssources: ["memory", "sessions"], masking the data loss.Version
OpenClaw 2026.3.8 (3caab92)
Steps to Reproduce
experimental.sessionMemory: trueandsources: ["memory", "sessions"]text-embedding-3-small, config resolves totext-embedding-3-large)warmSession→sync({ reason: "session-start" }))Expected Behavior
The full reindex should include both memory files AND session transcripts, since the agent is configured with
sources: ["memory", "sessions"].Actual Behavior
The full reindex only syncs memory files. Session transcript data is dropped from the new index database. The index metadata still reports
sources: ["memory", "sessions"], hiding the regression.Root Cause
In
src/memory/manager-sync-ops.ts, theshouldSyncSessionsmethod has a priority bug:The
session-startearly return (line 4) fires before theneedsFullReindexcheck (line 5). This means when a full reindex is needed but triggered by a session starting, sessions are skipped.The call chain:
warmSession()→sync({ reason: "session-start" })sync()detectsneedsFullReindex = true(model/provider/config mismatch)runSafeReindex({ reason: "session-start" })runSafeReindexcallsshouldSyncSessions({ reason: "session-start" }, true)falsebecausesession-startshort-circuits beforeneedsFullReindexis checkedwriteMeta()writessources: ["memory", "sessions"]from config — masking the lossSuggested Fix
Reorder the checks so
needsFullReindextakes priority over the incremental-sync skip:The
session-start/watchskip is correct for incremental syncs (don't burn resources on every session start), but should not apply when a full reindex is required — full reindexes need all data or the new database is incomplete.Conditions That Trigger
needsFullReindexAny of these being true during a
session-startsync will cause session data loss:!meta— no metadata in DBmeta.model !== provider.model— embedding model changemeta.provider !== provider.id— embedding provider changemeta.providerKey !== providerKey— API key rotationmetaSourcesDiffer(meta, configuredSources)— sources config changemeta.chunkTokens !== settings.chunking.tokens— chunk size changemeta.chunkOverlap !== settings.chunking.overlap— chunk overlap changevectorReady && !meta?.vectorDims— vector extension loaded after initial buildImpact
In our deployment (15 agents), this bug has caused recurring session data loss across 3 separate incidents over 3 days. Each time, manual
openclaw memory index --force(which bypasses the bug viaforce: true) fixes it, but the regression returns after the next gateway restart because the underlying trigger conditions persist.File Reference
dist/manager-Ch8Hmvy3.js—shouldSyncSessionsmethod (corresponds tosrc/memory/manager-sync-ops.tsin source)