Skip to content

Commit 3e5d863

Browse files
committed
fix: initialize reset transcript files
1 parent 77d1584 commit 3e5d863

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/gateway/server.sessions.gateway-server-sessions-a.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,7 @@ describe("gateway server sessions", () => {
11111111
expect(reset.payload?.entry.modelProvider).toBe("openai");
11121112
expect(reset.payload?.entry.model).toBe("gpt-test-a");
11131113
expect(reset.payload?.entry.contextTokens).toBeUndefined();
1114+
await expect(fs.stat(reset.payload?.entry.sessionFile as string)).resolves.toBeTruthy();
11141115

11151116
ws.close();
11161117
});

src/gateway/session-reset-service.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { randomUUID } from "node:crypto";
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
import { CURRENT_SESSION_VERSION } from "@mariozechner/pi-coding-agent";
25
import { getAcpSessionManager } from "../acp/control-plane/manager.js";
36
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
47
import { clearBootstrapSnapshot } from "../agents/bootstrap-cache.js";
@@ -387,6 +390,20 @@ export async function performGatewaySessionReset(params: {
387390
agentId: target.agentId,
388391
reason: "reset",
389392
});
393+
fs.mkdirSync(path.dirname(next.sessionFile as string), { recursive: true });
394+
if (!fs.existsSync(next.sessionFile as string)) {
395+
const header = {
396+
type: "session",
397+
version: CURRENT_SESSION_VERSION,
398+
id: next.sessionId,
399+
timestamp: new Date().toISOString(),
400+
cwd: process.cwd(),
401+
};
402+
fs.writeFileSync(next.sessionFile as string, `${JSON.stringify(header)}\n`, {
403+
encoding: "utf-8",
404+
mode: 0o600,
405+
});
406+
}
390407
if (hadExistingEntry) {
391408
await emitSessionUnboundLifecycleEvent({
392409
targetSessionKey: target.canonicalKey ?? params.key,

0 commit comments

Comments
 (0)