fix(memory): keep FTS-only sync offline

This commit is contained in:
Vincent Koc
2026-06-02 13:34:11 +02:00
parent 1824aa07a0
commit cd0af35e5c
6 changed files with 124 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ const DEFAULT_FILE_COUNT = 512;
const DEFAULT_MAX_WORKSPACE_REG_FDS = process.platform === "darwin" ? 8 : 64;
export const GATEWAY_READY_OUTPUT_MAX_CHARS = 128 * 1024;
export const MEMORY_SEARCH_RESPONSE_MAX_BYTES = 256 * 1024;
export const MEMORY_SEARCH_PROBE_QUERY = "Top-level memory file";
const SKIP_GATEWAY_ENV = {
NODE_ENV: "test",
@@ -277,15 +278,22 @@ function writeSyntheticWorkspace(workspaceDir, fileCount) {
}
}
function writeConfig({ homeDir, workspaceDir, port, token }) {
export function writeConfig({ homeDir, workspaceDir, port, token }) {
const configDir = path.join(homeDir, ".openclaw");
fs.mkdirSync(configDir, { recursive: true });
const configPath = path.join(configDir, "openclaw.json");
const indexPath = path.join(configDir, "memory", "main.sqlite");
const config = {
agents: {
defaults: {
workspace: workspaceDir,
memorySearch: {
provider: "none",
model: "",
store: {
path: indexPath,
vector: { enabled: false },
},
sync: {
watch: true,
onSessionStart: false,
@@ -313,6 +321,37 @@ function writeConfig({ homeDir, workspaceDir, port, token }) {
return configPath;
}
function formatTail(text, maxChars = 4096) {
return text.length > maxChars ? text.slice(-maxChars) : text;
}
function preindexSyntheticMemory(env) {
logStep("preindex start");
const result = spawnSync(
process.execPath,
["scripts/run-node.mjs", "memory", "index", "--force", "--agent", "main"],
{
cwd: process.cwd(),
encoding: "utf8",
env,
maxBuffer: 10 * 1024 * 1024,
stdio: ["ignore", "pipe", "pipe"],
},
);
if (result.status !== 0) {
throw new Error(
[
`memory preindex failed with exit ${result.status ?? result.signal}`,
formatTail(result.stdout || ""),
formatTail(result.stderr || ""),
]
.filter(Boolean)
.join("\n"),
);
}
logStep("preindex complete");
}
export function updateGatewayReadyOutputState(
state,
chunk,
@@ -591,7 +630,7 @@ async function invokeMemorySearch({ port, token, timeoutMs }) {
body: JSON.stringify({
tool: "memory_search",
args: {
query: "FD-leak-probe-sentinel-xyzzy-nomatch",
query: MEMORY_SEARCH_PROBE_QUERY,
maxResults: 1,
corpus: "memory",
},
@@ -673,6 +712,7 @@ async function main() {
OPENCLAW_CONFIG_PATH: configPath,
OPENCLAW_GATEWAY_TOKEN: token,
};
preindexSyntheticMemory(env);
const child = spawn(
process.execPath,
[