fix: harden memory indexing and embedded session locks

This commit is contained in:
Peter Steinberger
2026-01-18 04:29:42 +00:00
parent b7575a889e
commit cf8b3ed988
2 changed files with 66 additions and 69 deletions

View File

@@ -146,10 +146,7 @@ const readSessionMessages = async (sessionFile: string) => {
}; };
describe("runEmbeddedPiAgent", () => { describe("runEmbeddedPiAgent", () => {
it( it("appends new user + assistant after existing transcript entries", { timeout: 90_000 }, async () => {
"appends new user + assistant after existing transcript entries",
{ timeout: 90_000 },
async () => {
const { SessionManager } = await import("@mariozechner/pi-coding-agent"); const { SessionManager } = await import("@mariozechner/pi-coding-agent");
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-agent-")); const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-agent-"));
@@ -220,9 +217,7 @@ describe("runEmbeddedPiAgent", () => {
expect(seedAssistantIndex).toBeGreaterThan(seedUserIndex); expect(seedAssistantIndex).toBeGreaterThan(seedUserIndex);
expect(newUserIndex).toBeGreaterThan(seedAssistantIndex); expect(newUserIndex).toBeGreaterThan(seedAssistantIndex);
expect(newAssistantIndex).toBeGreaterThan(newUserIndex); expect(newAssistantIndex).toBeGreaterThan(newUserIndex);
}, });
45_000,
);
it("persists multi-turn user/assistant ordering across runs", async () => { it("persists multi-turn user/assistant ordering across runs", async () => {
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-agent-")); const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-agent-"));
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-workspace-")); const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-workspace-"));

View File

@@ -1,4 +1,5 @@
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import path from "node:path";
type LockFilePayload = { type LockFilePayload = {
pid: number; pid: number;
@@ -46,6 +47,7 @@ export async function acquireSessionWriteLock(params: {
const staleMs = params.staleMs ?? 30 * 60 * 1000; const staleMs = params.staleMs ?? 30 * 60 * 1000;
const sessionFile = params.sessionFile; const sessionFile = params.sessionFile;
const lockPath = `${sessionFile}.lock`; const lockPath = `${sessionFile}.lock`;
await fs.mkdir(path.dirname(lockPath), { recursive: true });
const held = HELD_LOCKS.get(sessionFile); const held = HELD_LOCKS.get(sessionFile);
if (held) { if (held) {