Skip to content

feat: port Rust core runtime#104

Draft
pgherveou wants to merge 6 commits into
mainfrom
worktree-issue-96-rust-core-port
Draft

feat: port Rust core runtime#104
pgherveou wants to merge 6 commits into
mainfrom
worktree-issue-96-rust-core-port

Conversation

@pgherveou

@pgherveou pgherveou commented May 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR ports dotli onto the shared Rust TrUAPI core and makes the Rust crates the source of truth for protocol dispatch, generated product/client types, host capability bindings, auth/session state, permissions, SSO/signing orchestration, chainHead, preimage, theme, and notification plumbing.

The web host now embeds the Rust runtime through @parity/truapi-host-wasm. dotli keeps the browser-specific pieces: iframe/worker transport, DOM presentation, storage adapters, and chain-provider wiring. Native/mobile scaffolding continues in #215.

Reviewable stack

This PR is the umbrella / cumulative view. For review, it is broken into a per-commit stack. Please review and merge bottom-up. The tip, #253, has the same cumulative diff as this PR.

  1. feat(truapi): add testing API and versioned wiring #248 — truapi: testing API + versioned wiring (base: main)
  2. feat(truapi-platform): add host capability traits #249 — truapi-platform: host capability traits
  3. feat(truapi-codegen): emit Rust dispatcher, wire table, and host callbacks #254 — truapi-codegen: Rust dispatcher + wire table
  4. feat(truapi-server): add host logic primitives #255 — truapi-server: host logic primitives
  5. feat(truapi-server): add wire and chain infrastructure #256 — truapi-server: wire and chain infrastructure
  6. feat(truapi-server): add platform runtime and host bridge #250 — truapi-server: platform runtime and host bridge
  7. feat(host-wasm): add @parity/truapi-host-wasm runtime #252 — host-wasm: @parity/truapi-host-wasm runtime
  8. chore: docs, CI, tooling, and dotli integration for the Rust core #253 — docs, CI, tooling, dotli integration

Architecture

Validation

  • make check
  • make e2e-dotli with signer-bot should give you the same report as published in the explorer
  • make dev will build and run so you can test the truapi-playground locally, running http://localhost:5173/localhost:3000

@pgherveou pgherveou marked this pull request as draft May 17, 2026 16:22
pgherveou added a commit that referenced this pull request May 18, 2026
Bug fixes:
- Makefile uniffi target now writes Swift bindings through a tempdir
  and copies into the actual SwiftPM layout (Sources/TrUAPIHost/ for
  the .swift file, Sources/truapi_serverFFI/include/ for the C header
  and module.modulemap). Cdylib path picks .dylib on macOS.
- electron provider: onClose sets disposed=true and clears listener
  sets so subsequent postMessage no-ops cleanly and close listeners
  don't fire twice if the caller also calls dispose().
- web worker provider: init-failure paths call worker.terminate()
  before rejecting so a failed core init doesn't leak the worker.
- createWebSocketProvider: subscribe / subscribeClose use Set instead
  of Array+indexOf so double-registration of the same callback is
  idempotent (matches the other providers in the package).

Test coverage:
- New js/packages/truapi/test/ws-provider.test.mjs exercises the WS
  provider against a stubbed WebSocket constructor (queue+flush,
  fan-out, set semantics, close fan-out, post-after-close throws).

Doc + style fixes:
- docs/design/dotli-architecture-change.md describes featureSupported
  as a current callback with a planned removal, matching the platform
  trait and the host shells. The implementation-vs-doc contradiction
  is gone.
- Migration narrative stripped from runtime.rs, wasm.rs, native.rs,
  host_logic/features.rs, the Kotlin shell, and the Swift shell.
- Em-dashes swept from 18 PR-scope files (CLAUDE.md, both design
  docs, both native READMEs, the TS host packages, a few platform
  doc comments).
- create-iframe-host.ts comment now describes current behaviour
  without referencing the "legacy fallback".
