Skip to content

Commit 0609bf8

Browse files
authored
feat(memory): harden dreaming and multilingual memory promotion (#60697)
* feat(memory): add recall audit and doctor repair flow * refactor(memory): rename symbolic scoring and harden dreaming * feat(memory): add multilingual concept vocabulary * docs(changelog): note dreaming memory follow-up * docs(changelog): shorten dreaming follow-up entry * fix(memory): address review follow-ups * chore(skills): tighten security triage trust model * Update CHANGELOG.md
1 parent 0ab160c commit 0609bf8

19 files changed

Lines changed: 2308 additions & 56 deletions

‎.agents/skills/security-triage/SKILL.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Check in this order:
5555
- Was it fixed before release?
5656
3. Exploit path
5757
- Does the report show a real boundary bypass, not just prompt injection, local same-user control, or helper-level semantics?
58+
- If data only moves between trusted workspace-memory files called out in `SECURITY.md`, do not treat "injection markers" alone as a security bug.
59+
- In that case, frame sanitization as optional hardening only if it preserves expected memory workflows.
5860
4. Functional tradeoff
5961
- If a hardening change would reduce intended user functionality, call that out before proposing it.
6062
- Prefer fixes that preserve user workflows over deny-by-default regressions unless the boundary demands it.
@@ -104,5 +106,6 @@ gh search prs --repo openclaw/openclaw --match title,body,comments -- "<terms>"
104106
- “fixed on main, unreleased” is usually not a close.
105107
- “needs attacker-controlled trusted local state first” is usually out of scope.
106108
- “same-host same-user process can already read/write local state” is usually out of scope.
109+
- “trusted workspace memory promotes/reindexes trusted workspace memory” is usually out of scope unless it crosses a documented boundary.
107110
- “helper function behaves differently than documented config semantics” is usually invalid.
108111
- If only the severity is wrong but the bug is real, keep it open and narrow the impact in the reply.

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Docs: https://docs.openclaw.ai
2525
- Tests/runtime: trim local unit-test import/runtime fan-out across browser, WhatsApp, cron, task, and reply flows so owner suites start faster with lower shared-worker overhead while preserving the same focused behavior coverage. (#60249) Thanks @shakkernerd.
2626
- Tests/secrets runtime: restore split secrets suite cache and env isolation cleanup so broader runs do not leak stale plugin or provider snapshot state. (#60395) Thanks @shakkernerd.
2727
- Memory/dreaming (experimental): add opt-in weighted short-term recall promotion to `MEMORY.md`, managed dreaming modes (`off|core|rem|deep`), and a `/dreaming` command plus Dreams UI so durable memory promotion can run on background cadence without manual scheduling. (#60569) Thanks @vignesh07.
28+
- Memory/dreaming (experimental): add follow-up dreaming hardening, multilingual conceptual tagging, and doctor/status repair support. Thanks @vincentkoc. (#60697)
2829
- Agents/system prompts: add an internal cache-prefix boundary across Anthropic-family, OpenAI-family, Google, and CLI transport shaping so stable system-prompt prefixes stay reusable without leaking internal cache markers to provider payloads. (#59054) Thanks @coletebou and @vincentkoc.
29-
- Docs/memory: add a dedicated Dreaming concept page, expand Memory overview with the Dreaming model, and link Dreaming from further reading to document the experimental opt-in consolidation workflow. Thanks @vignesh07.
3030
- Agents/cache prefixes: route compaction, OpenAI WebSocket HTTP fallback, and later-turn embedded session reuse through the same cache-safe prompt shaping path so Anthropic-family and OpenAI-family requests keep stable prompt bytes across follow-up turns and fallback transport changes. (#60691) Thanks @vincentkoc.
3131
- Agents/Claude CLI: expose OpenClaw tools to background Claude CLI runs through a loopback MCP bridge that reuses gateway tool policy, honors session/account/channel scoping, and only advertises the bridge when the local runtime is actually live. (#35676) Thanks @mylukin.
3232
- Providers/Anthropic: remove setup-token from new onboarding and auth-command setup paths, keep existing configured legacy token profiles runnable, and steer new Anthropic setup to Claude CLI or API keys.

‎extensions/memory-core/openclaw.plugin.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
"placeholder": "0 3 * * *",
1313
"help": "Optional cron cadence override for managed dreaming runs."
1414
},
15+
"dreaming.cron": {
16+
"label": "Dreaming Cron",
17+
"placeholder": "0 3 * * *",
18+
"help": "Optional cron cadence override for managed dreaming runs."
19+
},
1520
"dreaming.timezone": {
1621
"label": "Dreaming Timezone",
1722
"placeholder": "America/Los_Angeles",
@@ -53,6 +58,9 @@
5358
"frequency": {
5459
"type": "string"
5560
},
61+
"cron": {
62+
"type": "string"
63+
},
5664
"timezone": {
5765
"type": "string"
5866
},

‎extensions/memory-core/runtime-api.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ export {
33
getBuiltinMemoryEmbeddingProviderDoctorMetadata,
44
listBuiltinAutoSelectMemoryEmbeddingProviderDoctorMetadata,
55
} from "./src/memory/provider-adapters.js";
6+
export {
7+
auditShortTermPromotionArtifacts,
8+
repairShortTermPromotionArtifacts,
9+
} from "./src/short-term-promotion.js";
610
export type { BuiltinMemoryEmbeddingProviderDoctorMetadata } from "./src/memory/provider-adapters.js";
11+
export type {
12+
RepairShortTermPromotionArtifactsResult,
13+
ShortTermAuditSummary,
14+
} from "./src/short-term-promotion.js";

‎extensions/memory-core/src/cli.runtime.ts‎

Lines changed: 153 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ import type {
3030
MemoryPromoteCommandOptions,
3131
MemorySearchCommandOptions,
3232
} from "./cli.types.js";
33+
import { resolveShortTermPromotionDreamingConfig } from "./dreaming.js";
3334
import {
3435
applyShortTermPromotions,
36+
auditShortTermPromotionArtifacts,
37+
repairShortTermPromotionArtifacts,
3538
recordShortTermRecalls,
3639
rankShortTermPromotionCandidates,
40+
resolveShortTermRecallLockPath,
3741
resolveShortTermRecallStorePath,
42+
type RepairShortTermPromotionArtifactsResult,
43+
type ShortTermAuditSummary,
3844
} from "./short-term-promotion.js";
3945

4046
type MemoryManager = NonNullable<Awaited<ReturnType<typeof getMemorySearchManager>>["manager"]>;
@@ -59,6 +65,13 @@ type LoadedMemoryCommandConfig = {
5965
diagnostics: string[];
6066
};
6167

68+
function asRecord(value: unknown): Record<string, unknown> | null {
69+
if (!value || typeof value !== "object" || Array.isArray(value)) {
70+
return null;
71+
}
72+
return value as Record<string, unknown>;
73+
}
74+
6275
function getMemoryCommandSecretTargetIds(): Set<string> {
6376
return new Set([
6477
"agents.defaults.memorySearch.remote.apiKey",
@@ -96,6 +109,57 @@ function emitMemorySecretResolveDiagnostics(
96109
}
97110
}
98111

112+
function resolveMemoryPluginConfig(cfg: OpenClawConfig): Record<string, unknown> {
113+
const entry = asRecord(cfg.plugins?.entries?.["memory-core"]);
114+
return asRecord(entry?.config) ?? {};
115+
}
116+
117+
function formatDreamingSummary(cfg: OpenClawConfig): string {
118+
const pluginConfig = resolveMemoryPluginConfig(cfg);
119+
const dreaming = resolveShortTermPromotionDreamingConfig({ pluginConfig, cfg });
120+
if (!dreaming.enabled) {
121+
return "off";
122+
}
123+
const timezone = dreaming.timezone ? ` (${dreaming.timezone})` : "";
124+
return `${dreaming.cron}${timezone} · limit=${dreaming.limit} · minScore=${dreaming.minScore} · minRecallCount=${dreaming.minRecallCount} · minUniqueQueries=${dreaming.minUniqueQueries}`;
125+
}
126+
127+
function formatAuditCounts(audit: ShortTermAuditSummary): string {
128+
const scriptCoverage = audit.conceptTagScripts
129+
? [
130+
audit.conceptTagScripts.latinEntryCount > 0
131+
? `${audit.conceptTagScripts.latinEntryCount} latin`
132+
: null,
133+
audit.conceptTagScripts.cjkEntryCount > 0
134+
? `${audit.conceptTagScripts.cjkEntryCount} cjk`
135+
: null,
136+
audit.conceptTagScripts.mixedEntryCount > 0
137+
? `${audit.conceptTagScripts.mixedEntryCount} mixed`
138+
: null,
139+
audit.conceptTagScripts.otherEntryCount > 0
140+
? `${audit.conceptTagScripts.otherEntryCount} other`
141+
: null,
142+
]
143+
.filter(Boolean)
144+
.join(", ")
145+
: "";
146+
const suffix = scriptCoverage ? ` · scripts=${scriptCoverage}` : "";
147+
return `${audit.entryCount} entries · ${audit.promotedCount} promoted · ${audit.conceptTaggedEntryCount} concept-tagged · ${audit.spacedEntryCount} spaced${suffix}`;
148+
}
149+
150+
function formatRepairSummary(repair: RepairShortTermPromotionArtifactsResult): string {
151+
const actions: string[] = [];
152+
if (repair.rewroteStore) {
153+
actions.push(
154+
`rewrote store${repair.removedInvalidEntries > 0 ? ` (-${repair.removedInvalidEntries} invalid)` : ""}`,
155+
);
156+
}
157+
if (repair.removedStaleLock) {
158+
actions.push("removed stale lock");
159+
}
160+
return actions.length > 0 ? actions.join(" · ") : "no changes";
161+
}
162+
99163
function formatSourceLabel(source: string, workspaceDir: string, agentId: string): string {
100164
if (source === "memory") {
101165
return shortenHomeInString(
@@ -367,6 +431,8 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
367431
embeddingProbe?: Awaited<ReturnType<MemoryManager["probeEmbeddingAvailability"]>>;
368432
indexError?: string;
369433
scan?: MemorySourceScan;
434+
audit?: ShortTermAuditSummary;
435+
repair?: RepairShortTermPromotionArtifactsResult;
370436
}> = [];
371437

372438
for (const agentId of agentIds) {
@@ -440,7 +506,28 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
440506
extraPaths: status.extraPaths,
441507
})
442508
: undefined;
443-
allResults.push({ agentId, status, embeddingProbe, indexError, scan });
509+
let audit: ShortTermAuditSummary | undefined;
510+
let repair: RepairShortTermPromotionArtifactsResult | undefined;
511+
if (workspaceDir) {
512+
if (opts.fix) {
513+
repair = await repairShortTermPromotionArtifacts({ workspaceDir });
514+
}
515+
const customQmd = asRecord(asRecord(status.custom)?.qmd);
516+
audit = await auditShortTermPromotionArtifacts({
517+
workspaceDir,
518+
qmd:
519+
status.backend === "qmd"
520+
? {
521+
dbPath: status.dbPath,
522+
collections:
523+
typeof customQmd?.collections === "number"
524+
? customQmd.collections
525+
: undefined,
526+
}
527+
: undefined,
528+
});
529+
}
530+
allResults.push({ agentId, status, embeddingProbe, indexError, scan, audit, repair });
444531
},
445532
});
446533
}
@@ -460,7 +547,7 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
460547
const label = (text: string) => muted(`${text}:`);
461548

462549
for (const result of allResults) {
463-
const { agentId, status, embeddingProbe, indexError, scan } = result;
550+
const { agentId, status, embeddingProbe, indexError, scan, audit, repair } = result;
464551
const filesIndexed = status.files ?? 0;
465552
const chunksIndexed = status.chunks ?? 0;
466553
const totalFiles = scan?.totalFiles ?? null;
@@ -490,6 +577,7 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
490577
`${label("Dirty")} ${status.dirty ? warn("yes") : muted("no")}`,
491578
`${label("Store")} ${info(storePath)}`,
492579
`${label("Workspace")} ${info(workspacePath)}`,
580+
`${label("Dreaming")} ${info(formatDreamingSummary(cfg))}`,
493581
].filter(Boolean) as string[];
494582
if (embeddingProbe) {
495583
const state = embeddingProbe.ok ? "ready" : "unavailable";
@@ -580,6 +668,24 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
580668
lines.push(`${label("Batch error")} ${warn(status.batch.lastError)}`);
581669
}
582670
}
671+
if (audit) {
672+
lines.push(`${label("Recall store")} ${info(formatAuditCounts(audit))}`);
673+
lines.push(`${label("Recall path")} ${info(shortenHomePath(audit.storePath))}`);
674+
if (audit.updatedAt) {
675+
lines.push(`${label("Recall updated")} ${info(audit.updatedAt)}`);
676+
}
677+
if (status.backend === "qmd" && audit.qmd) {
678+
const qmdBits = [
679+
audit.qmd.dbPath ? shortenHomePath(audit.qmd.dbPath) : "<unknown>",
680+
typeof audit.qmd.dbBytes === "number" ? `${audit.qmd.dbBytes} bytes` : null,
681+
typeof audit.qmd.collections === "number" ? `${audit.qmd.collections} collections` : null,
682+
].filter(Boolean);
683+
lines.push(`${label("QMD audit")} ${info(qmdBits.join(" · "))}`);
684+
}
685+
}
686+
if (repair) {
687+
lines.push(`${label("Repair")} ${info(formatRepairSummary(repair))}`);
688+
}
583689
if (status.fallback?.reason) {
584690
lines.push(muted(status.fallback.reason));
585691
}
@@ -592,6 +698,17 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
592698
lines.push(` ${warn(issue)}`);
593699
}
594700
}
701+
if (audit?.issues.length) {
702+
if (!scan?.issues.length) {
703+
lines.push(label("Issues"));
704+
}
705+
for (const issue of audit.issues) {
706+
lines.push(` ${issue.severity === "error" ? warn(issue.message) : muted(issue.message)}`);
707+
}
708+
if (!opts.fix) {
709+
lines.push(` ${muted(`Fix: openclaw memory status --fix --agent ${agentId}`)}`);
710+
}
711+
}
595712
defaultRuntime.log(lines.join("\n"));
596713
defaultRuntime.log("");
597714
}
@@ -846,11 +963,26 @@ export async function runMemoryPromote(opts: MemoryPromoteCommandOptions) {
846963
}
847964

848965
const storePath = resolveShortTermRecallStorePath(workspaceDir);
966+
const lockPath = resolveShortTermRecallLockPath(workspaceDir);
967+
const customQmd = asRecord(asRecord(status.custom)?.qmd);
968+
const audit = await auditShortTermPromotionArtifacts({
969+
workspaceDir,
970+
qmd:
971+
status.backend === "qmd"
972+
? {
973+
dbPath: status.dbPath,
974+
collections:
975+
typeof customQmd?.collections === "number" ? customQmd.collections : undefined,
976+
}
977+
: undefined,
978+
});
849979

850980
if (opts.json) {
851981
defaultRuntime.writeJson({
852982
workspaceDir,
853983
storePath,
984+
lockPath,
985+
audit,
854986
candidates,
855987
apply: applyResult
856988
? {
@@ -866,6 +998,11 @@ export async function runMemoryPromote(opts: MemoryPromoteCommandOptions) {
866998
if (candidates.length === 0) {
867999
defaultRuntime.log("No short-term recall candidates.");
8681000
defaultRuntime.log(`Recall store: ${shortenHomePath(storePath)}`);
1001+
if (audit.issues.length > 0) {
1002+
for (const issue of audit.issues) {
1003+
defaultRuntime.log(issue.message);
1004+
}
1005+
}
8691006
return;
8701007
}
8711008

@@ -879,6 +1016,7 @@ export async function runMemoryPromote(opts: MemoryPromoteCommandOptions) {
8791016
)}`,
8801017
);
8811018
lines.push(`${colorize(rich, theme.muted, "Recall store:")} ${shortenHomePath(storePath)}`);
1019+
lines.push(colorize(rich, theme.muted, `Store health: ${formatAuditCounts(audit)}`));
8821020
for (const candidate of candidates) {
8831021
lines.push(
8841022
`${colorize(rich, theme.success, candidate.score.toFixed(3))} ${colorize(
@@ -891,14 +1029,26 @@ export async function runMemoryPromote(opts: MemoryPromoteCommandOptions) {
8911029
colorize(
8921030
rich,
8931031
theme.muted,
894-
`recalls=${candidate.recallCount} avg=${candidate.avgScore.toFixed(3)} queries=${candidate.uniqueQueries} age=${candidate.ageDays.toFixed(1)}d`,
1032+
`recalls=${candidate.recallCount} avg=${candidate.avgScore.toFixed(3)} queries=${candidate.uniqueQueries} age=${candidate.ageDays.toFixed(1)}d consolidate=${candidate.components.consolidation.toFixed(2)} conceptual=${candidate.components.conceptual.toFixed(2)}`,
8951033
),
8961034
);
1035+
if (candidate.conceptTags.length > 0) {
1036+
lines.push(colorize(rich, theme.muted, `concepts=${candidate.conceptTags.join(", ")}`));
1037+
}
8971038
if (candidate.snippet) {
8981039
lines.push(colorize(rich, theme.muted, candidate.snippet));
8991040
}
9001041
lines.push("");
9011042
}
1043+
if (audit.issues.length > 0) {
1044+
lines.push(colorize(rich, theme.warn, "Audit issues:"));
1045+
for (const issue of audit.issues) {
1046+
lines.push(
1047+
colorize(rich, issue.severity === "error" ? theme.warn : theme.muted, issue.message),
1048+
);
1049+
}
1050+
lines.push("");
1051+
}
9021052
if (applyResult) {
9031053
if (applyResult.applied > 0) {
9041054
lines.push(

0 commit comments

Comments
 (0)