Workflow Guest Guide #
This document describes the current Wasm guest contract used by xburner workflow mode.
Overview #
In workflow mode, the host owns:
- transport
- TLS
- cookies
- metrics
- thresholds
- execution scheduling
The Wasm guest owns:
- iteration state
- request sequencing
- response-driven transitions
- guest-managed variables under
iter.*andvu.*
Required Exports #
Workflow guests must export the following functions:
get_abi_versioninitstart_iterationnext_requesthandle_response
Current ABI version:
1
Optional Exports #
Workflow guests may also export:
setupteardown
Export Semantics #
get_abi_version #
Signature:
uint32_t get_abi_version(void);
Return:
1
init #
Signature:
int32_t init(uint32_t vu_id, uint32_t seed_hi, uint32_t seed_lo);
Called once when a workflow instance is created or recreated.
Return:
0on success- non-zero to fail instance initialization
start_iteration #
Signature:
int32_t start_iteration(uint32_t input_ptr, uint32_t input_len);
Called at the start of every iteration.
Return:
0on success- non-zero to fail the iteration and recreate the instance
next_request #
Signature:
uint64_t next_request(void);
Return value:
0means the iteration is done and no more requests are needed- non-zero means a packed pointer/length pair pointing to
HttpRequestActionV1
The guest is responsible for returning a valid in-memory HttpRequestActionV1.
setup #
Signature:
int32_t setup(uint32_t input_ptr, uint32_t input_len);
Called once after host setup.requests complete and before any VU instances are created.
teardown #
Signature:
int32_t teardown(void);
Called once after execution completes. During interrupted shutdown it is best-effort and bounded by shutdown_timeout.
handle_response #
Signature:
int32_t handle_response(uint32_t meta_ptr, uint32_t meta_len,
uint32_t body_ptr, uint32_t body_len);
Return values:
0: continue iteration1: done, success2: done, failed check3: fatal script error
Host Imports #
The host exposes the same functions in the env, host, and xburner modules:
host_rand_u64host_now_nanoshost_loghost_get_varhost_set_varhost_get_response_headerhost_check_abort
Variable Namespaces #
Supported namespaces:
setup.*iter.*vu.*
Rules:
setup.*comes from setup requests and may be extended by guestsetup- the guest may write
setup.*only duringsetup - during iterations the guest may write only
iter.*andvu.* iter.*is cleared at iteration boundaries- recreated workflow instances also clear
iter.*,vu.*, response headers, and the cookie jar
Request Model #
The guest does not perform HTTP directly. It emits request actions that reference host-defined request templates by request_id.
The host-defined request templates live in [[http.requests]] in config.
The guest may override:
- body
- timeout
- capture body size
For gRPC workflows, the returned body bytes are sent as protobuf payload bytes and path resolves to the RPC path from config.
Response Model #
handle_response receives:
HttpResponseMetaV1for HTTP scenariosGrpcResponseMetaV1for gRPC scenarios- an optional captured body slice
The host sets transport flags and transport codes when a request fails before receiving a response.
Recovery Behavior #
The host may recreate a workflow instance when it observes:
- traps
- invalid actions
- invalid return values
- cooperative script timeout
The host may poison a worker on hard timeout, depending on backend behavior and configured limits.
Module Cache #
Workflow module startup keeps two cache layers:
- a filesystem validation cache under
.zig-cache/wasm-module-cache - an in-process module-bytes cache for repeated instance creation inside one run
The filesystem cache filename uses:
- runtime backend
- module content hash
Each cached JSON record also stores:
- a cache schema version
- the validated ABI version and required export set
When the guest bytes change, the hash changes and the previous cache entry is ignored automatically.
xburner validate logs the observed cache outcomes as validation_cache=hit|miss|stale and bytes_cache=hit|miss|reloaded.
Minimal Example #
See:
- include/xburner_workflow_guest.h
- samples/workflow-health.c
- samples/workflow-health.rs
- samples/workflow-health.go
- samples/workflow-health.toml
- templates/workflow-guest.c
- templates/workflow-guest.rs
- templates/workflow-guest.go
- templates/workflow-scenario.toml
The generic build helper is:
sh scripts/build_workflow_wasm.sh path/to/guest.c path/to/guest.wasm
Rust and Go helpers are also available:
sh scripts/build_workflow_rust_wasm.sh path/to/guest.rs path/to/guest.wasm
sh scripts/build_workflow_go_wasm.sh path/to/guest.go path/to/guest.wasm
Notes:
- the Rust template is validated in the repository template matrix
- the Go template currently targets
wasip1and is validated with thewasm3backend
The sample guest can be rebuilt with:
sh scripts/build_workflow_sample_wasm.sh
To scaffold a new workflow guest plus matching scenario config:
sh hacks/scaffold_workflow.sh my-flow ./my-flow
Language variants:
sh hacks/scaffold_workflow.sh --lang c my-flow ./my-flow-c
sh hacks/scaffold_workflow.sh --lang rust my-flow ./my-flow-rust
sh hacks/scaffold_workflow.sh --lang go my-flow ./my-flow-go
The scaffold helper also supports:
--target <url>--path <request-path>--request-name <name>--request-id <id>--mode <constant-vus|constant-arrival-rate>--vus <n>--rate <n>--pre-allocated-vus <n>--max-vus <n>--method <GET|POST|PUT|DELETE>--body <body>--pass-response-body <true|false>--capture-body-max-bytes <n>--duration <duration>--warmup <duration>--threshold <ratio>--backend <wamr|wasm3>--lang <c|rust|go>--cookie-jar <true|false>--cookie-jar-scope <vu|iteration>--use-tls <true|false>--connect-timeout-ms <ms>--max-steps-per-iteration <n>--header <key:value>--setup-header <key:value>--setup-body <body>--setup-capture-body-max-bytes <n>--setup-request <METHOD:PATH:STORE_KEY>
Backend Selection #
Workflow backend can be selected in config:
[scenario]
wasm_backend = "wamr"
Or overridden on the CLI:
xburner run --wasm-backend wasm3 path/to/scenario.toml