Skip to content

fix: skip exit summary on /reload to prevent blocking#8

Open
tysoncrosbie wants to merge 1 commit intojayzeng:mainfrom
tysoncrosbie:fix/skip-exit-summary-on-reload
Open

fix: skip exit summary on /reload to prevent blocking#8
tysoncrosbie wants to merge 1 commit intojayzeng:mainfrom
tysoncrosbie:fix/skip-exit-summary-on-reload

Conversation

@tysoncrosbie
Copy link
Copy Markdown

@tysoncrosbie tysoncrosbie commented Apr 22, 2026

Issue #7

Description of changes

The session_shutdown handler calls generateExitSummary() unconditionally on every /reload. Since /reload emits session_shutdown with reason: "reload", and the session continues afterward, no exit summary is needed — but the live LLM API call still fires, blocking /reload for several seconds whenever the session has messages.

The delay is invisible on a fresh empty session (messages.length === 0 exits early), which is why it was easy to miss.

Fix: read event.reason in the handler and return early when it is "reload". The SessionShutdownEvent.reason field is already part of pi's public extension API.

Relationship to #5: that issue was also in generateExitSummary — same path, different failure mode (throw vs. silent block).

Changes

  • index.ts: rename _eventevent, add early return for reason === "reload"
  • test/unit.test.ts: two regression tests added to the existing lifecycle hooks suite:
    • session_shutdown with reason=reload skips exit summary entirely — asserts no daily log file is written
    • session_shutdown with reason=quit still writes exit summary — asserts the guard does not suppress real quit summaries

Validation

bun test test/unit.test.ts

105 pass
0 fail
197 expect() calls
Ran 105 tests across 1 file. [627.00ms]

/reload emits session_shutdown with reason "reload" before rebuilding
the runtime. The session_shutdown handler was ignoring event.reason and
calling generateExitSummary() unconditionally — a live LLM API call
that blocks /reload for several seconds whenever the session has messages.

An empty session exits early (messages.length === 0) so the delay only
appears after sending at least one message, making it easy to miss.

Fix: check event.reason === "reload" and return early, skipping the LLM
call. The session continues after reload so no summary is needed.

The SessionShutdownEvent.reason field ("quit" | "reload" | "new" |
"resume" | "fork") is already part of pi's public extension API.

Closes jayzeng#7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant