You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 24171e3
Browse filesBrowse the repository at this point in the historyBrowse files
feat(state): persist through one checksummed journal (C2)
The shell state is now saved through `journal`: one file,
`.vsh_state.journal`, of framed records. Every mutation that must
survive a restart is one record, appended and synced, so a crash leaves
the state before or after it. The journal is rewritten as a single
snapshot record, all-or-nothing, once it outgrows the history. The code
mirrors the Agda model (`proofs/agda/JournalModel.agda`); it is not
derived from it.
What changes for a user:
- A saved state that cannot be read stops the shell from starting, and
the file is left as it is. Before, the shell started with an empty
history, and the next write replaced the file.
- Bytes at the end of the journal that are not a complete record (an
interrupted write) are set aside in a `.rejected.` file, reported, and
removed from the journal.
- An old `.vsh_state.json` is converted on first start and kept as
`.vsh_state.json.migrated`.
- Rollback marks each operation undone as it reverses it, so `undo` no
longer tries to reverse it again (`begin t; touch f; rollback; undo`
failed on main). It skips operations already undone inside the
transaction. It closes the transaction only when every operation has
been reversed; if one cannot be, the transaction stays open.
- Transaction begin, commit and rollback are journal records, no longer
whole-state rewrites.
Tests:
- `journal_crash_tests` now tolerates no failing class. On real files:
3,070 crash states. On simulated storage that implements the model's
file, after every storage call: 3,079 crash images, each required to
open, to recover the state before or after the interrupted step, to
recover the state after it once the step was acknowledged, and to
keep later work. Four deliberate bugs were each caught (no sync, a
trim left out of its record, a rollback written as a commit, a torn
tail left in place).
- Unit tests for an old-format file (a literal fixture), a damaged
old-format file, an unknown record, a newer snapshot version, and
failed appends, syncs and rewrites.
Local results: cargo fmt and clippy clean; cargo test 862 passed, 0
failed; stress suite 11 passed (82 s on ext4, 39 s on tmpfs). The CI
stress step now puts its temporary directories on tmpfs, so that it
measures the shell and not the runner's disk.
Still open on this branch: the journal lives in the session root, so
shell commands can delete or alter it and two shells on one root are not
kept apart (C3); deleted file contents are still inside history records
(C4).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDjNR1ZoYKEPxSKE2nq
Copy file name to clipboardExpand all lines: EXPLAINME.adoc
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,10 +127,10 @@ reproduce. Absence of a tool is an open obligation, not a passing leg
127
127
| About the model only. The crash model (synced bytes survive; the unsynced part survives as a prefix) is an assumption about storage, and reordered or partly written blocks are outside it. No property of the checksum is proved or needed
| The code predates the model. Its two-file journal (a snapshot and an append log) fails two crash classes, which the harness pins in `KNOWN_OPEN`. Until the code is rebuilt on the model's storage interface this row stays `open`; after that it can be at most `tested-only`
130
+
| tested-only
131
+
| `cargo test --test journal_crash_tests`: 3,079 crash images on simulated storage that implements the model's file, and 3,070 crash states on real files, none failing (2026-11-17, local); four deliberate bugs were each caught
| Written to mirror the model, not derived from it or proved against it. One scripted session, not all sessions. The journal file still lives in the session root, so the shell's own commands can delete or alter it; the model does not cover that
134
134
135
135
| Same theorems restated in Z3 (Isabelle and Mizar archived 2026-11-09)
136
136
| argued (the ledger word for PROOF-POLICY §5 `ASSUMED`: a direct SMT run with no proof certificate)
Copy file name to clipboardExpand all lines: docs/plans/VSH-ROUTE-PLAN-2026-11-04.adoc
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -967,7 +967,7 @@ and ends at a machine-checked gate.
967
967
|Step |What |Gate |Status
968
968
969
969
|C1 |Journal model in Agda (OD-30): record framing, event replay, a file and crash model |Checks under the estate invocation, in `All.agda` |Done (section 14.4)
970
-
|C2 |One file of length-prefixed, checksummed records behind a small storage interface (append, sync, atomic replace, read), with a real implementation and a simulated one that loses exactly what the model's crash may lose. Compaction writes one snapshot record to a new file, syncs it, renames it over the old one and syncs the directory. A failed load is an error that stops the shell from writing; the files are kept. Rollback writes a record that marks each reversed operation undone. Old `.vsh_state.json` files still load (fixture test) |`KNOWN_OPEN` is empty; the harness also runs against the simulated storage |Next
970
+
|C2 |One file of length-prefixed, checksummed records behind a small storage interface (append, sync, atomic replace, read), with a real implementation and a simulated one that loses exactly what the model's crash may lose. Compaction writes one snapshot record to a new file, syncs it, renames it over the old one and syncs the directory. A failed load is an error that stops the shell from writing; the files are kept. Rollback writes a record that marks each reversed operation undone. Old `.vsh_state.json` files still load (fixture test) |No failing crash class; the harness also runs against the simulated storage |Done (section 14.4a)
971
971
|C3 |State moves out of the command root to an owner-only directory keyed by session root (OD-12a), opened with `O_NOFOLLOW`, checked through the descriptor, and held under an exclusive lock for the life of the shell |Shell commands cannot delete or edit state; a second shell on the same root is refused; a two-instance test passes |Open
972
972
|C4 |Deleted-file contents go to a content-addressed blob store, not into the history |Removing 100 MB no longer writes about 300 MB of JSON |Open
973
973
|===
@@ -1035,6 +1035,34 @@ Limits:
1035
1035
* A checksum cannot rule out bytes that were never written as a record but
1036
1036
happen to match.
1037
1037
1038
+
[[c2-result]]
1039
+
*14.4a C2 result (Measured 2026-11-17, local).* The shell state now persists
1040
+
through `impl/rust-cli/src/journal.rs`: one file, `.vsh_state.journal`, of
1041
+
records framed as a 4-byte length, the payload and its SHA-256. Each mutation
1042
+
is one record, appended and synced. The crash harness finds no failing class:
1043
+
3,079 crash images on the simulated storage (the model's file: synced bytes,
1044
+
and every prefix of the unsynced ones, after every storage call) and 3,070
1045
+
crash states on real files. Four deliberate bugs (no sync, a trim left out of
1046
+
the record, a rollback written as a commit, a torn tail left in place) were
1047
+
each caught. `cargo test`: 862 passed, 0 failed. An old `.vsh_state.json` is
1048
+
converted on first start and kept under a new name. A sync costs about 0.15 ms
1049
+
here (p95 0.43 ms), under the 2 ms threshold for syncing every record; the
1050
+
stress suite takes 82 s on disk and 39 s on tmpfs, so its CI step uses tmpfs.
1051
+
1052
+
Three behaviours changed with it, each following the model. They are the
1053
+
owner's to confirm:
1054
+
1055
+
* A saved state that cannot be read stops the shell from starting, with the
1056
+
file left as it is. Before, the shell started with an empty history.
1057
+
* Rollback marks the operations it reverses as undone, so `redo` can bring
1058
+
them back one at a time.
1059
+
* If rollback cannot reverse an operation, the transaction stays open, to be
1060
+
rolled back again or committed. Before, it was closed with the operation
1061
+
still in place.
1062
+
1063
+
Still open in Phase C: the journal lives in the session root (C3), and deleted
1064
+
file contents are still inside the history records (C4).
1065
+
1038
1066
Design choices the model fixes for C2:
1039
1067
1040
1068
* The history is append-only. Undo and rollback mark entries; redo records a new
0 commit comments