Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,76 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
row can be `proven`; the Mizar target swallows failure (`|| echo`). Both are
logged as AP-6, AP-7 and AP-8 in the audit.

=== Fixed — 2026-11-17 (redo keeps undo data; undo of redirections)

- `redo` recorded the re-applied operation with no undo data, so
`rm f; undo; redo; undo` restored `f` empty, a redone `chmod`/`chown` changed
nothing and could not be undone, and a second redo of `cp`/`ln -s` failed.
Each operation now has one function that checks its preconditions, captures
its undo data and applies it; the command and `redo` both call it.
- `redo` now restores what an operation produced (the mode of a `chmod`, the
owner of a `chown`, the bytes a `>`/`>>` redirection wrote, a variable's
value). `undo` reads that state just before reversing it and keeps it in
memory with the redo entry. File content over `VSH_REDO_CAPTURE_LIMIT` bytes
(shell or environment variable; default 10 MiB; `0` = no limit) is not kept,
and redo of that entry says so. The limit is enforced while reading, so a
file that grows during the undo cannot take more memory than the limit.
- A `redo` that fails records nothing and stays on the redo stack. It also
leaves the filesystem as it found it, including when a file write fails
part-way: the partial file is removed, the overwritten bytes are put back,
or the partial append is cut off. The one exception is when that clean-up
fails too (an I/O error, or no space on a copy-on-write filesystem): the
file is then left changed, the error says so, and a retry would record the
damaged content as undo data. `redo` of
`cp`, `mv` and `touch` no longer overwrites a path that reappeared after the
undo.
- `rm` (and redo of `rm`) no longer deletes a file whose content it cannot
read. It used to delete it and record empty undo data, so undo brought the
file back empty. It now fails, leaves the file in place and points to
`obliterate` for irreversible deletion.
- `redo` refuses to recreate a file whose content undo could not read
(recorded as not captured, with the reason), where it used to recreate it
empty. A `cp` whose copy fails part-way removes the partial destination, for
the command and for its redo. Redo of an assignment restores the exported
flag as well as the value.
- Undo of a `>`/`>>` redirection failed whenever the sandbox root was not `/`
(the default root is the current directory): the history held an absolute
path that undo resolved under the root a second time. History paths for
redirections are now relative to the root.
- `touch` creates its file with `create_new`, so it no longer writes through a
dangling symbolic link.
- `chmod` and `chown` on a symbolic link recorded the link's own mode and
owner while changing the file it points to. Undo of that `chmod` set the
file to mode 0777, and redo of either restored the wrong value. Both now
record the mode and owner of the file they change.
- Redo of `touch`, or of a `>` redirection that created a file, brings the
file back with the mode it had when it was undone. It used to come back
with the default mode, so a file made private in between returned readable
by others. The owner is not restored.
- Redo of a redirection that replaced or appended to a file now reads,
measures and writes through one open file. Before, a file renamed over the
path between the read and the write was overwritten, and the undo data
recorded was the other file's.
- Redo of an assignment whose variable was no longer set when it was undone
(a function's local, removed when the function returned) failed with "not
captured". It now restores the variable as not set.
- Undo of a `>>` redirection no longer grows a file that was cut shorter
outside the history in the meantime. It used to extend the file to its
earlier size with zero bytes.
- Redo of `unset` succeeds when the variable is already not set, where it
failed and stayed on the redo stack.
- Idris2 model: `redoUndoIdentity`, `undoRedoUndoIdentity`,
`redoUndoComposition` added to `Filesystem.Composition`. Their status is
the proof ledger's row for the undo/redo stack laws
(`proven-with-postulates`); the Rust link stays `tested-only`.
- Known and *not* fixed here (tests exclude them, see
`impl/rust-cli/tests/redo_roundtrip_tests.rs`): undo of `rm`/`rmdir` does
not restore the mode; undo of `unset` does not restore the exported flag;
`rm` and redirections follow symbolic links and their undo does not account
for it. Undo and redo identify a file by its path only: a file replaced
outside the history between an operation and its undo is overwritten or cut
by that undo.

=== Planned
- Glob expansion (*.txt, ?.rs, [a-z]*)
- Quote processing (proper escaping, single/double quotes)
Expand Down
12 changes: 12 additions & 0 deletions EXPLAINME.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ reproduce. Absence of a tool is an open obligation, not a passing leg
| `impl/rust-cli/tests/model_oracle_correspondence.rs`
| Sampled, precondition-respecting sequences only; a divergence would be a real bug but agreement is not a proof

| Undo then redo, and redo then undo, are identities on the undo/redo stack model (single step and `n`-fold)
| proven-with-postulates
| Idris2 0.8.0, `idris2 --build valence-shell.ipkg` (`--total`), re-run 2026-11-17, plus the `believe_me` gate; CI `idris-verification.yml`
| `proofs/idris2/src/Filesystem/Composition.idr`: `undoRedoIdentity`, `undoRedoComposition`, and (2026-11-17) `redoUndoIdentity`, `undoRedoUndoIdentity`, `redoUndoComposition`
| `redoUndoIdentity` and `redoUndoComposition` use no axiom; they are conditional on a per-step reversibility premise. `undoRedoIdentity` and its corollary `undoRedoUndoIdentity` discharge that premise through lemmas resting on the registered `axStringEqRefl`. The model has five operations (mkdir, rmdir, touch, rm, write) on a flat path map: no cp, mv, links, modes, ownership, variables or redirections. It says nothing about the Rust `redo`

| The Rust `undo`/`redo` round trip restores state for every operation type that reaches the history
| tested-only
| `cargo test --test redo_roundtrip_tests` (22 tests: 19 operation scenarios, 48 random sequences via `proptest`) and `test_redo_then_undo_correspondence`
| `impl/rust-cli/tests/redo_roundtrip_tests.rs`, `impl/rust-cli/tests/redo_write_failure_tests.rs` (a redo whose write fails part-way, forced with `RLIMIT_FSIZE`), `impl/rust-cli/tests/correspondence_tests.rs`
| Whole-sandbox comparison (bytes, modes, owners, link targets, one shell variable). Three scenarios assert only the redo laws because undo itself loses data there (mode on `rm`/`rmdir`, exported flag on `unset`); random sequences exclude symbolic links for the same reason; the `chown` scenario runs only as root. Not a proof and not a refinement of the Idris2 model

| Idris2 ABI layout, encodings and round-trips match the C header
| tested-only
| `--total`, plus `scripts/check-abi-layout.sh`
Expand Down
69 changes: 69 additions & 0 deletions docs/LEAN4_RUST_CORRESPONDENCE.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,75 @@ let op = Operation::new(OperationType::DeleteFile, path.to_string(), None)
* ✅ Restored on undo
* ✅ Correspondence maintained

==== Redo, and redo followed by undo (added 2026-11-17)

The redo stack is modelled only in Idris2
(`+proofs/idris2/src/Filesystem/Composition.idr+`); the Lean and Coq
developments state single-step and sequence undo, with no redo stack.

[cols="2,3",options="header"]
|===
| Model statement (Idris2) | What it says

| `+undoRedoIdentity+`
| `+undo (execute op s) >>= redo = Just (execute op s)+`. The equality is on
the whole `+UndoState+`: filesystem, undo stack and redo stack.

| `+undoRedoUndoIdentity+`
| Undo, redo, undo equals undo. Corollary of the above.

| `+redoUndoIdentity+`
| From any state with an operation to redo, redo then undo is the identity,
given that the operation inverts at the current filesystem.

| `+redoUndoComposition+`
| `+n+` redos followed by `+n+` undos is the identity, over a `+Redoable+`
witness (mirror of `+undoRedoComposition+`).
|===

Status: recorded in the proof ledger, `EXPLAINME.adoc#proof-ledger` (the row
for the undo/redo stack model); it is not restated here. The model has five
operations (mkdir, rmdir, touch, rm, write) on a flat path map. The link to
the Rust code is `tested-only`.

The model re-applies the *same* operation value on redo, so the redone entry
on the undo stack is identical to the original. The Rust `+redo+` did not do
that before 2026-11-17: it re-executed the operation and recorded it with no
undo data, so the filesystem matched after a redo but the history record did
not, and the next undo restored an empty file (`+rm f; undo; redo; undo+`).
The existing tests compared only the filesystem after a redo, so they did not
see it.

What the Rust does now (`+impl/rust-cli/src/commands.rs+`):

* Each operation has one `+apply_*+` function that checks its preconditions,
captures its undo data and changes the filesystem. The command and `+redo+`
both call it, so a redone record carries freshly captured undo data.
* What an operation *produced* (the mode a `+chmod+` set, the bytes a
redirection wrote, a variable's new value) is read by `+undo+` just before it
reverses the operation and kept on the in-memory redo entry
(`+state::RedoData+`). File content over `+VSH_REDO_CAPTURE_LIMIT+` bytes
(default 10 MiB, `+0+` for no limit) is not kept; redo of that entry fails
with the reason.
* A redo that fails records nothing and stays on the redo stack. It also
leaves the filesystem as it found it, including when a file write fails
part-way: the partial file is removed, the overwritten bytes are put back, or
the partial append is cut off. The one exception is when that clean-up fails
too (an I/O error, or no space on a copy-on-write filesystem): the file is
then left changed, the error says so, and a retry would record the damaged
content as undo data. That double failure is not tested; it needs fault
injection below the filesystem calls.

Tests (`tested-only`): `+impl/rust-cli/tests/redo_roundtrip_tests.rs+`
(every operation type, random sequences, the capture limit) and
`+test_redo_then_undo_correspondence+` in `+correspondence_tests.rs+`, which
compares the history records as well as the filesystem.

Not covered by the model: cp, mv, symbolic links, chmod, chown, variables,
redirections, nested directories. Known undo defects that these tests
exclude are listed in the test file (`+undo_is_exact: false+` and the note on
symbolic links).

'''''

=== Composition Theorems
Expand Down
Loading
Loading