M1.7: crash-recovery journal and restore dialog

Dirty buffers are written atomically to <data_dir>/recovery/<project-id>/
about 1 s after the last edit (at most 2 s while typing), from pump_vfs,
never per keystroke. Entries are removed on save, close (also force),
forced project close/open and recovery.discard. project.open emits
recoveryAvailable; recovery.list/restore/discard; restored buffers are
dirty and keep line ending and BOM. Corrupt entries are moved aside and
reported as warning notifications.

UI: restore dialog in ui/src/components/recovery (Restore all, Restore
selected, Discard, time, changed-on-disk hint), catalog keys and runtime
allow-list. Tests: crash/restore with CRLF + BOM, corrupt entries, removal
paths, property test of random edits, headless control-channel test,
Vitest for the dialog. Docs: architecture, parity, gaps, ROADMAP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-16 15:54:52 +02:00
parent 6d976ed03e
commit 0b40eb90f8
27 changed files with 2222 additions and 27 deletions

View file

@ -114,7 +114,8 @@ impl Engine {
}
/// Applies pending changes on disk (reloads clean buffers, reports
/// changed directories and conflicts) and returns every queued event.
/// changed directories and conflicts), writes due recovery-journal
/// entries (see [`crate::journal`]) and returns every queued event.
/// Hosts call it regularly, e.g. every 100 ms from a background thread.
///
/// # Errors
@ -124,6 +125,23 @@ impl Engine {
let state = &mut self.state;
guard::run(|| {
crate::workspace::pump(state);
crate::journal::tick(state, std::time::Instant::now());
Ok(())
})?;
Ok(state.take_events())
}
/// Writes every unsaved edit to the recovery journal now instead of
/// after the debounce, and returns every queued event. For tests and
/// for hosts that are about to stop.
///
/// # Errors
/// [`EngineError::Internal`] if writing panicked; the queued events stay
/// queued.
pub fn flush_journal(&mut self) -> Result<Vec<crate::Event>, EngineError> {
let state = &mut self.state;
guard::run(|| {
crate::journal::flush(state);
Ok(())
})?;
Ok(state.take_events())
@ -283,6 +301,9 @@ mod tests {
"project.close",
"project.open",
"project.openDialog",
"recovery.discard",
"recovery.list",
"recovery.restore",
"settings.get",
"settings.list",
"settings.reset",