mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-20 15:05:01 +00:00
Compaction Runner: wire post-compaction memory sync
This commit is contained in:
@@ -14,6 +14,7 @@ import { resolveChannelCapabilities } from "../../config/channel-capabilities.js
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { getMachineDisplayName } from "../../infra/machine-name.js";
|
||||
import { generateSecureToken } from "../../infra/secure-random.js";
|
||||
import { getMemorySearchManager } from "../../memory/index.js";
|
||||
import { getGlobalHookRunner } from "../../plugins/hook-runner-global.js";
|
||||
import { type enqueueCommand, enqueueCommandInLane } from "../../process/command-queue.js";
|
||||
import { isCronSessionKey, isSubagentSessionKey } from "../../routing/session-key.js";
|
||||
@@ -26,13 +27,14 @@ import { resolveUserPath } from "../../utils.js";
|
||||
import { normalizeMessageChannel } from "../../utils/message-channel.js";
|
||||
import { isReasoningTagProvider } from "../../utils/provider-utils.js";
|
||||
import { resolveOpenClawAgentDir } from "../agent-paths.js";
|
||||
import { resolveSessionAgentIds } from "../agent-scope.js";
|
||||
import { resolveSessionAgentId, resolveSessionAgentIds } from "../agent-scope.js";
|
||||
import type { ExecElevatedDefaults } from "../bash-tools.js";
|
||||
import { makeBootstrapWarn, resolveBootstrapContextForRun } from "../bootstrap-files.js";
|
||||
import { listChannelSupportedActions, resolveChannelMessageToolHints } from "../channel-tools.js";
|
||||
import { formatUserTime, resolveUserTimeFormat, resolveUserTimezone } from "../date-time.js";
|
||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../defaults.js";
|
||||
import { resolveOpenClawDocsPath } from "../docs-path.js";
|
||||
import { resolveMemorySearchConfig } from "../memory-search.js";
|
||||
import { getApiKeyForModel, resolveModelAuthMode } from "../model-auth.js";
|
||||
import { ensureOpenClawModelsJson } from "../models-config.js";
|
||||
import { resolveOwnerDisplaySetting } from "../owner-display.js";
|
||||
@@ -252,11 +254,42 @@ function resolvePostCompactionIndexSyncMode(config?: OpenClawConfig): "off" | "a
|
||||
|
||||
async function syncPostCompactionSessionMemory(params: {
|
||||
config?: OpenClawConfig;
|
||||
sessionKey?: string;
|
||||
mode: "off" | "async" | "await";
|
||||
}): Promise<void> {
|
||||
if (params.mode === "off" || !params.config) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const agentId = resolveSessionAgentId({
|
||||
sessionKey: params.sessionKey,
|
||||
config: params.config,
|
||||
});
|
||||
const resolvedMemory = resolveMemorySearchConfig(params.config, agentId);
|
||||
if (!resolvedMemory || !resolvedMemory.sources.includes("sessions")) {
|
||||
return;
|
||||
}
|
||||
const { manager } = await getMemorySearchManager({
|
||||
cfg: params.config,
|
||||
agentId,
|
||||
});
|
||||
if (!manager?.sync) {
|
||||
return;
|
||||
}
|
||||
const syncTask = manager.sync({
|
||||
reason: "post-compaction",
|
||||
force: resolvedMemory.sync.sessions.postCompactionForce,
|
||||
});
|
||||
if (params.mode === "await") {
|
||||
await syncTask;
|
||||
} else {
|
||||
void syncTask.catch((err) => {
|
||||
log.warn(`memory sync failed (post-compaction): ${String(err)}`);
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
log.warn(`memory sync skipped (post-compaction): ${String(err)}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -686,6 +719,7 @@ export async function compactEmbeddedPiSessionDirect(
|
||||
emitSessionTranscriptUpdate(params.sessionFile);
|
||||
await syncPostCompactionSessionMemory({
|
||||
config: params.config,
|
||||
sessionKey: params.sessionKey,
|
||||
mode: resolvePostCompactionIndexSyncMode(params.config),
|
||||
});
|
||||
// Estimate tokens after compaction by summing token estimates for remaining messages
|
||||
|
||||
Reference in New Issue
Block a user