Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
]
},
"scripts": {
"test": "node test/embedder-error-hints.test.mjs && node test/cjk-recursion-regression.test.mjs && node test/migrate-legacy-schema.test.mjs && node --test test/config-session-strategy-migration.test.mjs && node --test test/scope-access-undefined.test.mjs && node --test test/reflection-bypass-hook.test.mjs && node --test test/smart-extractor-scope-filter.test.mjs && node --test test/store-empty-scope-filter.test.mjs && node --test test/recall-text-cleanup.test.mjs && node test/update-consistency-lancedb.test.mjs && node --test test/strip-envelope-metadata.test.mjs && node test/cli-smoke.mjs && node test/functional-e2e.mjs && node test/retriever-rerank-regression.mjs && node test/smart-memory-lifecycle.mjs && node test/smart-extractor-branches.mjs && node test/plugin-manifest-regression.mjs && node --test test/session-summary-before-reset.test.mjs && node --test test/sync-plugin-version.test.mjs && node test/smart-metadata-v2.mjs && node test/vector-search-cosine.test.mjs && node test/context-support-e2e.mjs && node test/temporal-facts.test.mjs && node test/memory-update-supersede.test.mjs && node test/memory-upgrader-diagnostics.test.mjs && node --test test/llm-api-key-client.test.mjs && node --test test/llm-oauth-client.test.mjs && node --test test/cli-oauth-login.test.mjs && node --test test/workflow-fork-guards.test.mjs && node --test test/clawteam-scope.test.mjs && node --test test/cross-process-lock.test.mjs && node --test test/preference-slots.test.mjs && node test/is-latest-auto-supersede.test.mjs && node --test test/temporal-awareness.test.mjs",
"test": "node test/embedder-error-hints.test.mjs && node test/cjk-recursion-regression.test.mjs && node test/migrate-legacy-schema.test.mjs && node --test test/config-session-strategy-migration.test.mjs && node --test test/scope-access-undefined.test.mjs && node --test test/reflection-bypass-hook.test.mjs && node --test test/smart-extractor-scope-filter.test.mjs && node --test test/store-empty-scope-filter.test.mjs && node --test test/recall-text-cleanup.test.mjs && node test/update-consistency-lancedb.test.mjs && node --test test/strip-envelope-metadata.test.mjs && node test/cli-smoke.mjs && node test/functional-e2e.mjs && node test/retriever-rerank-regression.mjs && node test/smart-memory-lifecycle.mjs && node test/smart-extractor-branches.mjs && node test/plugin-manifest-regression.mjs && node --test test/session-summary-before-reset.test.mjs && node --test test/sync-plugin-version.test.mjs && node test/smart-metadata-v2.mjs && node test/vector-search-cosine.test.mjs && node test/context-support-e2e.mjs && node test/temporal-facts.test.mjs && node test/memory-update-supersede.test.mjs && node test/memory-update-metadata-refresh.test.mjs && node test/memory-upgrader-diagnostics.test.mjs && node --test test/llm-api-key-client.test.mjs && node --test test/llm-oauth-client.test.mjs && node --test test/cli-oauth-login.test.mjs && node --test test/workflow-fork-guards.test.mjs && node --test test/clawteam-scope.test.mjs && node --test test/cross-process-lock.test.mjs && node --test test/preference-slots.test.mjs && node test/is-latest-auto-supersede.test.mjs && node --test test/temporal-awareness.test.mjs",
"test:openclaw-host": "node test/openclaw-host-functional.mjs",
"version": "node scripts/sync-plugin-version.mjs openclaw.plugin.json package.json && git add openclaw.plugin.json"
},
Expand Down
40 changes: 38 additions & 2 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
import { homedir } from "node:os";
import { join } from "node:path";
import type { MemoryRetriever, RetrievalResult } from "./retriever.js";
import type { MemoryStore } from "./store.js";
import type { MemoryEntry, MemoryStore } from "./store.js";
import { isNoise } from "./noise-filter.js";
import { isSystemBypassId, resolveScopeFilter, parseAgentIdFromSessionKey, type MemoryScopeManager } from "./scopes.js";
import type { Embedder } from "./embedder.js";
Expand Down Expand Up @@ -1263,8 +1263,9 @@ export function registerMemoryUpdateTool(
// --- Temporal supersede guard ---
// For temporal-versioned categories (preferences/entities), changing
// text must go through supersede to preserve the history chain.
let existing: MemoryEntry | null = null;
if (text && newVector) {
const existing = await context.store.getById(resolvedId, scopeFilter);
existing = await context.store.getById(resolvedId, scopeFilter);
if (existing) {
const meta = parseSmartMetadata(existing.metadata, existing);
if (TEMPORAL_VERSIONED_CATEGORIES.has(meta.memory_category)) {
Expand Down Expand Up @@ -1354,6 +1355,41 @@ export function registerMemoryUpdateTool(
updates.importance = clamp01(importance, 0.7);
if (category) updates.category = category;

// Rebuild smart metadata when text or importance changes (#544)
if (text && existing) {
const meta = parseSmartMetadata(existing.metadata, existing);
const effectiveCategory = category
? (category as string)
: meta.memory_category;
const newExpiry = inferExpiry(text);
const updatedMeta = buildSmartMetadata(existing, {
l0_abstract: text,
l1_overview: `- ${text}`,
l2_content: text,
fact_key: deriveFactKey(effectiveCategory, text),
memory_temporal_type: classifyTemporal(text),
// Pass 0 when no expiry so buildSmartMetadata clears the old value
// (undefined means "keep existing" in buildSmartMetadata)
valid_until: newExpiry ?? (0 as any),
confidence:
importance !== undefined
? clamp01(importance, 0.7)
: meta.confidence,
});
updates.metadata = stringifySmartMetadata(updatedMeta);
} else if (importance !== undefined && !text) {
// Sync confidence for importance-only changes
const entry =
existing ?? (await context.store.getById(resolvedId, scopeFilter));
if (entry) {
const meta = parseSmartMetadata(entry.metadata, entry);
const updatedMeta = buildSmartMetadata(entry, {
confidence: clamp01(importance, 0.7),
});
updates.metadata = stringifySmartMetadata(updatedMeta);
}
}

const updated = await context.store.update(
resolvedId,
updates,
Expand Down
Loading
Loading