ADR 0197 — Restore writes indexed files back from their snapshots
- Status: Accepted
- Date: 2026-11-22
- Related: ADR 0060 (redaction placeholders), ADR 0064 (the queue lock restore does not take), ADR 0072 (a folder’s workspace), ADR 0081 (snapshots), ADR 0195 (data files restore exactly), ADR 0196 (deleted files keep their snapshots), source memory
Context
Section titled “Context”After a WSL wipe the owner rebuilt lost plan files from Imprint’s source snapshots by reading them back with read_source, page by page, and writing them out by hand. No command did it. ADR 0195 made large data files restore byte for byte, and ADR 0196 keeps a deleted file’s snapshot instead of pruning it, so a whole folder can now be written back.
Three properties of snapshots shape such a command:
- They hold redacted text (ADR 0060), so a file with a secret cannot come back exactly.
- Extracted documents (PDF, Office, images read by OCR, audio transcripts) hold only the text read out of them.
- Their provenance, the original path included, also arrives from paired devices, so a path in a snapshot is untrusted input.
Decision
Section titled “Decision”imprint restore <dir> [--to <out>]restores the heads whose recordedsource_pathlies under<dir>and that this device recorded (device.local_source). Both paths are resolved, as pruning compares them. Each file goes back to its original path, or under<out>at its path relative to<dir>. The workspace is--workspace, else the folder’s (ADR 0072), else the active one.imprint restore --project NAME --to <out>restores every file head of the project, from any device, under<out>at its path within the project:source_relative_path, or the source key without its project.--tois required, since another device’s absolute path means nothing here.- Preview by default;
--applywrites.- Only destinations that do not exist are written.
--allalso compares those that exist: an identical file is reported unchanged, a different one is kept unless--overwriteis given.- When two heads restore to one path, the newer one is written and the other reported.
- What is written depends on the snapshot.
- Kind
text(code, text, data files kept whole): the text as UTF-8 bytes with its line endings as stored. Its SHA-256 is compared with the recordedsource_hash, and the file is reported as exact (its modification time is restored too), as holding redacted secrets (with their count), or as differing. - Documents (kind
extracted; an audio file’s transcript, kindconversationwithmedia: audio; a spreadsheet kept whole, whose text is extracted): the text, as<name>.extracted.txtbeside where the document was. It is written only when the document itself is not at the destination, and never under the document’s own name. - Conversations, URLs and inline content are not files: counted and skipped.
- Kind
- Paths are untrusted.
- A project-relative path goes through
device.relative_path, which refuses absolute paths, drive letters,..and NUL. - Every destination is resolved and must lie inside the destination folder, so a link or junction inside it cannot lead out. A destination that is itself a link is refused.
- A refused file is an error.
- A project-relative path goes through
- Writing is all or nothing per file. Each file is written to a temporary file in its folder, then renamed over the destination. Restore never writes over a file that appeared meanwhile, and a replaced file keeps its permissions. Long Windows paths go through their extended-length spelling (ADR 0147).
- Output lists up to 200 files, errors first, then totals. Restore exits nonzero when anything was refused or failed.
- No queue lock. Restore reads snapshot heads (one SQLite read each, validated by its checksums) and writes outside the data folder. A refresh running meanwhile replaces a head atomically (ADR 0081), so restore writes either the old or the new version of a file. It is a CLI command only, not in the dashboard’s command catalog.
Rejected alternatives
Section titled “Rejected alternatives”- Write every snapshot under its file’s own name. A PDF, DOCX or XLSX would be replaced by plain text under a name that promises the format: a broken file that looks restored.
- Restore another device’s files to their recorded absolute paths. A path from synced data would choose where this device writes, possibly a path of another operating system.
--projectplaces them under a folder the user names. - Overwrite, or rewrite every file, by default. A snapshot is the file as of its last refresh. A file that survived the loss may hold newer edits, and overwriting it would lose them.
- Take the queue lock, like scrub. Restore would wait behind long ingests (ADR 0064) for work that changes no memory, and nothing it does conflicts with them.
- Offer restore in the dashboard or as an MCP tool. Both would write into the user’s folders from a server process or an agent session. The case at hand is a person rebuilding a folder from a terminal after a loss.
Consequences
Section titled “Consequences”- A lost folder comes back in one command. Secrets come back as placeholders, counted in the report, and documents as their text.
- A file edited after its last refresh restores as of that refresh; the report cannot tell.
- A data file that was not UTF-8 holds extracted text under kind
text(ADR 0195). It is written under its name and reported as differing. - A head replaced by a paired device’s copy is not local: a full-workspace import from a release without delta sync, or a bundle import, does that.
<dir>mode skips such heads;--projectrestores them. - Restored files inside a scanned folder are indexed by the next refresh as new versions, placeholders included.
- A snapshot of a file indexed only as legacy chunks does not exist, so restore cannot write that file (
refresh --forcecreates snapshots, ADR 0081).
Invalidation conditions
Section titled “Invalidation conditions”- If snapshots gain version history, let restore choose a version or a date.
- If snapshots ever keep a document’s original bytes, write documents under their own names.
- If restoring from the dashboard or an agent is wanted, add it with the same path refusals and the dashboard’s confirmation.
- If restore and a refresh of the same folder are found to interfere in practice, take the queue lock.
Validation
Section titled “Validation”tests/test_restore.py,RestoreTests(9 tests), on the Windows install’s Python 3.13 venv from a native copy, covers:- Preview and apply: a preview writes nothing;
--applyrestores a CRLF, non-ASCII file byte for byte with its modification time, counts a redacted GitHub token, and leaves no temporary file. - Existing files: they are left alone, compared with
--all, and replaced only with--overwrite. - Destinations:
--towrites at the same relative paths;--projectwrites another device’s file under--to, which<dir>mode skips;--projectwithout--tois a usage error. - Refusals:
.., absolute and drive-letter paths are refused and the exit code is 1. A junction inside--tothat leads outside is refused (a symbolic link on POSIX). - Documents: an extracted PDF and a kept-whole spreadsheet are written as
.extracted.txt, not once the PDF is back; a conversation is skipped. - Conflicts: the newer of two heads of one path is written.
- Preview and apply: a preview writes nothing;
- Go 1.26.11 on WSL (linux/amd64):
go vet ./...andgo test ./..., includingTestRestoreArgsMakeTheFolderAndDestinationAbsolute. - End to end on Windows 11:
imprint.execross-compiled for windows/amd64 and run against a disposable data folder that ingest and refresh had filled.- It resolved the folder’s workspace from its approved root.
- A preview wrote nothing;
--applyrestored a deleted folder, exact apart from the counted secret. --projectwithout--toexited 2; with--toit wrote the project’s files.
- Not run: the binary against the live install, macOS, and a Windows runtime restoring a WSL folder through
\\wsl.localhost.