Skip to content

Export and import workspaces with exact Reverie memories - #59

Merged
MichaelSchmidle merged 2 commits into
mainfrom
codex/workspace-export-import
Nov 17, 2026
Merged

MichaelSchmidle merged 2 commits into
mainfrom
codex/workspace-export-import

Conversation

@MichaelSchmidle

@MichaelSchmidle MichaelSchmidle commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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, previewImport and importMemory API. 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:

Turns Export Preview Import
400 304 ms 177 ms 728 ms
800 443 ms 279 ms 650 ms

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,800 selects the larger cases.

Validation on Windows:

  • All 50 Rust tests passed, including indexed ancestry equivalence, prefix revision encoding, publication source reuse, stale-cache rejection, cancellation after validation starts, transactional rollback and safe retry.
  • All 4 workspace archive integration tests passed against the updated native Reverie executable, including multiple stories/paths/publications, historical-prefix source reconstruction, identical re-export after restore, source integrity, occupied destinations, cancellation, native failure and safe retry. The additional 400-/800-turn release probes both passed.
  • Native dependency-boundary audit, lint, TypeScript typecheck, smoke check, npm run ui:build and git diff --check passed.
  • Isolated DSH desktop-host browser test passed export, review, import, restart and desktop/narrow viewport checks using scripted local models. Transfer made no model calls and no real stories were changed.
  • npm run check is 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 in draft-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.

@j2msReginaldBot j2msReginaldBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clones archive.commits on every lookup. That makes each ancestry/project_branch call over an archive O(C²).
  • validate_host calls this projection once per branch (workspace_archive.rs:186), once per publication through source_for (:237, which may walk back through earlier heads at :139), and once per scene heading (:324).
  • archive_api.rs repeats source_for for every native memory (:104, :216, :263).
  • archive::read runs 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! in workspace.rs drops the future, but a running spawn_blocking(archive::read) keeps going until it finishes.
  • The source_for calls in archive_api.rs run directly on async runtime threads rather than in blocking(...).

What I verified

  • cargo test in api/: 46 passed on Linux.
  • tests/workspace-archive.test.ts with DOXVELT_REVERIE_EXECUTABLE set 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 the current receipt. 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) / MoveFileExW with 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, .dsh and .git are 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 rowid order round-trips;
    • INSERT OR IGNORE on content_revisions is now followed by an equality check, so the legacy /packages import still rejects conflicting content.

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 j2msReginaldBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ancestor are 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 in verify_structure rejects them before ordered_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 reproduces json_hash of the compact array, with and without the public-role-labels-v1 marker; 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 turn p, which is the latest head holding exactly the first p turns. That is the same head the old backward walk found.
  • Body corrections. These are derived per branch from Edit origins, so they behave as before. A publication made before a correction still matches on the source branch.
  • The build_manual_commit_with shortcut. This also changes the live turn path. When the turn uses the current knowledge policy, has no accessChanges, and expectedHead is the branch head, the projection is now skipped. In that case, append_effect_events only uses the links when applying accessChanges, and first_impressions is 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 --locked in api/: 50 passed.
  • tests/workspace-archive.test.ts with 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 Validate is 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.

@MichaelSchmidle
MichaelSchmidle merged commit efb737d into main Nov 17, 2026
1 check passed
@MichaelSchmidle
MichaelSchmidle deleted the codex/workspace-export-import branch November 17, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants