fix: harden exit summary (skip empty summaries, bound shutdown work) - #28
Merged
Merged
Conversation
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
force-pushed
the
fix/exit-summary-hardening
branch
from
August 11, 2026 06:05
af7bc37 to
9448598
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 checkedresult.hasMessages && result.summary— so trivial sessions (>= EXIT_SUMMARY_MIN_MESSAGESmessages, zero substance) got a boilerplate entry appended to the daily log, where it is re-injected at everysession_startfor the rest of the day and indexed by qmd. A newisExitSummaryEmpty()helper filters these out, completing the curated-write gate the code already intends (cf. the comment onEXIT_SUMMARY_MIN_MESSAGESand the earlier fix for failure-boilerplate).2. Self-imposed timeout for shutdown summary work
Pi core awaits
session_shutdownhandlers with no timeout, andgenerateExitSummary()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 againstPI_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_statusconfiguration section.Tests (TDD per AGENTS.md)
Baseline before edits:
bun test test/unit.test.ts→ 172 pass;tsc --noEmitandbiome checkclean.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 keptgetExitSummaryTimeoutMs(): env parsing, invalid/negative values fall back to the 10s defaultPI_MEMORY_EXIT_SUMMARY_TIMEOUT_MS=50,session_shutdownreturns promptly and writes nothing (without the race this test can only fail via bun's per-test timeout)After: 177 pass, 0 fail;
tsc --noEmitandbiome checkclean.Refs #26