- tests/object_safety.rs renamed to tests/bounds.rs with a docstring
  that matches what the test actually asserts (the trait isn't
  object-safe; the bound check is on Send + Sync + 'static).
- iOS: drop dead `_ = self.callbackRetainer` line; explain the
  retainer in plain prose instead of via a no-op suppression.
- Android: drop redundant @Suppress("unused") on a property that is
  read in init.

Deferred to follow-up issues (#105-#111).
@pgherveou pgherveou changed the title feat: port Rust core runtime from truapi_next prototype feat: port Rust core runtime May 18, 2026
pgherveou added a commit that referenced this pull request May 30, 2026
Harden the Rust core runtime and host SDKs against the review of the core
port. No change to the wire protocol or the generated artifacts (codegen
regenerates byte-identically; the committed WASM bundle is rebuilt).

truapi-server:
- Subscriptions use generation-stamped reservation slots: a reused or raced
  request_id stops-and-replaces instead of leaking an unstoppable stream, and
  a _stop arriving before activation cancels the pending subscription.
  Unregistered methods answer Unsupported instead of leaving the caller to
  hang. Dead negotiated_version slot and interrupt API removed.
- chainHead-v1 runtime: single-flight follow setup (no duplicate or leaked
  remote subscriptions), the close-vs-insert race in request_value is closed
  so a caller can no longer hang forever, the pending follow-event buffer is
  bounded, and an orphaned remote follow is unfollowed when its local follow
  is torn down mid-setup.
- WS bridge: constant-time token comparison, bounded inbound message size,
  bounded outbound queue and connection count, documented loopback trust
  model.
- wasm surface registers a panic hook and surfaces non-boolean / non-string
  host returns as errors; permissions persist only genuine user decisions, so
  a transient prompt-callback error no longer locks a capability out; dotns
  classifies trailing-dot FQDNs and lowercases/de-dupes remote domains;
  navigate_to returns an error instead of panicking on a contract violation.
- smoldot provider is wired into the runtime behind its feature (with a
  platform fallback), with finite json-rpc ceilings, a distinguishable
  reconnect error, and Apache-2.0 attribution (SPDX headers +
  THIRD_PARTY_NOTICES.md).
- Tests: subscription-race regressions, malformed-frame drop, subscription
  lifecycle through the wire boundary, and a hardened Rust<->TS wire-table
  parity check (panics on unparseable ids, compares all four subscription
  ids, asserts a row-count floor).

codegen: Rust dispatcher/wire-table emitters use writedoc!/formatdoc!
(byte-identical output); TS host-callbacks handles bare trait-object returns.

JS hosts: worker-runtime faults now reach close subscribers; the WebSocket
provider is built on the shared close-once base provider; the electron
provider detaches port listeners on remote close; new tests for the node
WASM round-trip, WS error/non-binary/CLOSING paths, and the iframe
handshake/origin/dispose paths.

native: Android and iOS HostBridge document that callbacks fire on the
truapi-ws-bridge worker thread; the iOS bootstrap uses a JSONEncoder-based JS
string-literal escaper; Maven coordinates reconciled across build.gradle.kts,
jitpack.yml, and the README.

CI/docs: host-packages CI runs the host-shared smoke test against the
freshly built WASM bundle and triggers on truapi-platform changes; the
Makefile wasm target no longer hides the committed bundle; design docs and
the truapi-platform README are reconciled to the shipped trait set.
@pgherveou

Copy link
Copy Markdown
Collaborator Author

Superseded by a 3-PR stack carved from this branch, each independently reviewable and green on CI:

Review bottom-up. Authored with assistance from Claude Code.

@pgherveou pgherveou closed this Jun 12, 2026
@pgherveou pgherveou reopened this Jun 12, 2026
Comment thread js/packages/truapi-host-wasm/src/web/create-worker-host-runtime.ts Outdated
Comment thread js/packages/truapi-host-wasm/src/web/create-worker-host-runtime.ts Outdated
Comment thread js/packages/truapi-host-wasm/src/web/create-worker-host-runtime.ts Outdated
Comment thread js/packages/truapi-host-wasm/src/node-runtime.ts Outdated
Comment thread js/packages/truapi/src/transport.ts Outdated
Comment thread js/packages/truapi/src/wire-tags.ts Outdated
Comment thread docs/design/host-contract-and-core-impl/A - host-primitives.md Outdated
Comment thread playground/src/components/DiagnosisView.tsx
Comment thread rust/crates/truapi/src/api/account.rs Outdated
Comment thread rust/crates/truapi/src/v01/permissions.rs Outdated
@pgherveou

Copy link
Copy Markdown
Collaborator Author

Follow-up update: PR #214 was merged back into this PR branch so the parent can run e2e, and #214 is now closed as superseded. Mobile host scaffolding/config/CI moved to child PR #215.

@pgherveou pgherveou force-pushed the worktree-issue-96-rust-core-port branch from 341366d to c5fb5c9 Compare June 14, 2026 09:29
pgherveou added a commit that referenced this pull request Jun 26, 2026
The truapi-ready/truapi-init handshake pairs with the WASM host's
createIframeHost (#104). Keep sandbox.ts at base so merging to main does not
break the deployed playground against the current host.
@pgherveou pgherveou changed the base branch from main to slim/js-playground-extract June 26, 2026 10:22
Base automatically changed from slim/js-playground-extract to main June 26, 2026 10:48
@pgherveou pgherveou force-pushed the worktree-issue-96-rust-core-port branch from a0793b9 to 5f03570 Compare June 28, 2026 10:00
@pgherveou pgherveou force-pushed the worktree-issue-96-rust-core-port branch 2 times, most recently from 227c3fb to eec4794 Compare June 30, 2026 09:52

@pgherveou pgherveou left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review cleanup notes for the Rust core port stack.

@pgherveou pgherveou force-pushed the worktree-issue-96-rust-core-port branch from eec4794 to 58e8db3 Compare June 30, 2026 11:02

@pgherveou pgherveou left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed review cleanup comments.

Comment thread rust/crates/truapi/src/v01/testing.rs Outdated
Comment thread rust/crates/truapi/src/lib.rs Outdated
Comment thread rust/crates/truapi-platform/src/lib.rs Outdated
Comment thread rust/crates/truapi-platform/src/lib.rs
@pgherveou pgherveou force-pushed the worktree-issue-96-rust-core-port branch from 58e8db3 to c992e4c Compare June 30, 2026 11:17

@pgherveou pgherveou left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

.

Comment thread rust/crates/truapi-platform/src/lib.rs
@pgherveou pgherveou force-pushed the worktree-issue-96-rust-core-port branch 2 times, most recently from 2b612da to 589e7dc Compare June 30, 2026 12:35
Adds the canonical testing module (api/testing.rs) and its v01/v02/versioned
wiring used by the Rust host runtime and generated clients.
@pgherveou pgherveou force-pushed the worktree-issue-96-rust-core-port branch from d1d0e97 to 30032e9 Compare June 30, 2026 15:30
New crate defining the host syscall traits (storage, navigation, consent,
permissions, ...) that host runtimes implement. Types are re-exported from
truapi::versioned/v01 rather than redefined.
WASM host runtime that hosts implement: dispatcher, SCALE frames, subscription
streams, chain runtime, host logic (sessions, SSO pairing, permissions,
statement store, dotns) and the wasm bindings. Includes the committed generated
dispatcher/wire-table under src/generated/.
…backs

Extends the rustdoc-JSON code generator to emit the Rust dispatcher and wire
table consumed by truapi-server, plus the TS host-callbacks adapter. Golden
tests pin the emitted shapes.
New WASM-backed host runtime package embedding the Rust core, with web iframe
and Web Worker entry points. Updates the @parity/truapi client (SCALE, sandbox,
transport) and drops the obsolete explorer 0.3.2 codegen snapshot.
Updates CLAUDE.md/README, CI workflows, Makefile, deny.toml, changesets, and
linguist attributes for generated code, and bumps the dotli submodule to the
host integration that consumes the WASM runtime.
@pgherveou

Copy link
Copy Markdown
Collaborator Author

This PR has been broken down into a stack of per-commit PRs for easier review. This PR stays open as the umbrella / cumulative view. Please review and merge the stack bottom-up:

  1. feat(truapi): add testing API and versioned wiring #248 — truapi: testing API + versioned wiring (base: main)
  2. feat(truapi-platform): add host capability traits #249 — truapi-platform: host capability traits
  3. feat(truapi-server): add platform runtime and host bridge #250 — truapi-server: Rust host runtime
  4. feat(truapi-codegen): emit Rust dispatcher, wire table, and host callbacks #251 — truapi-codegen: Rust dispatcher + wire table
  5. feat(host-wasm): add @parity/truapi-host-wasm runtime #252 — host-wasm: @parity/truapi-host-wasm runtime
  6. chore: docs, CI, tooling, and dotli integration for the Rust core #253 — docs, CI, tooling, dotli integration

Each PR is based on the one below it; the tip (#253) has the same cumulative diff as this PR.

decrypto21 added a commit that referenced this pull request Jul 1, 2026
Adapt the mock platform to #104's async_trait capability traits and
truapi::latest types: add #[async_trait] to each capability impl, flatten
feature_supported to bare v01 request/response types, update
CoreStorageKey::PermissionAuthorization to { product_id, request }, and add
JsonRpcConnection::close.

Fix the through-core preimage + storage-fault tests to assert the Result
discriminant at wire byte 1: the versioned envelope is
[version_index, result_discriminant, ..inner], and V1's version index is 0,
so the Ok/Err distinction lives at byte 1, not byte 0.
@decrypto21 decrypto21 mentioned this pull request Jul 1, 2026
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.

1 participant