Skip to content

Detached sessions L1: make session state survive a crash the same as a clean quit #181

Description

@arzafran

What

Today a clean quit saves layout, directories, and scrollback. A crash or a kill -9 saves whatever was in the last snapshot, which can be nothing. Either way, relaunching replays saved scrollback text into a brand new shell.

This is the first layer of the detached-sessions plan (docs/plans/detached-sessions.md, section 0). It does not keep processes alive. It makes the state durable, so crash and clean quit produce the same result, and it builds the substrate the later layer reattaches to.

Why it matters

It is worth shipping on its own, and it is not thrown away when we do process survival: the same journal becomes the reattach log.

Scope

  1. Append-only WAL of PTY output per surface, written from Ghostty's io-reader thread with a debounced fsync so a hard kill loses at most ~100ms
  2. Mirror live VT screen state (grid, cursor, modes) into an mmap'd file so relaunch repaints a frame instead of replaying a transcript
  3. Per-session fact files (UUID, PID, PTY path, cwd, argv) so the next launch can answer "what was running" with no live process
  4. On any restore failure, fall open to a read-only tail of the last output instead of an error
  5. One restore banner per launch ("3 sessions found"), not one dialog per pane

Risks

  • Torn mmap writes are the load-bearing risk. Double-buffer with an atomic generation flip so a reader sees a complete frame or the previous one, never a half-written grid.
  • Typing latency is non-negotiable. The tap point must stay off the keystroke path; measure before building (see #TODO spike PR).

Verify

Run a build in a surface, kill -9 the app mid-run, relaunch: the pane repaints its last frame and the tail of output is intact. Compare against a clean quit and the result should be indistinguishable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions