Skip to content

fix(editor): restore the terminal promptly on quit - #278

Merged
fcoury merged 1 commit into
mainfrom
fcoury/quit-latency
Aug 18, 2026
Merged

fcoury merged 1 commit into
mainfrom
fcoury/quit-latency

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Why

:q could leave the editor visibly frozen while command history, recovery snapshots, plugin hooks, and external services finished shutting down. Local macOS PTY measurements put the original clean-quit screen transition at 39.3 ms median, with a 210 ms outlier. Recovery writes must remain durable, but they do not need to keep the alternate screen visible.

What changed

  • Batch exit-hook preference updates, start agent shutdown alongside independent cleanup, and defer accepted quit commands' history writes. Rejected or failed quit commands still persist history immediately.
  • Restore terminal modes as soon as the interactive loop stops, then finish recovery and service cleanup. Repeated restoration is safe, and restoration errors do not skip the final snapshot.
  • Add shutdown timing spans, lifecycle/persistence regressions, and scripts/quit_bench.py.

The final local measurements were 0.605 ms median / 1.092 ms maximum for clean quit, and 0.593 ms median / 1.086 ms maximum across 30 forced quits. Full process exit still waits for cleanup. These measurements used isolated configuration with AI/LSP disabled; they are not a physical-display or network-service latency guarantee. Full methodology and results are in docs/performance-quit-latency-2026-08-18.md.

How to Test

  1. Build with cargo build --locked --release --bin red.
  2. Run python3 scripts/quit_bench.py --binary target/release/red --runs 10. Expect one alternate-screen restore, normal terminal flags, persisted quit history, and separate screen/process timings.
  3. Run python3 scripts/quit_bench.py --binary target/release/red --dirty --runs 5. Expect ordinary :q to refuse unsaved changes, :q! to restore the terminal, the source file to remain unchanged, and the recovery snapshot to contain the edit.
  4. Exercise preference-heavy exits with --storage-updates 200 and --preference-kib 8192. Expect plugin state and command history to survive without delaying the screen transition until the writes finish.

Validated at 68c769c: 2,844 Rust tests passed, one ignored, strict all-targets/all-features Clippy passed, and the retained tmux clean/rejected/forced-quit walkthrough passed. Focused regressions include interactive_shutdown_restores_and_persists_before_waiting_for_agent, interactive_shutdown_persists_even_when_terminal_restore_fails, and the accepted/rejected quit-history tests.

@fcoury
fcoury merged commit 5e39d4b into main Aug 18, 2026
10 checks passed
@fcoury
fcoury deleted the fcoury/quit-latency branch August 18, 2026 03:33
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.

2 participants