@@ -81,6 +81,7 @@ export class Session {
8181 id: string | null = null;
8282 logPath: string | null = null;
8383 private fd: number | null = null;
84+ private closed = false;
8485
8586 constructor(sessionsDir: string, cwd: string) {
8687 this.sessionsDir = sessionsDir;
@@ -88,6 +89,7 @@ export class Session {
8889 }
8990
9091 appendMessage(message: Message): void {
92+ if (this.closed) return;
9193 this.ensure(titleFor(message));
9294 this.write({
9395 type: "message",
@@ -97,11 +99,13 @@ export class Session {
9799 }
98100
99101 appendRequest(input: Omit<RequestRecord, "type" | "at">): void {
102+ if (this.closed) return;
100103 this.ensure("session");
101104 this.write({ type: "request", at: new Date().toISOString(), ...input });
102105 }
103106
104107 close(): void {
108+ this.closed = true;
105109 if (this.fd !== null) {
106110 closeSync(this.fd);
107111 this.fd = null;