Skip to content

Move Doxvelt to Rust and package the desktop plugin - #50

Merged
MichaelSchmidle merged 7 commits into
mainfrom
codex/native-desktop-package
Nov 16, 2026
Merged

MichaelSchmidle merged 7 commits into
mainfrom
codex/native-desktop-package

Conversation

@MichaelSchmidle

@MichaelSchmidle MichaelSchmidle commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Moves compilation, immutable simulation history, actor projections, drafts, persistence, source authoring, archives, workspace operations and Reverie integration into Rust. DSH remains the workspace UI and credential-owned model host. Maintained API/CLI/DSH entry points no longer load the retired TypeScript kernel/store or Nuxt workbench.

Adds a complete Windows x64 plugin package containing the prebuilt Doxvelt engine, bundled JavaScript dependencies, pinned Reverie v0.2.0, licenses and notices. The installer verifies files, installs a versioned user-local copy and registers it through DSH. Players need DSH Desktop 0.2.2-rc.3; Node, Bun, Rust, a checkout and a separate Reverie installation are unnecessary. README covers players; CONTRIBUTING covers source setup and release engineering.

The reviewed fixes restore duplicate-edge access revocation and failed memory-completion recovery, reject malformed host protocol strings, fail pending callers on uncorrelated protocol errors, and settle cancelled drafts under every policy from the point of reservation. Regression tests verify rollback/retry, retained knowledge, source parity, protocol failure recovery and restart behavior without advancing accepted history.

Validation: all 44 Rust tests; full Linux CI (503 JavaScript tests passed, 5 skipped); typecheck, lint, dependency audit, native smoke, plugin validation and startup verification. Windows native/workspace/bundle/Reverie checks, isolated package install/reinstall without toolchains, damaged-update rejection, manual/model play, memory formation/recall and the actual DSH desktop flow through restart and four viewport sizes pass. The full Windows reference suite still has documented filesystem/locking failures; one focused source-save check required a successful rerun after transient access denial. Scripted providers establish integration behavior, not live model quality.

Remaining non-blocking review findings are tracked separately:

The owner approved merge and release after these follow-ups were created. The v0.2.0-alpha.1 package will be rebuilt and verified from the exact release commit after merge. Reverie v0.2.0 remains independently published and pinned by SHA-256.

@MichaelSchmidle
MichaelSchmidle marked this pull request as ready for review November 16, 2026 09:02

@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.

Requesting changes for two regressions from the TypeScript reference. This PR claims to preserve that reference's behavior (findings 1 and 2 below). I recommend fixing a third issue in the same pass: a protocol hang (finding 3).

I reviewed ec3bd8a against main@9a5113c. The review was by reading only, because this host has no Rust toolchain. Linux CI Validate is green on this head. That run covers cargo test --locked through bun run check. I did not rerun the Windows packaging or desktop evidence.

Blocking

  1. Revoking access can leave live access in place (api/src/access.rs:51, inline). When the compiled graph has duplicate edges, the revoke removes only one of them. TS applyAccessChange collapses duplicate edges, so a revoke removes access completely there. This breaks the subjective-context invariant.
  2. A memory job can stay running permanently (api/src/memory.rs:130, inline). If the completing transaction fails, the job is never marked failed. Every later retry returns 409. TS marked the job failed in its catch.

Should fix
3. An invalid host message hangs its caller. The Rust side answers without an id, so the Node caller never settles (api/src/main.rs:372, inline).
4. Non-memory draft generation can get stuck. If it is cancelled or the HTTP client disconnects, the draft can stay generating (api/src/generation.rs:535, inline).

Non-blocking (carried over from TS or hardening)

  • The default trusted origins still include localhost:3000, now that Nuxt is gone (api/src/main.rs:408, inline). The listener also checks no Host header. Same-origin GETs therefore send no Origin header, and DNS rebinding to the fixed default port can read transcripts and beliefs. That behavior was carried over from server.ts, but the migration doc calls for origin verification at the Rust boundary.

  • Source paths can contain .. after an allowed first segment, so worlds/../.doxvelt/workspace.json passes resolve (api/src/source.rs:63, inline). TS has the same check, but in the Rust version that save path skips configuration validation.

  • Export redaction covers only api_key-style frontmatter keys (content.rs portable()), plus a line regex in portable.rs. That leaves gaps:

    • Plain YAML or JSON model files without --- keep their key in compiled.models[].body, and from there it reaches simulation.json.
    • The regex misses JSON "apiKey": lines and multi-line YAML values.

    TS has the same gap. I'm noting it because the README/CONTRIBUTING now tell players packages are shareable.

  • Two packaging issues (inline):

    • The installer migration only works while the old marker comments are intact.
    • The packager copies a fixed api/target/release path and the current node_modules. Neither is checked against CARGO_TARGET_DIR or bun.lock.

Comment thread api/src/access.rs
});
if change.action == AccessAction::Revoke {
if let Some(index) = position {
next.remove(index);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This removes only the first matching edge. Duplicate member→container edges can come from ordinary authoring: content.rs pushes one AccessLink per :access:member line and never dedupes. For example, the same membership could be stated in a dossier and again in a connections/ file.

Scenario:

  1. The compiled links are [jade→mafia, jade→mafia].
  2. A turn revokes jade/mafia.
  3. projection.rs keeps one edge, so resolve_belief_access still finds the path.
  4. Jade's context keeps the live Mafia beliefs.
  5. retained.rs uses the same apply_change, so no retained-after-loss beliefs are produced.
  6. The archive verifier replays the same result, so nothing catches it.

The reference (9a5113c:src/core/access-graph.ts applyAccessChange) rebuilds a Map keyed by member\0container\0mode, so a revoke removes every copy and a grant dedupes. Suggest matching those semantics, and adding a parity case with a duplicated authored edge.

Comment thread api/src/memory.rs Outdated
return Err(error);
}
};
let completed = repository.settle_memory_job(&job, Some(&closure))?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

start_memory_job has already committed running. If this settle_memory_job(.., Some(..)) fails, the ? returns and the job stays running permanently. Causes include SQLITE_BUSY after the 5 s timeout while another Store holds the write lock, an I/O error, or the closure/operation match check rejecting the result. Every later episode.close / memory-job.run then hits MemoryJobConflict (409), and no API resets the job.

The TS reference (9a5113c:src/core/branch-episode.ts) wraps completion in try and calls failMemoryJob in catch. The test near line 435 has to settle the job manually after a failed completion, which shows the gap. Suggest marking the attempt failed (best effort) on any error after start_memory_job, not only when generation fails.

Comment thread api/src/main.rs
Ok(message) => message,
Err(_) => {
publish(
json!({"error": {"code": "INVALID_JSON", "message": "Expected a protocol envelope."}}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This error envelope has no id. native-server.ts handles only cancelCall, callId or a numeric id, so it drops the message and the pending request never settles.

It is reachable from ordinary input. JSON.stringify emits a lone surrogate as \ud800, which serde_json::from_str rejects. Only provider text_delta is checked with isWellFormed(). Source text in a collection save, story names/bodies, episode dates/cues, and memory.reflect / cli.generate callback results are not checked.

operation()'s abort only sends abort to Rust and doesn't reject locally. The hung promise therefore also blocks the per-root tails chain in workspace-host.mjs until DSH restarts. A callback reply that fails to parse also leaves Rust's receive.await waiting with no timeout.

Suggest two changes:

  • Reject or normalize ill-formed strings before sending, or fail the request on the TS side when its id is unknown.
  • Have the TS reader fail all pending calls on an id-less error envelope.

Comment thread api/src/generation.rs Outdated
let _ = crate::publish(
json!({"callId":id,"method":"model.close","params":{"draftId":self.draft["id"]}}),
);
if self.cancellable && !self.finished {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This only settles the draft when cancellable, which means knowledge policy with memory enabled. For default, routing-v1 and knowledge-without-memory drafts, dropping the future leaves the reserved row in generating. The future is dropped by the host abort (via the select! in main.rs http_request) and, normally, by a client disconnect. recoverable_actor_drafts keeps returning that row, and replaying the same commandId returns the stuck draft. TS ran these generations to completion.

There is a smaller window for cancellable drafts too: a cancel during the finish_preserved await happens before the lease exists. Discarding the draft recovers in both cases, so this is not blocking, but it is a behavior regression on an ordinary disconnect.

Comment thread api/src/main.rs
.and_then(|v| serde_json::from_value(v.clone()).ok())
.unwrap_or_else(|| {
vec![
"http://localhost:3000".into(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This default was the Nuxt dev origin, and this PR removes Nuxt. Neither the DSH engine (workspace-host.mjs) nor index.ts without --origin passes allowedOrigins, so any page served on port 3000 gets CORS-approved access. That page could then:

  • read every transcript, belief and memory;
  • write sources with a caller-chosen workspacePath;
  • export to an arbitrary targetDir.

The random engine port doesn't stop that origin from scanning loopback. Suggest defaulting to an empty list, and adding a Host allowlist (loopback names plus the bound port) against DNS rebinding.

Comment thread api/src/source.rs
if !normalized
.split('/')
.next()
.is_some_and(|s| FOLDERS.contains(&s))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Only the first segment is checked. safe_fs::absolute then normalizes .. lexically, so worlds/../.doxvelt/workspace.json resolves inside the root and passes. Through collection::save_source, that overwrites the workspace configuration and bypasses validate_configuration and its revision protocol. TS had the same check, so this is not new, but rejecting ., .. and empty segments is a cheap fix here.

$doxveltPatch = Join-Path $doxveltProfileDirectory 'cordis.patch.yml'
if (Test-Path -LiteralPath $doxveltPatch) {
$doxveltBefore = [IO.File]::ReadAllText($doxveltPatch)
$doxveltAfter = [regex]::Replace($doxveltBefore, '(?ms)^# BEGIN DOXVELT INSTALLATION\r?\n.*?^# END DOXVELT INSTALLATION\r?\n?', '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This migration only removes the old developer entry while its marker comments are intact. install-dsh.ps1 already handles DSH saving cordis.patch.yml as a JSON array, which suggests DSH can rewrite the file without the comments, for example when the user saves a model connection. If the comments are gone, the id: doxvelt / config.reverie: <checkout path> entry survives. workspace-host.mjs prefers options.reverie over the bundled executable, so memory keeps using the old checkout's Reverie, or fails once it is deleted, while the installer reports success. Suggest also removing a bare id: doxvelt entry that has a reverie key, or at least warning about it.

Comment thread scripts/package-dsh.mjs
for (const required of ['reverie-engine.exe', 'LICENSE', 'NOTICE', 'notices/README.md']) await readFile(path.join(reverie, required));
await cp(reverie, path.join(native, 'reverie'), { recursive: true });
run(process.execPath, [path.join(root, 'scripts/cargo.mjs'), 'build', '--release', '--locked'], { cwd: root, stdio: 'inherit' });
await copyFile(path.join(root, 'api/target/release/doxvelt-api.exe'), path.join(native, 'doxvelt-api.exe'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This copies a fixed path after cargo build, but cargo.mjs passes through the environment. If CARGO_TARGET_DIR or a global build.target is set, cargo writes elsewhere, and a stale api/target/release/doxvelt-api.exe gets packaged. That path is ignored by git, so the dirty check can't catch it. Similarly, bundle-dsh.mjs bundles whatever is in node_modules, without a --frozen-lockfile install or lockfile check. release.json can therefore record a clean sourceCommit that doesn't match the shipped bits. Suggest using cargo build --message-format=json (or cargo metadata) to locate the artifact, and running bun install --frozen-lockfile before bundling.

@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 654aee8. I re-reviewed ec3bd8a..654aee8 (f334b52, 654aee8) by reading the code; Linux CI on this head is green, including the Rust tests.

  • Access revoke: apply_change now collapses duplicate (member, container, mode) edges before applying the change, matching the TS Map semantics. A revoke removes access completely, and the new unit test covers revoke, grant and an unrelated change.
  • Memory job: any error after start_memory_job, whether from generation or the completing transaction, now triggers a best-effort settle_memory_job(.., None), and the original error is still returned. The added test covers a completion rollback followed by a successful retry.
  • Protocol hang: outgoing keys and values are checked for well-formed Unicode before sending. An invalid callback result becomes a correlated error through the existing answer catch. An id-less error envelope fails every pending caller and stops the child, and non-object envelopes are rejected.
  • Stuck drafts: the cleanup lease is now created inside the reservation worker. It applies to every policy and covers the finish_preserved window. If the request is dropped while that worker is still running, the returned lease drops and settles the draft as aborted. The updated restart test, which now expects interrupted generations to end as failed, follows from this.

The non-blocking findings (default origin and Host check, .. in source paths, export redaction, installer migration, package provenance) remain open and are documented as deferred in the PR description. I'd track them as follow-ups before the hosted or shareable-package work depends on them.

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