Skip to content
zeronshPublic

About

Rivet actors in Odin: a RivetKit port, packaged with opm

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rivet

Rivet actors in Odin: a port of RivetKit 3.1.2 that keeps the modern feature set. It speaks to rivetdev/engine 3.1.2 or newer over the envoy protocol (v11).

  • An envoy runtime with a serialized mailbox per actor, every lifecycle hook, sleep and grace.
  • SQLite through the envoy, and in-memory vars. No state, KV, queues or connection state.
  • Schedules and cron with history.
  • Connections and events with guards, over JSON, CBOR and BARE.
  • Raw requests and websockets, streamed responses, and the inspector.
  • A typed client with realtime connections. Contracts give end-to-end types.
  • Durable workflows (workflow) that read and write RivetKit's history format, with steps, sleeps, loops, join and race, rollback and versioning.

Packages

Import
rivet actors, the registry, the envoy runtime and the client
rivet/workflow durable workflows
rivet/cron cron expressions
rivet/protocol the envoy and client protocols

HTTP, websockets and the BARE codec come from odinlibs, which opm installs with rivet.

Install

With opm:

$ opm add github.com/zeronsh/rivet
import "libs:rivet"
import "libs:rivet/workflow"

Libraries should import the canonical path instead: import "pkg:github.com/zeronsh/rivet".

The HTTP and websocket transports link libcurl (libcurl4-openssl-dev on Debian and Ubuntu; macOS ships it).

An actor

package counter

import "libs:rivet"

Counter :: struct {}
Vars :: struct {}

Increment :: struct {
	amount: i64,
}

Count_Changed :: struct {
	count: i64,
}

Count_Row :: struct {
	count: i64,
}

actor :: rivet.Actor(Counter, rivet.None, rivet.None){name = "counter"}
increment :: rivet.Action(Counter, Increment, i64){name = "increment"}
count_changed :: rivet.Event(Counter, Count_Changed){name = "countChanged"}

register :: proc(registry: ^rivet.Registry) {
	definition := rivet.register(registry, actor, Vars, {on_migrate = migrate})
	rivet.implement(definition, increment, on_increment)
}

migrate :: proc(ctx: ^rivet.Context, is_new: bool) -> rivet.Error {
	rivet.sql_exec(ctx, "CREATE TABLE IF NOT EXISTS counter (id INTEGER PRIMARY KEY CHECK (id = 1), count INTEGER NOT NULL)") or_return
	_ = rivet.sql_execute(ctx, "INSERT OR IGNORE INTO counter (id, count) VALUES (1, 0)") or_return
	return nil
}

on_increment :: proc(ctx: ^rivet.Context, vars: ^Vars, args: Increment) -> (count: i64, err: rivet.Error) {
	row, _ := rivet.sql_query_one(ctx, Count_Row, "UPDATE counter SET count = count + ? WHERE id = 1 RETURNING count", args.amount) or_return
	rivet.broadcast(ctx, count_changed, {count = row.count}) or_return
	return row.count, nil
}

Serve it with rivet.serve(&registry, config) (rivet.config_from_env() reads RIVET_ENDPOINT, RIVET_TOKEN, RIVET_NAMESPACE and RIVET_POOL), and call it with the typed client:

client, _ := rivet.client_from_env()
handle := rivet.get_or_create(client, counter.actor, "default")
count, err := rivet.call(handle, counter.increment, {amount = 1})

Development

$ opm test .             # and protocol, cron, workflow
$ scripts/engine.sh      # rivetdev/engine 3.1.2 on :6420, admin token "dev"
$ opm build e2e -out:sdk-probe && RIVET_ENDPOINT=http://127.0.0.1:6420 RIVET_TOKEN=dev ./sdk-probe
$ opm build workflow/e2e -out:wf-probe && RIVET_ENDPOINT=http://127.0.0.1:6420 RIVET_TOKEN=dev ./wf-probe

The probes host their own actors and check them live against the engine: 44 checks for the SDK, and a workflow run through a long sleep, an alarm and a replay. scripts/wake-failures.sh then reads the engine's metrics and fails on any actor wake failure, which is how a missing alarm ack shows up (start the engine with RIVET_ALARM_ACK_TIMEOUT_MS=5000 so it shows up quickly). RIVET_PROBE_SCENARIO=slow-migrate ./sdk-probe instead holds an actor in onMigrate until the engine gives up on its start, against an engine started with short thresholds:

$ RIVET_ENGINE_ENV="RIVET__PEGBOARD__ACTOR_START_THRESHOLD=5000 RIVET__PEGBOARD__ACTOR_STOP_THRESHOLD=5000 RIVET__PEGBOARD__NODE_LOST_THRESHOLD=10000 RIVET__PEGBOARD__ACTOR_LOST_THRESHOLD=10000" scripts/engine.sh

opm installs the compiler pinned in odin.toml ([toolchain], Odin dev-2026-12) and odinlibs. rivet's own packages import each other by relative path. To work on odinlibs at the same time, opm link odinlibs ../odinlibs.

Releasing: tag vX.Y.Z and push the tag.

License

MIT. RivetKit, which this ports, is Apache-2.0: https://github.com/rivet-dev/rivet.

About

Rivet actors in Odin: a RivetKit port, packaged with opm

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages