Repository navigation
Export and import workspaces with exact Reverie memories - #59
Conversation
j2msReginaldBot
left a comment
There was a problem hiding this comment.
Export, preview and import time grows quadratically with story length. In my tests, a history of 800 turns took about 40 s to import, and the same story is much faster in live play. Nothing I tested lost or corrupted data. I'd fix the scaling before merge because a workspace transfer has to work on long stories.
Reviewed at bb0f8cf on base 67cc505. The setup was Linux x64, Rust 1.99.1, and Reverie memrok-com/reverie#31 at f8b233b built from source.
Scaling (should fix)
I timed one story with two memory publications (one current, one drifted) using tests/workspace-archive.test.ts fixtures and a scripted reflector:
| Turns | API build | Export | Preview | Import | Live /stage |
|---|---|---|---|---|---|
| 100 | debug | 2.0 s | 2.1 s | 4.3 s | 32 ms |
| 200 | debug | 6.6 s | 8.0 s | 15.0 s | 79 ms |
| 400 | debug | 24.2 s | 32.6 s | 58.0 s | 153 ms |
| 400 | release | 3.8 s | n/a | 9.0 s | 53 ms |
| 800 | release | 16.3 s | n/a | 39.0 s | 61 ms |
Each doubling of turns multiplies the time by about 4. Extrapolating, about 1,600 turns would take several minutes to import. More publications, branches or scene headings add to that cost.
Cause:
ArchiveReader::commit(api/src/archive.rs:115) scans and clonesarchive.commitson every lookup. That makes eachancestry/project_branchcall over an archive O(C²).validate_hostcalls this projection once per branch (workspace_archive.rs:186), once per publication throughsource_for(:237, which may walk back through earlier heads at:139), and once per scene heading (:324).archive_api.rsrepeatssource_forfor every native memory (:104,:216,:263).archive::readruns the whole validation twice during import (:184,:289).
The live Store reader does not have this problem, which explains the gap with /stage.
Suggested fix: Index commits by id in ArchiveReader, or build the index once per story. Compute source_for once per publication and reuse it. That should bring the cost close to linear.
Two related points:
- Validating an untrusted archive is CPU-bound and has no cancellation check. The abort
select!inworkspace.rsdrops the future, but a runningspawn_blocking(archive::read)keeps going until it finishes. - The
source_forcalls inarchive_api.rsrun directly on async runtime threads rather than inblocking(...).
What I verified
cargo testinapi/: 46 passed on Linux.tests/workspace-archive.test.tswithDOXVELT_REVERIE_EXECUTABLEset to the #31 build: all 3 passed on Linux. They cover multi-story and multi-branch round trips, an identical re-export, redaction, occupied destinations, cancellation, Reverie startup failure and retry, and thecurrentreceipt. This covers part of the "Linux runtime unverified" note in the PR description.- No problems found in the rest of the code:
- publication goes through
renameat2(RENAME_NOREPLACE)/MoveFileExWwith no replace flag, from a staging directory on the same parent; - the staging marker stays out of the published tree;
- Reverie sessions use
kill_on_drop; - the restored configuration is limited to
version/actorModel/reflectionModel, so an archive cannot inject an executable path; .doxvelt,.dshand.gitare refused at the root of an imported source;- the date-ordering check on dependencies holds, because a scene's revision includes its date, so a re-dated slot can't be resolved as an earlier dependency;
- catalog and heading insert column order matches the schemas, and publication
rowidorder round-trips; INSERT OR IGNOREoncontent_revisionsis now followed by an equality check, so the legacy/packagesimport still rejects conflicting content.
- publication goes through
Not verified
Windows behavior, the DSH desktop browser runner on Linux, and archives created by a Reverie build other than #31. This PR still depends on #31 merging and a release that contains it.
j2msReginaldBot
left a comment
There was a problem hiding this comment.
Approving. Export, preview and import now scale about linearly with story length, which resolves my earlier finding. I found no new defects in aa6e958.
Re-reviewed on base 67cc505 on Linux x64 (Rust 1.99.1, Reverie memrok-com/reverie#31 at f8b233b built from source). I used the same benchmark as before: one story with two memory publications, where the earlier one is matched through a historical prefix.
| Turns (release API) | Export | Preview | Import | Before this fix |
|---|---|---|---|---|
| 400 | 0.32 s | 0.17 s | 0.45 s | 3.8 s export / 9.0 s import |
| 800 | 0.54 s | 0.31 s | 0.76 s | 16.3 s export / 39.0 s import |
| 1600 | 0.96 s | 0.56 s | 1.17 s | — |
What I checked in the fix:
- Commit index and ancestry. The DFS pre/post-order ranges in
is_ancestorare a correct ancestor test. The new Rust test compares it against full history walks on every pair of commits. Duplicate commit ids are still caught: the commit loop inverify_structurerejects them beforeordered_commits()is read. - Access validation. Carrying each parent's access links forward in DFS order checks the same thing as the old per-path replay, because a parent is always visited before its children.
- Historical prefix match (
matching_prefix). The hand-built SHA input reproducesjson_hashof the compact array, with and without thepublic-role-labels-v1marker; the unit test covers quotes and newlines in ids. A hash match is only a candidate: the scene is re-projected at that head and its revision checked again before its source is used.heads[p]is the parent of turnp, which is the latest head holding exactly the firstpturns. That is the same head the old backward walk found. - Body corrections. These are derived per branch from
Editorigins, so they behave as before. A publication made before a correction still matches on the source branch. - The
build_manual_commit_withshortcut. This also changes the live turn path. When the turn uses the current knowledge policy, has noaccessChanges, andexpectedHeadis the branch head, the projection is now skipped. In that case,append_effect_eventsonly uses the links when applyingaccessChanges, andfirst_impressionsis only read for legacy-policy turns. The skipped projection therefore had no effect on the commit, and the expected-head commit is still checked for existence. - Cancellation. It is now checked inside the blocking validation, file-hashing and staged-insert work. The new Rust test cancels during indexing, during semantic validation and during the transactional insert, and confirms each time that nothing was stored and a retry succeeds.
- Second read before publishing. It is now an integrity check only: checksum and source-file hashes. That is enough, because the semantic validation ran on the same checksummed bytes.
Tests:
cargo test --lockedinapi/: 50 passed.tests/workspace-archive.test.tswith the #31 Reverie build: 4 of 4 passed, including the new 160-turn round trip (export 1.0 s, preview 0.7 s, import 1.2 s on a debug API build).- CI
Validateis green on this head.
Still not verified by me: Windows behaviour and the DSH browser runner. Merging still depends on reverie#31 and a Reverie release that includes it.
Doxvelt's DSH plugin now offers Export / import for a complete workspace: authored collection, pinned content, accepted stories and alternate paths, episode dates, player scene headings, publication history, and exact Reverie memories. Review validates the archive and subjective source projections; import stages the whole restore and publishes a new workspace atomically without replacing an existing destination or calling a model.
Native memory goes through Reverie's new
exportMemory,previewImportandimportMemoryAPI. Preserves older memory publications and dependencies, rejects damaged or mismatched data, and supports retry after interruption or a lost response. Credentials, DSH chats, unaccepted drafts and installation-local navigation remain outside the archive. Existing single-simulation package routes retain their compatibility format; Pi ZIP migration is deferred.Archive transfer indexes immutable commits and branches once per reader, checks ancestry through indexed paths, carries access state through each history edge, and inserts commits in parent-first order. Current-policy manual turns without access mutations avoid rebuilding unused historical state; legacy and access-changing turns retain their full validation. Publication source projections are reused for every character. Historical revision prefixes are hashed incrementally, and only matching candidates are projected and verified. Source reconstruction and semantic verification run on workers with cooperative cancellation checks. A final checksum/source integrity reread preserves the publication guard without repeating semantic replay.
Release probes on this Windows workstation, using one story with an early and a current memory publication:
These are single-run diagnostics, not timing thresholds or a same-machine comparison with the reviewer's Linux measurements. Both probes verified an identical re-export and zero model calls during transfer. The default regression uses 160 turns;
DOXVELT_ARCHIVE_SCALE=400,800selects the larger cases.Validation on Windows:
npm run ui:buildandgit diff --checkpassed.npm run checkis not fully green: the final run had 499 TypeScript tests pass, 12 fail, and 1 skip. The same 12 failures previously reproduced serially in unchanged reference tests (saved-alternatives,saved-alternative-identities,sqlite-open), involving Windows SQLite cleanup locks and a lock-timing assertion. An earlier concurrent run also hit a Windows rename race indraft-acceptance-package; its isolated rerun and the final full run passed.GitHub Linux CI passed for
aa6e958, including the full required check, DSH plugin package verification and native API startup.Requires memrok-com/reverie#31 and an executable built with memory archive version 1; the currently released Reverie v0.2.0 lacks these operations. The reviewer verified the earlier commit's 46 Rust tests and 3 native archive tests on Linux. These review fixes were exercised locally on Windows; Linux desktop runtime behavior, real model quality and assistive-technology behavior remain unverified. Installer/bundled-binary release updates are not part of this PR.