Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,19 @@ export default function (pi: ExtensionAPI) {
});

// --- session_shutdown: write exit summary + clean up timer ---
pi.on("session_shutdown", async (_event, ctx) => {
pi.on("session_shutdown", async (event, ctx) => {
if (terminalInputUnsubscribe) {
terminalInputUnsubscribe();
terminalInputUnsubscribe = null;
}

// /reload emits session_shutdown with reason "reload" before rebuilding the
// runtime. Generating an exit summary here would make every /reload block
// for several seconds on a live LLM call. Skip it — the session continues.
if (event.reason === "reload") {
return;
}

const reason = exitSummaryReason ?? "session-end";
exitSummaryReason = null;

Expand Down
55 changes: 55 additions & 0 deletions test/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,61 @@ describe("lifecycle hooks", () => {
expect(content).toContain("API key resolution unavailable");
});

test("session_shutdown with reason=reload skips exit summary entirely", async () => {
// Regression test for: /reload blocks for several seconds because
// session_shutdown fires generateExitSummary() on every reload.
const ctx = createShutdownCtx({
branch: [
{
type: "message",
message: {
role: "user",
content: [{ type: "text", text: "hi" }],
timestamp: Date.now(),
},
},
],
model: { provider: "openai", id: "gpt-4o-mini" },
});

await hooks.session_shutdown({ reason: "reload" }, ctx);

// No daily log file should have been created — summary was skipped.
expect(fs.existsSync(dailyPath(todayStr()))).toBe(false);
});

test("session_shutdown with reason=quit still writes exit summary", async () => {
// Ensure the reload-skip guard does not suppress real quit summaries.
const ctx = createShutdownCtx({
branch: [
{
type: "message",
message: {
role: "user",
content: [{ type: "text", text: "Remember: dark mode preferred" }],
timestamp: Date.now(),
},
},
{
type: "message",
message: {
role: "assistant",
content: [{ type: "text", text: "Noted." }],
timestamp: Date.now(),
},
},
],
model: { provider: "openai", id: "gpt-4o-mini" },
modelRegistry: {},
});

await hooks.session_shutdown({ reason: "quit" }, ctx);

// Fallback summary (no real API key) should still be written.
const content = fs.readFileSync(dailyPath(todayStr()), "utf-8");
expect(content).toContain("## Session Summary");
});

// -- session_before_compact --

test("session_before_compact appends handoff when scratchpad has open items", async () => {
Expand Down