Skip to content

fix: harden exit summary (skip empty summaries, bound shutdown work) - #28

Merged
jayzeng merged 1 commit into
jayzeng:mainfrom
cokekitten:fix/exit-summary-hardening
Aug 11, 2026
Merged

fix: harden exit summary (skip empty summaries, bound shutdown work)#28
jayzeng merged 1 commit into
jayzeng:mainfrom
cokekitten:fix/exit-summary-hardening

Conversation

@cokekitten

Copy link
Copy Markdown
Contributor

Implements the two hardening items from the follow-up comment on #26. Independent of the configurability PR (which adds the opt-out/model knobs); both may touch the README env table and changelog, so whichever lands second gets a trivial rebase.

What

1. Don't persist all-"None." summaries

The summary prompt instructs the model to write None. under each heading when nothing is worth recording, but the write path only checked result.hasMessages && result.summary — so trivial sessions (>= EXIT_SUMMARY_MIN_MESSAGES messages, zero substance) got a boilerplate entry appended to the daily log, where it is re-injected at every session_start for the rest of the day and indexed by qmd. A new isExitSummaryEmpty() helper filters these out, completing the curated-write gate the code already intends (cf. the comment on EXIT_SUMMARY_MIN_MESSAGES and the earlier fix for failure-boilerplate).

2. Self-imposed timeout for shutdown summary work

Pi core awaits session_shutdown handlers with no timeout, and generateExitSummary() is only bounded by the provider's own timeout — a hanging provider could block quitting indefinitely even for users who want the summary. Summary generation is now raced against PI_MEMORY_EXIT_SUMMARY_TIMEOUT_MS (default 10s). On expiry nothing is persisted; the late result is dropped.

Both surface in the README env table, the changelog, and the memory_status configuration section.

Tests (TDD per AGENTS.md)

Baseline before edits: bun test test/unit.test.ts → 172 pass; tsc --noEmit and biome check clean.

New tests (added red, then green):

  • isExitSummaryEmpty(): all-"None." blocks (incl. bullet/case/missing-period variants, headings-only) are empty; any real content (even text merely mentioning "None.") is kept
  • getExitSummaryTimeoutMs(): env parsing, invalid/negative values fall back to the 10s default
  • handler-level: with a never-resolving API-key lookup and PI_MEMORY_EXIT_SUMMARY_TIMEOUT_MS=50, session_shutdown returns promptly and writes nothing (without the race this test can only fail via bun's per-test timeout)

After: 177 pass, 0 fail; tsc --noEmit and biome check clean.

Refs #26

Two robustness fixes for the exit summary on session_shutdown, raised in
the follow-up discussion on jayzeng#26:

1. Persist gate: summaries whose every section is "None." (trivial
   sessions with nothing worth recording) are no longer written to the
   daily log. The prompt tells the model to emit "None." per section
   when there is nothing to record, but the write path only checked for
   a non-empty string, so boilerplate entries were appended, re-injected
   at every session start, and indexed by qmd. New isExitSummaryEmpty()
   helper completes the curated-write gate.
2. Timeout: summary generation is now raced against a self-imposed
   timeout (PI_MEMORY_EXIT_SUMMARY_TIMEOUT_MS, default 10s). Pi core
   awaits shutdown handlers with no timeout, so a hanging provider
   previously blocked quitting indefinitely. On expiry nothing is
   persisted; the late result is dropped.

Refs jayzeng#26

Signed-off-by: Bowen M. <drmoaint@gmail.com>

Signed-off-by: Zeng, Jay <Jay.Zeng+cvsh@CVSHealth.com>
@jayzeng
jayzeng force-pushed the fix/exit-summary-hardening branch from af7bc37 to 9448598 Compare August 11, 2026 06:05
@jayzeng
jayzeng merged commit 0799932 into jayzeng:main Aug 11, 2026
3 checks passed
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.

2 participants