Skip to content

Skip auto-save during boot grace to prevent restore clobber#159

Open
vivek8031 wants to merge 1 commit into
tmux-plugins:masterfrom
vivek8031:fix/skip-save-during-boot-grace
Open

Skip auto-save during boot grace to prevent restore clobber#159
vivek8031 wants to merge 1 commit into
tmux-plugins:masterfrom
vivek8031:fix/skip-save-during-boot-grace

Conversation

@vivek8031

Copy link
Copy Markdown

Problem

When @continuum-restore on is set, a status-bar driven continuum_save.sh can fire after the bootstrap (single-session) tmux state has been created but before the backgrounded continuum_restore.sh has finished restoring the saved sessions. The save then overwrites the resurrect last symlink with the bootstrap-only state, so auto-restore reads a near-empty file on the next boot and brings nothing back.

This matches symptoms reported in:

Reproduction

# With @continuum-restore on and any non-empty saved state:
tmux kill-server
tmux new-session -d -s bootstrap   # status-bar fires before restore completes
# `last` symlink now points at a single-session save; restore reads it -> nothing useful

Fix

Add an in_boot_grace_window guard to continuum_save.sh's main loop. The guard only activates when @continuum-restore on is set (so users who don't auto-restore aren't affected) and blocks auto-save until uptime exceeds @continuum-restore-max-delay + 30s. The 30s buffer covers the actual restore work after the delay window for restore-start expires.

Verification

Tested against a separate tmux socket (-L test-patch) with @resurrect-save-script-path pointed at a probe script that logs invocations:

Test Uptime @continuum-restore Expected Got
1 21 s on skip skip ✅
2 42 s on save save ✅
3 1 s off save save ✅

Compatibility

  • No new tmux options introduced — reuses existing @continuum-restore-max-delay (default 10).
  • Behaviour unchanged when @continuum-restore is off or unset (default).
  • Behaviour unchanged after the boot window expires.

When @continuum-restore is on, a periodic auto-save can fire after the
bootstrap (single-session) tmux state is created but before the
backgrounded continuum_restore.sh has finished. The save then
overwrites the resurrect 'last' symlink with the bootstrap-only state,
so auto-restore reads a near-empty file and brings nothing back.

Reproduce: kill the tmux server, start it fresh (e.g. via
@continuum-boot or `tmux new-session -d`), and let auto-restore race
the next status-bar driven continuum_save. Affected users have
reported intermittent restore failures over the years (tmux-plugins#90, tmux-plugins#94,
joeywrites.dev/posts/fixing-broken-tmux-resurrect-save).

Add an in_boot_grace_window guard that, only when auto-restore is
enabled, blocks auto-save until uptime exceeds
@continuum-restore-max-delay + 30s. The 30s buffer covers the actual
restore work after the delay window expires. When auto-restore is
disabled the guard is a no-op, preserving existing behaviour.

Verified with three isolated tests against a separate tmux socket:
1. uptime=21s, restore=on   -> save SKIPPED (correct)
2. uptime=42s, restore=on   -> save FIRED   (correct)
3. uptime=1s,  restore=off  -> save FIRED   (correct, no false positive)
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.

1 participant