mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(memory-core): check SQLite plugin state for dreaming ingestion audit after JSON migration (fixes #92017) (#92020)
* fix(memory-core): check SQLite plugin state for dreaming ingestion audit after JSON migration (fixes #92017) * fix: add SQLite-only regression tests for dreaming ingestion audit (fixes #92017)
This commit is contained in:
@@ -6,6 +6,7 @@ import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
|
||||
import { auditDreamingArtifacts, repairDreamingArtifacts } from "./dreaming-repair.js";
|
||||
import {
|
||||
configureMemoryCoreDreamingStateForTests,
|
||||
DREAMING_DAILY_INGESTION_NAMESPACE,
|
||||
DREAMING_SESSION_INGESTION_FILES_NAMESPACE,
|
||||
DREAMING_SESSION_INGESTION_SEEN_NAMESPACE,
|
||||
readMemoryCoreWorkspaceEntries,
|
||||
@@ -214,4 +215,42 @@ describe("dreaming artifact repair", () => {
|
||||
}),
|
||||
).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
it("reports ingestion state present from SQLite when legacy JSON is absent", async () => {
|
||||
const workspaceDir = await createWorkspace();
|
||||
// Write SQLite ingestion entries but NO legacy session-ingestion.json
|
||||
await writeMemoryCoreWorkspaceEntries({
|
||||
namespace: DREAMING_SESSION_INGESTION_FILES_NAMESPACE,
|
||||
workspaceDir,
|
||||
entries: [
|
||||
{
|
||||
key: "main/session.jsonl",
|
||||
value: { lastSize: 120, lastMtimeMs: 1_000, lastContentHash: "hash", cursorLine: 42 },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const audit = await auditDreamingArtifacts({ workspaceDir });
|
||||
|
||||
expect(audit.sessionIngestionExists).toBe(true);
|
||||
});
|
||||
|
||||
it("reports ingestion state present from SQLite daily namespace", async () => {
|
||||
const workspaceDir = await createWorkspace();
|
||||
// Only daily ingestion namespace has rows
|
||||
await writeMemoryCoreWorkspaceEntries({
|
||||
namespace: DREAMING_DAILY_INGESTION_NAMESPACE,
|
||||
workspaceDir,
|
||||
entries: [
|
||||
{
|
||||
key: "2026-06-10",
|
||||
value: { ingestedAt: Date.now() },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const audit = await auditDreamingArtifacts({ workspaceDir });
|
||||
|
||||
expect(audit.sessionIngestionExists).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,8 +5,10 @@ import path from "node:path";
|
||||
import { extractErrorCode } from "openclaw/plugin-sdk/error-runtime";
|
||||
import {
|
||||
clearMemoryCoreWorkspaceNamespace,
|
||||
DREAMING_DAILY_INGESTION_NAMESPACE,
|
||||
DREAMING_SESSION_INGESTION_FILES_NAMESPACE,
|
||||
DREAMING_SESSION_INGESTION_SEEN_NAMESPACE,
|
||||
readMemoryCoreWorkspaceEntries,
|
||||
} from "./dreaming-state.js";
|
||||
|
||||
type DreamingArtifactsAuditIssue = {
|
||||
@@ -208,6 +210,29 @@ export async function auditDreamingArtifacts(params: {
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to SQLite plugin state when the legacy JSON file was archived by migration.
|
||||
if (!sessionIngestionExists) {
|
||||
try {
|
||||
const ingestionNamespaces = [
|
||||
DREAMING_SESSION_INGESTION_FILES_NAMESPACE,
|
||||
DREAMING_SESSION_INGESTION_SEEN_NAMESPACE,
|
||||
DREAMING_DAILY_INGESTION_NAMESPACE,
|
||||
] as const;
|
||||
for (const namespace of ingestionNamespaces) {
|
||||
const entries = await readMemoryCoreWorkspaceEntries({
|
||||
namespace,
|
||||
workspaceDir,
|
||||
});
|
||||
if (entries.length > 0) {
|
||||
sessionIngestionExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// SQLite plugin state unavailable — keep filesystem-only result.
|
||||
}
|
||||
}
|
||||
|
||||
if (suspiciousSessionCorpusLineCount > 0) {
|
||||
issues.push({
|
||||
severity: "warn",
|
||||
|
||||
Reference in New Issue
Block a user