Skip to content

Commit cf09447

Browse files
committed
refactor(memory): remove normalization of fixed search defaults
1 parent fc7031b commit cf09447

2 files changed

Lines changed: 28 additions & 101 deletions

File tree

‎src/agents/memory-search.test.ts‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ describe("memory search config", () => {
502502
},
503503
});
504504

505-
expect(resolveMemorySearchSyncConfig(cfg, "main")).toEqual({
505+
expect(resolveMemorySearchSyncConfig(cfg, "main")).toStrictEqual({
506506
onSessionStart: true,
507507
onSearch: true,
508508
watch: true,
@@ -517,22 +517,23 @@ describe("memory search config", () => {
517517
});
518518
});
519519

520-
it("keeps the fixed embedding batch timeout unset", () => {
521-
const cfg = asConfig({
522-
memory: {
523-
search: {
524-
provider: "openai",
525-
},
526-
},
527-
528-
agents: {
529-
defaults: {},
530-
},
531-
});
532-
533-
expect(
534-
resolveMemorySearchSyncConfig(cfg, "main")?.embeddingBatchTimeoutSeconds,
535-
).toBeUndefined();
520+
it("keeps resolved defaults isolated across calls and sync-only consumers", () => {
521+
const cfg = configWithDefaultProvider("openai");
522+
const resolved = resolveMemorySearchConfig(cfg, "main")!;
523+
const expected = structuredClone(resolved);
524+
expect(resolved.cache).toStrictEqual({ enabled: true, maxEntries: undefined });
525+
526+
resolved.chunking.tokens = 1;
527+
resolved.chunking.overlap = 0;
528+
resolved.sync.watch = false;
529+
resolved.sync.sessions.deltaBytes = 0;
530+
resolved.query.hybrid.vectorWeight = 0;
531+
resolved.query.hybrid.mmr.lambda = 0;
532+
resolved.query.hybrid.temporalDecay.halfLifeDays = 1;
533+
resolved.cache.enabled = false;
534+
535+
expect(resolveMemorySearchConfig(cfg, "main")).toStrictEqual(expected);
536+
expect(resolveMemorySearchSyncConfig(cfg, "main")).toStrictEqual(expected.sync);
536537
});
537538

538539
it("merges defaults and overrides", () => {

‎src/agents/memory-search.ts‎

Lines changed: 10 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
* Resolves memory-search source, sync, and ranking configuration.
33
*/
44
import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";
5-
import {
6-
MAX_TIMER_TIMEOUT_MS,
7-
resolvePositiveTimerTimeoutMs,
8-
} from "@openclaw/normalization-core/number-coercion";
95
import type { OpenClawConfig, MemorySearchConfig } from "../config/config.js";
106
import type { SecretInput } from "../config/types.secrets.js";
117
import {
@@ -22,7 +18,7 @@ import { getMemoryEmbeddingProvider } from "../plugins/memory-embedding-provider
2218
import { assertSecretOwnerAvailable } from "../secrets/runtime-degraded-state.js";
2319
import { runtimeMemorySecretOwnerId } from "../secrets/runtime-memory-secret-owner.js";
2420
import { resolveOpenClawAgentSqlitePath } from "../state/openclaw-agent-db.paths.js";
25-
import { clampInt, clampNumber } from "../utils.js";
21+
import { clampNumber } from "../utils.js";
2622
import { resolveAgentConfig } from "./agent-scope.js";
2723

2824
export type ResolvedMemorySearchConfig = {
@@ -137,34 +133,13 @@ const DEFAULT_SOURCES: Array<"memory" | "sessions"> = ["memory"];
137133
const DEFAULT_MEMORY_EMBEDDING_PROVIDER = "openai";
138134
const DEFAULT_REMOTE_BATCH_POLL_INTERVAL_MS = 2_000;
139135
const DEFAULT_REMOTE_BATCH_TIMEOUT_MINUTES = 60;
140-
const MAX_REMOTE_BATCH_TIMEOUT_MINUTES = Math.floor(MAX_TIMER_TIMEOUT_MS / 60_000);
141136

142137
type ConfiguredMemoryEmbeddingProvider = {
143138
defaultModel?: string;
144139
transport?: "local" | "remote";
145140
supportsMultimodalEmbeddings?: (params: { model: string }) => boolean;
146141
};
147142

148-
function resolveRemoteBatchPollIntervalMs(
149-
overrideValue: number | undefined,
150-
defaultValue: number | undefined,
151-
): number {
152-
return resolvePositiveTimerTimeoutMs(
153-
overrideValue ?? defaultValue,
154-
DEFAULT_REMOTE_BATCH_POLL_INTERVAL_MS,
155-
);
156-
}
157-
158-
function resolveRemoteBatchTimeoutMinutes(
159-
overrideValue: number | undefined,
160-
defaultValue: number | undefined,
161-
): number {
162-
const value = overrideValue ?? defaultValue;
163-
return typeof value === "number" && Number.isFinite(value) && value > 0
164-
? clampInt(value, 1, MAX_REMOTE_BATCH_TIMEOUT_MINUTES)
165-
: DEFAULT_REMOTE_BATCH_TIMEOUT_MINUTES;
166-
}
167-
168143
function normalizeSources(
169144
sources: Array<"memory" | "sessions"> | undefined,
170145
sessionMemoryEnabled: boolean,
@@ -238,8 +213,8 @@ function mergeConfig(
238213
enabled: overrideRemote?.batch?.enabled ?? defaultRemote?.batch?.enabled ?? false,
239214
wait: true,
240215
concurrency: 2,
241-
pollIntervalMs: resolveRemoteBatchPollIntervalMs(undefined, undefined),
242-
timeoutMinutes: resolveRemoteBatchTimeoutMinutes(undefined, undefined),
216+
pollIntervalMs: DEFAULT_REMOTE_BATCH_POLL_INTERVAL_MS,
217+
timeoutMinutes: DEFAULT_REMOTE_BATCH_TIMEOUT_MINUTES,
243218
};
244219
const remote = includeRemote
245220
? {
@@ -297,7 +272,7 @@ function mergeConfig(
297272
tokens: DEFAULT_CHUNK_TOKENS,
298273
overlap: DEFAULT_CHUNK_OVERLAP,
299274
};
300-
const sync = resolveSyncConfig(defaults, overrides);
275+
const sync = resolveSyncConfig();
301276
const query = {
302277
maxResults: overrides?.query?.maxResults ?? defaults?.query?.maxResults ?? DEFAULT_MAX_RESULTS,
303278
minScore: overrides?.query?.minScore ?? defaults?.query?.minScore ?? DEFAULT_MIN_SCORE,
@@ -321,25 +296,7 @@ function mergeConfig(
321296
maxEntries: DEFAULT_CACHE_MAX_ENTRIES,
322297
};
323298

324-
const overlap = clampNumber(chunking.overlap, 0, Math.max(0, chunking.tokens - 1));
325299
const minScore = clampNumber(query.minScore, 0, 1);
326-
const vectorWeight = clampNumber(hybrid.vectorWeight, 0, 1);
327-
const textWeight = clampNumber(hybrid.textWeight, 0, 1);
328-
const sum = vectorWeight + textWeight;
329-
const normalizedVectorWeight = sum > 0 ? vectorWeight / sum : DEFAULT_HYBRID_VECTOR_WEIGHT;
330-
const normalizedTextWeight = sum > 0 ? textWeight / sum : DEFAULT_HYBRID_TEXT_WEIGHT;
331-
const candidateMultiplier = clampInt(hybrid.candidateMultiplier, 1, 20);
332-
const temporalDecayHalfLifeDays = Math.max(
333-
1,
334-
Math.floor(
335-
Number.isFinite(hybrid.temporalDecay.halfLifeDays)
336-
? hybrid.temporalDecay.halfLifeDays
337-
: DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS,
338-
),
339-
);
340-
const deltaBytes = clampInt(sync.sessions.deltaBytes, 0, Number.MAX_SAFE_INTEGER);
341-
const deltaMessages = clampInt(sync.sessions.deltaMessages, 0, Number.MAX_SAFE_INTEGER);
342-
const postCompactionForce = sync.sessions.postCompactionForce;
343300
return {
344301
enabled,
345302
rememberAcrossConversations,
@@ -360,49 +317,18 @@ function mergeConfig(
360317
outputDimensionality,
361318
local,
362319
store,
363-
chunking: { tokens: Math.max(1, chunking.tokens), overlap },
364-
sync: {
365-
...sync,
366-
sessions: {
367-
deltaBytes,
368-
deltaMessages,
369-
postCompactionForce,
370-
},
371-
},
320+
chunking,
321+
sync,
372322
query: {
373323
...query,
374324
minScore,
375-
hybrid: {
376-
enabled: hybrid.enabled,
377-
vectorWeight: normalizedVectorWeight,
378-
textWeight: normalizedTextWeight,
379-
candidateMultiplier,
380-
mmr: {
381-
enabled: hybrid.mmr.enabled,
382-
lambda: Number.isFinite(hybrid.mmr.lambda)
383-
? Math.max(0, Math.min(1, hybrid.mmr.lambda))
384-
: DEFAULT_MMR_LAMBDA,
385-
},
386-
temporalDecay: {
387-
enabled: hybrid.temporalDecay.enabled,
388-
halfLifeDays: temporalDecayHalfLifeDays,
389-
},
390-
},
391-
},
392-
cache: {
393-
enabled: cache.enabled,
394-
maxEntries:
395-
typeof cache.maxEntries === "number" && Number.isFinite(cache.maxEntries)
396-
? Math.max(1, Math.floor(cache.maxEntries))
397-
: undefined,
325+
hybrid,
398326
},
327+
cache,
399328
};
400329
}
401330

402-
function resolveSyncConfig(
403-
_defaults: MemorySearchConfig | undefined,
404-
_overrides: MemorySearchConfig | undefined,
405-
): ResolvedMemorySearchSyncConfig {
331+
function resolveSyncConfig(): ResolvedMemorySearchSyncConfig {
406332
return {
407333
onSessionStart: true,
408334
onSearch: true,
@@ -464,5 +390,5 @@ export function resolveMemorySearchSyncConfig(
464390
if (!enabled) {
465391
return null;
466392
}
467-
return resolveSyncConfig(defaults, overrides);
393+
return resolveSyncConfig();
468394
}

0 commit comments

Comments
 (0)