fix: harden sandbox writes and centralize atomic file writes

This commit is contained in:
Peter Steinberger
2026-03-02 16:44:46 +00:00
parent 14e4575af5
commit 18f8393b6c
12 changed files with 203 additions and 139 deletions

View File

@@ -6,6 +6,7 @@ import readline from "node:readline";
import { resolveAgentWorkspaceDir } from "../agents/agent-scope.js";
import type { OpenClawConfig } from "../config/config.js";
import { resolveStateDir } from "../config/paths.js";
import { writeFileWithinRoot } from "../infra/fs-safe.js";
import { createSubsystemLogger } from "../logging/subsystem.js";
import {
materializeWindowsSpawnProgram,
@@ -1410,11 +1411,17 @@ export class QmdMemoryManager implements MemorySearchManager {
if (cutoff && entry.mtimeMs < cutoff) {
continue;
}
const target = path.join(exportDir, `${path.basename(sessionFile, ".jsonl")}.md`);
const targetName = `${path.basename(sessionFile, ".jsonl")}.md`;
const target = path.join(exportDir, targetName);
tracked.add(sessionFile);
const state = this.exportedSessionState.get(sessionFile);
if (!state || state.hash !== entry.hash || state.mtimeMs !== entry.mtimeMs) {
await fs.writeFile(target, this.renderSessionMarkdown(entry), "utf-8");
await writeFileWithinRoot({
rootDir: exportDir,
relativePath: targetName,
data: this.renderSessionMarkdown(entry),
encoding: "utf-8",
});
}
this.exportedSessionState.set(sessionFile, {
hash: entry.hash,