Skip to content

fix: write the exit summary in the next session instead of blocking quit - #56

Open
felipeadeildo wants to merge 1 commit into
jayzeng:mainfrom
felipeadeildo:fix/exit-without-waiting
Open

felipeadeildo wants to merge 1 commit into
jayzeng:mainfrom
felipeadeildo:fix/exit-without-waiting

Conversation

@felipeadeildo

@felipeadeildo felipeadeildo commented Oct 21, 2026 •

Copy link
Copy Markdown

Fixes #55.

Pi stops its screen before it runs session_shutdown handlers, and then waits for them with no timeout. The exit summary's model call ran in that wait, so quitting looked like a hang for up to 10 s. The Ctrl+C that followed killed pi, which lost the summary and the To resume this session line.

Quitting now only saves what the summary needs, and the next interactive session writes it:

  • On quit: the transcript, truncated as before, the model ref and the end time go to memory/pending/<session-id>.json. Quitting the same session again replaces that file.
  • On the next interactive session_start: the session claims each pending file by renaming it to <file>.<pid>.claimed. Files claimed by a process that is still alive are skipped, and ones left by a dead process are taken over. It then writes each summary in the background, one at a time, into the daily log of the day the session ended, with the original timestamp. A run in print mode leaves them alone.
  • On failure: no key, an error or the timeout send the entry back for the next session, up to 3 tries. A late answer after the timeout is dropped, so a retry cannot write it twice. A summary whose every section is "None." is still dropped.
  • Timeout: PI_MEMORY_EXIT_SUMMARY_TIMEOUT_MS now bounds the background call, and its default goes from 10 s to 60 s. 10 s was often too short for a long session, and nothing is waiting on it anymore.

Verified

  • bun test test/unit.test.ts passes: 197 → 203 tests. The new tests cover the daily log of the end day, replacing a session's pending entry, dropping an empty summary, the 3-try limit, claims held by live and by dead processes, and the interactive-only start. The tests that expected the model call at quit now expect it from the next session.
  • npm run lint and npm run build are clean.
  • In a pty with a copy of a 13-message session, two Ctrl+C now exit in 0.1 s instead of 9.8 s, and the resume line is printed. The next interactive session wrote the summary under the original date and end time, and removed the pending file.

Related

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.

Quitting hangs with nothing on screen while the exit summary runs, and the Ctrl+C that follows kills pi

1 participant