[PR #19805] Add periodic buffer persistence to protect against unexpected termination #31965

Open
opened 2026-01-31 09:50:39 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/19805

State: open
Merged: No


Summary

This PR adds periodic buffer persistence to protect against unexpected termination (BSOD, power failure, Task Manager kill).

Fixes #19804

The Problem

Previously, terminal buffer content was only persisted on graceful exit:

  • At end of message loop (normal quit)
  • On WM_ENDSESSION (graceful OS shutdown)

The 5-minute persistence timer only saved layout (tabs, panes, positions), not buffer content. This meant:

What Gets Saved When Survives Unexpected Termination
Tab layout Every 5 minutes Yes
Buffer content Only on graceful exit No

Users running long-lived sessions (Claude Code, SSH, development environments) would lose hours of terminal history on crash, even though tabs appeared to be "restored."

The Solution

  • Extract buffer persistence into a new _persistBuffers() function
  • Call _persistBuffers() on the existing 5-minute persistence timer
  • Refactor _finalizeSessionPersistence() to use the shared function

Now buffer content is saved every 5 minutes alongside layout.

Validation Steps Performed

  • Code review for correctness
  • Verified refactored _finalizeSessionPersistence() maintains cleanup behavior
  • Confirmed _persistBuffers() respects FirstWindowPreference::PersistedLayoutAndContent setting

PR Checklist


🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/microsoft/terminal/pull/19805 **State:** open **Merged:** No --- ## Summary This PR adds periodic buffer persistence to protect against unexpected termination (BSOD, power failure, Task Manager kill). Fixes #19804 ### The Problem Previously, terminal buffer content was only persisted on graceful exit: - At end of message loop (normal quit) - On `WM_ENDSESSION` (graceful OS shutdown) The 5-minute persistence timer only saved **layout** (tabs, panes, positions), not buffer content. This meant: | What Gets Saved | When | Survives Unexpected Termination | |-----------------|------|--------------------------------| | Tab layout | Every 5 minutes | ✅ Yes | | Buffer content | Only on graceful exit | ❌ **No** | Users running long-lived sessions (Claude Code, SSH, development environments) would lose hours of terminal history on crash, even though tabs appeared to be "restored." ### The Solution - Extract buffer persistence into a new `_persistBuffers()` function - Call `_persistBuffers()` on the existing 5-minute persistence timer - Refactor `_finalizeSessionPersistence()` to use the shared function Now buffer content is saved every 5 minutes alongside layout. ## Validation Steps Performed - [x] Code review for correctness - [x] Verified refactored `_finalizeSessionPersistence()` maintains cleanup behavior - [x] Confirmed `_persistBuffers()` respects `FirstWindowPreference::PersistedLayoutAndContent` setting ## PR Checklist - [x] Closes #19804 - [x] Tests added/passed (N/A - existing persistence tests cover this code path) - [x] Documentation updated (N/A - no user-facing changes, existing setting controls behavior) - [x] Schema updated (N/A - no new settings) --- 🤖 Generated with [Claude Code](https://claude.ai/code)
claunia added the pull-request label 2026-01-31 09:50:39 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31965