Skip to content

Rust Runtime

The Rust runtime is the host process that turns generated component artifacts into HTTP behavior.

It loads generated route metadata, exposes HTTP endpoints, executes WASM handlers through Wasmtime, registers sigMAX primitives, prepares typed inputs, collects ObjectIR output and returns JSON responses.

It should remain generic. Business-specific behavior belongs in contracts, route metadata, bindings, agreements, storage declarations and WASM artifacts.

At startup, the runtime reads a generated routes file and resolves the WASM modules referenced by each route.

Runtime inputPurpose
SIGMAX_ROUTESPath to generated/routes.yaml; defaults to ../generated/routes.yaml.
Route definitionsHTTP method, path, handler export, WASM path, request shape, response shape, limits and bindings.
Type definitionsc_repr layouts used to encode typed request bodies into WASM memory.
WASM modulesCompiled handlers referenced by the generated route metadata.
BindingsDeclared service/storage invocation targets available to the route.
CapabilitiesRuntime permissions attached to the active route.

If a route references a missing WASM module, startup fails instead of serving a partially broken component.

The runtime uses Axum as the HTTP server and Wasmtime as the WASM host.

HTTP request

Axum route

Runtime context

Wasmtime

WASM handler

sigMAX primitives

ObjectIR output

JSON response

For each incoming route, the runtime:

  1. matches the HTTP method and path;
  2. extracts route parameters or JSON body data;
  3. prepares typed inputs when the route declares c_repr data;
  4. creates a fresh request context;
  5. attaches route capabilities and bindings;
  6. loads the WASM module with Wasmtime;
  7. registers sigMAX imports in the Wasmtime linker;
  8. calls the exported handler function;
  9. reads status and ObjectIR output from the runtime context;
  10. returns a JSON response with the declared or emitted status.

Each request receives a dedicated runtime context shared with WASM primitives through a thread-safe wrapper.

Context areaWhat it stores
Route dataPath parameters, typed inputs and available type definitions.
Policy dataRoute capabilities and resolved runtime bindings.
Response stateStatus, headers and ObjectIR root value.
Error stateRecorded runtime or validation errors.
Local stateIn-memory state values accessible through state primitives.
ObjectIR stackTemporary nested object/array construction state.

This context is the controlled bridge between the sandboxed module and the host runtime.

The runtime registers the host imports that generated WASM modules are allowed to call.

Primitive familyRuntime responsibility
InputRead route parameters, headers and typed request objects.
ResponseSet HTTP status and response headers.
ObjectIRBuild structured output objects and arrays.
ErrorsEmit validation or runtime errors in a predictable shape.
ObservabilityLog messages and expose trace/metric hooks.
CapabilitiesCheck whether a route is allowed to use a sensitive primitive.
Regex, JSON, crypto, timeExecute bounded helper operations on the host side.
HTTP, secrets, random, invocation, stateGate host-facing behavior through policy and limits.

The primitive layer owns pointer checks, length checks, buffer writes and stable error codes. WASM code does not receive direct access to host memory, files, sockets or process APIs.

The runtime also exposes a small operational surface.

EndpointPurpose
/healthzHealth check returning ok.
/docs and /docs/Serves generated component documentation.
/openapi.yamlServes the generated OpenAPI document.
/.well-known/componentReturns component discovery metadata pointing to docs and OpenAPI.

The documentation and OpenAPI paths can be configured with SIGMAX_DOCS_INDEX_PATH and SIGMAX_OPENAPI_PATH.

VariableDefaultMeaning
SIGMAX_ROUTES../generated/routes.yamlGenerated routes file loaded at startup.
SIGMAX_BIND0.0.0.0:8080HTTP bind address for the component runtime.
SIGMAX_DOCS_INDEX_PATH/app/generated/docs/index.htmlStatic generated docs entry.
SIGMAX_OPENAPI_PATH/app/generated/openapi.yamlGenerated OpenAPI document.
DAPR_HTTP_ENDPOINTunsetEnables Dapr invocation when bindings require it.
SIGMAX_TIME_FIXED_UNIX_MSunsetOptional deterministic time source for time primitives.
SIGMAX_RANDOM_DETERMINISTIC_SEEDunsetOptional deterministic random source for repeatable runs.

HTTP, secret and external target primitives also use SIGMAX_HTTP_* and SIGMAX_SECRET_* policy variables when those capabilities are enabled.

The runtime enforces route timeout and memory limits when they are declared.

Failure modeRuntime response
Invalid request shape400 with VALIDATION_ERROR.
WASM execution timeout504 with TIMEOUT.
Missing handler exportRuntime error.
Missing or invalid WASM moduleStartup or execution failure.
Unsupported response formatRuntime error.
Memory above route limitRuntime error.
Undeclared statusLogged as a warning and returned as emitted.

The current response path expects successful output to be JSON built from ObjectIR. Other response formats should be declared only when the runtime supports them.

The Rust runtime should stay business-neutral.

It should not:

  • encode invoice, customer, payment or domain-specific behavior;
  • decide architecture boundaries;
  • invent route capabilities;
  • bypass Binary Contracts or Agreements;
  • expose raw database or filesystem access to WASM;
  • silently accept drift between generated metadata and executable artifacts.

Its job is to provide the same execution contract for every generated component: load declared routes, run validated WASM, expose controlled primitives and return observable results.