mirror of https://github.com/openclaw/openclaw.git
fix: clean up attachments for killed subagent runs
This commit is contained in:
parent
807daf54fe
commit
dd11bdd003
|
|
@ -1,3 +1,6 @@
|
|||
import { promises as fs } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const noop = () => {};
|
||||
|
|
@ -431,4 +434,34 @@ describe("subagent registry seam flow", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("removes attachments for killed delete-mode runs", async () => {
|
||||
const attachmentsRootDir = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "openclaw-kill-attachments-"),
|
||||
);
|
||||
const attachmentsDir = path.join(attachmentsRootDir, "child");
|
||||
await fs.mkdir(attachmentsDir, { recursive: true });
|
||||
await fs.writeFile(path.join(attachmentsDir, "artifact.txt"), "artifact");
|
||||
|
||||
mod.registerSubagentRun({
|
||||
runId: "run-killed-delete-attachments",
|
||||
childSessionKey: "agent:main:subagent:killed-delete-attachments",
|
||||
requesterSessionKey: "agent:main:main",
|
||||
requesterDisplayKey: "main",
|
||||
task: "kill and delete attachments",
|
||||
cleanup: "delete",
|
||||
attachmentsDir,
|
||||
attachmentsRootDir,
|
||||
});
|
||||
|
||||
const updated = mod.markSubagentRunTerminated({
|
||||
runId: "run-killed-delete-attachments",
|
||||
reason: "manual kill",
|
||||
});
|
||||
|
||||
expect(updated).toBe(1);
|
||||
await vi.waitFor(async () => {
|
||||
await expect(fs.access(attachmentsDir)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1654,6 +1654,10 @@ export function markSubagentRunTerminated(params: {
|
|||
childSessionKey: entry.childSessionKey,
|
||||
});
|
||||
});
|
||||
const shouldDeleteAttachments = entry.cleanup === "delete" || !entry.retainAttachmentsOnKeep;
|
||||
if (shouldDeleteAttachments) {
|
||||
void safeRemoveAttachmentsDir(entry);
|
||||
}
|
||||
completeCleanupBookkeeping({
|
||||
runId: entry.runId,
|
||||
entry,
|
||||
|
|
|
|||
Loading…
Reference in New Issue