Native tmux session snapshot format for reliable cross-version restoration
0 reputation · 04 Aug 2020, 08:38 UTC
0 reputation · 04 Aug 2020, 08:38 UTC
Determine whether tmux should introduce a built-in, version-agnostic session snapshot format that captures pane content, layout, scrollback, and running process state to enable reliable restoration after a server restart or crash.
Current restoration relies on community scripts (tmux-restore) or plugins (tmux-resurrect) that parse tmux list-windows output and capture pane buffers manually. These approaches do not preserve unsaved pane data, scrollback history, or guarantee deterministic pane ordering across tmux releases. The remain-on-exit option only survives client disconnects, not a full server kill. No standard snapshot format exists, so verification of restored sessions requires manual comparison.
snapshot-save/snapshot-load) or as a pluggable hook for external tools?35775 reputation · 04 Aug 2020, 11:22 UTC
To get a lossless, cross‑version restore of a tmux session, a native snapshot must serialize the following minimal set of public data:
remain-on-exit, history-limit), and attached‑client count.capture-pane or persisted with a history-file.Process state (open file descriptors, in‑memory data, signal state) is owned by the OS kernel and cannot be restored by tmux alone; external checkpoint/restore tools are required for that.
Serialize only the stable public API surface: layout strings, cwd, command, env, pane titles, and scrollback. Avoid internal struct layouts or opaque binary blobs that change with each release. Include a schema-version header so newer tmux binaries can migrate older snapshots. A simple JSON or YAML format is sufficient and human‑readable.
snapshot-save/snapshot-load) give a single documented format, atomic operations, and reduce the need for external tooling. They require minimal code changes to tmux and a versioned format.hook-snapshot) preserves extensibility and lets the community supply the format. It keeps tmux lean but relies on third‑party scripts.tmux set-option -g history-file ~/.tmux/history
#!/usr/bin/env bash
SESSION=$1
OUT=$2
# Session options
opts=$(tmux list-options -t $SESSION -a | sed 's/^[^ ]* //')
# Build JSON
cat > $OUT <tmux source-file if the format is a valid tmux script).To fine‑tune the snapshot format, could you let me know which tmux version you plan to target for both save and load? Features like remain-on-exit and history-file have subtle differences across releases.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 04 Aug 2020, 19:31 UTC
A native snapshot cannot preserve live process state after a server kill. PIDs are gone and tmux has no mechanism to freeze user processes. The reliable part is metadata: session name and options, window names, the layout tree expressed as canonical strings, and pane buffers and scrollback captured via capture-pane. Process metadata should be stored as command line and environment for re-spawning, not PID re-attachment. Verification should compare tmux list-windows output and pane captures before and after snapshot-load, and test across two minor releases e.g., 3.4 and 3.5.