rift · protocol

the rift wire contract, protocol 1

Between the rift daemon (dev.gigantic.rift) and its clients: the rift command line and any program on its socket. Clients are written against this page; a change here breaks them unless it is additive. What rift is: the design.

Transport

Framing

Hello

The first line on every connection is the client's hello, client a string and proto an integer:

{"client":"example/1.0.0","op":"hello","proto":1}

The reply when the protocol matches:

{"boot":7,"ok":true,"pid":4211,"proto":1,"since":"2026-11-22T18:04:11.201Z","state":"ready","version":"2026.11.0-abc1234"}

Another proto is answered, and the connection closed:

{"code":"proto","ok":false,"proto":1,"version":"2026.11.0-abc1234"}

version is <release>-<build>: the release's YYYY.M.N (a checkout's build: the crate version), then the short commit it was built from, -dirty over uncommitted work.

Requests

After hello the connection carries requests, one per line, each answered by one line (a pong, sound or done by none). Any line, hello included, may carry "id", a string or number, and its reply echoes it, an error included; "id":null is no id, and an id of another type is bad_request, not echoed.

oprequestreply
device{"kind":"ear","name":"desk","op":"device"}
{"kind":"mouth","name":"desk","op":"device","plays":true}
{"ears":true,"ok":true,"ping":1764000000000000,"track":"ear-desk"}, then the connection is that track's device; plays, a mouth's alone, makes it one that plays, and its reply carries "plays":true
done{"op":"done","play":3}a playing mouth's: nothing more of the play will sound or be sent; none
ears{"on":true,"op":"ears"}as quiet, for the ears
end{"op":"end"}a giver's: {"ok":true}; nothing more is given, and what was plays out
feed{"after":null,"op":"feed"}
{"after":{"boot":7,"seq":12},"op":"feed"}
{"ok":true,"reset":false}, then the connection is a feed; after is required
frame{"op":"frame","pcm":"…","t":81234567}
{"mic":"MacBook Pro Microphone","op":"frame","pcm":"…","t":81234567}
a device's: {"ok":true,"t":1764000000020000}, the frame's time on its track, perhaps with a ping; mic, optional, names the microphone it was heard on
give{"op":"give","pcm":"…"}a giver's: {"given":4800,"ok":true}, the play's samples given so far, withheld while its mouth holds $RIFT_AHEAD_MS or more unplayed (plays)
health{"op":"health"}the hello reply's fields, plus "quiet":false, "seq":12 (the last event's seq in this boot), and the stream's "archive":null, "devices":["ear-desk"] (the live tracks), "ears":true, "engines":{} (engines), "playing":{"mouth-desk":3} (each open play by its mouth) and "window":600
hush{"op":"hush","track":"mouth-desk"}the mouth's play ended at once, then its played fields, {"dropped":8400,"given":38400,"ok":true,"play":4,"played":30000,"reason":"hush","seq":45,"track":"mouth-desk"}; with no play open, {"ok":true,"play":null}
keep{"archive":"/Volumes/a/rift","op":"keep","window":600}{"ok":true,"seq":14}: the window in seconds and the archive, an absolute directory or null; then a sweep, which the reply does not wait for
listen{"op":"listen","track":"ear-desk"}{"ok":true}, then the connection follows the track live
play{"op":"play","rate":24000,"track":"mouth-desk"}{"ok":true,"play":3,"seq":40}, then the connection is that play's giver; rate is the given audio's, 8000 to 48000 Hz
pong{"op":"pong","ping":1764000000000000,"t":81234000}a device's answer to a ping; none
quiet{"on":true,"op":"quiet"}{"changed":true,"ok":true,"seq":13}; the value it already has appends nothing and answers "changed":false with the current seq
read{"from":1764000000000000,"op":"read","to":1764000010000000,"track":"ear-desk"}{"ok":true}, then the range, then end of stream
shutdown{"op":"shutdown"}{"ok":true}, then the daemon drains and exits 0; the agent does not respawn it
sound{"from":0,"op":"sound","play":3,"samples":9600,"t":81234567}a playing mouth's: the run so far of the play's samples its output took back to back; none

Errors are {"code":"<code>","ok":false}, and clients match on code, never on other text. A request error leaves the connection open; only too_long and a refused hello close it.

codewhen
absenta play for a mouth no playing device streams (none connected, or a file-fed one)
aheada frame half a frame or more before its track's end: the device's clock runs fast, and the frame was dropped
bad_framepcm is not 640 bytes as hex, or mic (a mouth's: speaker) is neither a string nor null; a give's pcm is not 2 to 16384 bytes, whole samples, as hex
bad_requestnot JSON, not an object, a missing or mistyped field; a kind, name or track not of the form; frame or pong off a device, device, feed, listen or read on one; a read whose from is not before its to; plays on an ear, a play or hush naming an ear's track or a rate out of range, play or hush on a device, give or end off a play's connection or once its play is over, a second end, any other op on a play's connection, sound or done off a playing mouth
busya play for a mouth that has one open; nothing changed
closeda frame while the ears are closed; it was not taken
gonea read from before now less the window
ioa write to the log or a segment failed; the request took no effect, though a segment it closed on the way stays closed, logged, so a retry repeats nothing
protothe hello's protocol is not the daemon's
quieta play while quiet is on
stoppinga request other than health while draining
takena device for a track another device is streaming
too_longthe line is over the limit
unknown_opan op this protocol does not have, a second hello included
unsynceda frame or a sound before its device's first pong: it has no place on the timeline yet

Events

Every event is one line, in the log and on a feed:

{"boot":7,"e":{"kind":"quiet","on":true},"seq":13,"t":"2026-11-22T18:09:40.118Z"}
kindfieldswhen
bootpid, versionthe first event of every boot
earsonthe ears opened or closed
hole[mic,] samples, start, tracka gap in a track's frames this boot, or another microphone, logged as the frame after it arrives
keeparchive, windowthe window or archive was set
playplay, rate, tracka play opened on the mouth track; play counts plays from 1 across every boot, never reused
playeddropped, given, play, played, reason, trackthe play is over, its counts in its own samples at its rate: given = played + dropped (plays); the next boot's for a play a kill left open has neither given nor dropped
quietonthe quiet setting changed: health's quiet is on from here; on, every open play ends quiet after it
soundfrom, play, samples, start, trackone run of the play's samples, from up to from + samples, that the output took back to back, the first sounding at start; logged when the run ends, before the next run's and the played
segment[mic,] n, path, samples, start, tracka segment closed; path is under the root, audio/<boot>/<track>/<n>.pcm
stopreasonthe drain began: health's state is stopping from here, and nothing follows it in this boot; a killed boot has none
track[mic,] start, tracka track's first frame this boot

[mic,]: the microphone the event's frames name, present only when they name one, so a file-fed device's events are as they were; a mouth's name the output they sounded on, speaker, carried the same way and by the same rule.

Additive, so no proto bump: a new kind, a new field on an event or a reply, a new op, a new error code. Clients ignore kinds and fields they do not know.

The log

Feed

The stream

Devices

Plays

A client, the giver, gives audio to the daemon for a mouth; the daemon passes it to the device streaming that mouth's track, which plays it on its output (the mouth). The daemon holds no audio: what waits, waits in the mouth.

On a feed, a play of 3 s at 24 kHz that ran to its end, then one hushed 1.25 s in, its giver 350 ms ahead (the mouth's own track events, when the ears are open, interleave, its segment closing at each played):

{"boot":7,"e":{"kind":"play","play":3,"rate":24000,"track":"mouth-desk"},"seq":40,"t":"2026-11-22T18:10:00.004Z"}
{"boot":7,"e":{"from":0,"kind":"sound","play":3,"samples":72000,"start":1764000000021000,"track":"mouth-desk"},"seq":41,"t":"2026-11-22T18:10:03.008Z"}
{"boot":7,"e":{"dropped":0,"given":72000,"kind":"played","play":3,"played":72000,"reason":"end","track":"mouth-desk"},"seq":42,"t":"2026-11-22T18:10:03.008Z"}
{"boot":7,"e":{"kind":"play","play":4,"rate":24000,"track":"mouth-desk"},"seq":43,"t":"2026-11-22T18:10:05.000Z"}
{"boot":7,"e":{"from":0,"kind":"sound","play":4,"samples":30000,"start":1764000005019000,"track":"mouth-desk"},"seq":44,"t":"2026-11-22T18:10:06.252Z"}
{"boot":7,"e":{"dropped":8400,"given":38400,"kind":"played","play":4,"played":30000,"reason":"hush","track":"mouth-desk"},"seq":45,"t":"2026-11-22T18:10:06.252Z"}

Audio on disk

Readers

Client rules

Engines

Served, the echo engine's clean track aside, designed (the slices). An engine is a client that does one kind of work on one track and reports results, which the daemon checks and logs as events (the design). Every op, field, event and code here is additive: proto stays 1, and nothing above changes meaning.

reportkindlinerule; logged as
donespeech{"op":"done","say":5}after the say's end, no play is coming (nothing to sound); the say ends end, spoken 0. Before its end or with its play opened: bad_request
frameecho{"op":"frame","pcm":"…","t":…}the clean track's frame for the ear's frame at t, at most one each; streamed to clean-<name> as a device's frames are, segments and window alike
markspeech{"op":"mark","samples":21600,"say":5,"text":13}the say's first text characters (Unicode scalar values) have sounded once the play's sample samples has; each past the last on both; not logged, kept for spoken
maskecho{"on":true,"op":"mask","start":…}from an on's start to its off's the ear is the machine hearing itself; on and off alternating from on, rising; mask
partialwords{"end":…,"op":"partial","start":…,"words":[…]}a hypothesis for audio after the last final, superseding the last partial; not logged, sent to partials readers
ruledecho{"op":"ruled","to":…}every sample before to is ruled on; rising; releases the frames held for it; not logged
talkerstalkers{"end":…,"op":"talkers","start":…,"talkers":[{"id":"enrolled-1","score":0.82},{"id":2,"score":null}]}the voices speaking throughout [start, end), settled, never revised; spans never overlap and rise, none empty; at most 16 talkers, each id a string of a track name's form starting with a letter, with a score from 0 to 1 or null (not identified), or an integer from 1 with null, the score always present; strings in byte order, then integers rising, none twice; talkers, each talker's two fields alone
turnturn{"end":…,"op":"turn","start":…}a turn from the voice that began it to the voice's end that closed it; turns never overlap and rise; turn
voiceturn{"on":true,"op":"voice","start":…}speech starts (on) or stops at start, on and off alternating from on; voice
wordswords{"end":…,"op":"words","start":…,"words":[{"end":…,"start":…,"text":"hello"}]}final words for [start, end), never revised; finals never overlap and rise, each word inside its span, the words rising; words
oprequestreply
end{"op":"end"}on a say's connection: {"ok":true}; no more text, and what was given is spoken out
partials{"op":"partials","track":"ear-desk"}{"ok":true}, then each partial as its engine sends it, {"end":…,"engine":"transcribe","start":…,"track":"ear-desk","words":[…]}, no replay, until the engine leaves (end of stream) or the client falls 1024 behind; absent with no words engine on the track
say{"op":"say","track":"mouth-desk"}{"ok":true,"say":5,"seq":50}, then the connection is that say's: texts and one end, as a play's gives; it ends in one line, the spoken event's fields and seq, then the end of stream
text{"op":"text","text":"Hello there. "}a say's: {"ok":true,"text":13}, the characters given so far, passed to the speech engine as given; withheld while 8 pieces or more are queued for the engine and not yet written to it, so a client faster than its engine is paced by its replies
kindfieldswhen
enginename, on, stage, trackan engine connected (on) or left, stage its request's kind (the event's own kind is engine); a turn engine leaving with its voice on has it logged off at the end of the last frame it was given, before this event, and a boot after a kill logs a voice left on off as it starts, so every voice on is followed by its off, live and in a replay
maskengine, on, start, trackan echo engine's mask of its ear going on or off
play[say,] play, rate, trackas above; say when the play is a say's
saysay, tracka say opened on the mouth track
spokenplay, reason, say, spoken, text, trackthe say is over: text all it was given, spoken how many of its characters sounded, play its play or null
talkersend, engine, start, talkers, tracka talkers engine's span, each talker {"id","score"}
turnend, engine, start, tracka turn engine's turn
voiceengine, on, start, tracka turn engine's speech start or stop
wordsend, engine, start, track, wordsa words engine's final words, each {"end","start","text"}

Engine results are events, kept in the log for good while the audio they name leaves with the window: a client reads past ones on a feed from a position, and may find the audio behind a words event gone or in the archive. Codes beside the table above: absent also for a say or partials with no engine of its kind on the track; busy for a say or play while a say is open; gone for an engine's from; taken for a kind and track held.

Minimal engines, one per kind, lines as sent (→) and read (←), hello and its reply left out. A words engine reading live:

→ {"from":null,"kind":"words","name":"transcribe","op":"engine","track":"ear-desk"}
← {"ok":true,"seq":20,"through":null}
← {"pcm":"…","t":1764000000000000}
← … a frame every 20 ms
→ {"end":1764000000640000,"op":"partial","start":1764000000000000,"words":[{"end":1764000000640000,"start":1764000000300000,"text":"hel"}]}
← {"ok":true}
← {"turn":{"end":1764000001200000,"start":1764000000300000}}
→ {"end":1764000001200000,"op":"words","start":1764000000000000,"words":[{"end":1764000000700000,"start":1764000000300000,"text":"hello"},{"end":1764000001200000,"start":1764000000760000,"text":"there"}]}
← {"ok":true,"seq":24}

A turn engine:

→ {"from":null,"kind":"turn","name":"endpoint","op":"engine","track":"ear-desk"}
← {"ok":true,"seq":21,"through":null}
← {"pcm":"…","t":1764000000000000}
→ {"on":true,"op":"voice","start":1764000000300000}
← {"ok":true,"seq":22}
→ {"on":false,"op":"voice","start":1764000001200000}
← {"ok":true,"seq":23}
→ {"end":1764000001200000,"op":"turn","start":1764000000300000}
← {"ok":true,"seq":24}

A talkers engine, one voice enrolled as enrolled-1, reading the turn above; a second voice joins at 1.6 s, the two overlap, the first stops:

→ {"from":"through","kind":"talkers","name":"diarize","op":"engine","track":"ear-desk"}
← {"ok":true,"seq":25,"through":null}
← {"pcm":"…","t":1764000000000000}
← … frames; its labels for a time settle about 1 s after it
← {"turn":{"end":1764000001200000,"start":1764000000300000}}
→ {"end":1764000000300000,"op":"talkers","start":1764000000000000,"talkers":[]}
← {"ok":true,"seq":26}
→ {"end":1764000001200000,"op":"talkers","start":1764000000300000,"talkers":[{"id":"enrolled-1","score":null}]}
← {"ok":true,"seq":27}
→ {"end":1764000001600000,"op":"talkers","start":1764000001200000,"talkers":[]}
← {"ok":true,"seq":30}
→ {"end":1764000002100000,"op":"talkers","start":1764000001600000,"talkers":[{"id":"enrolled-1","score":null},{"id":1,"score":null}]}
← {"ok":true,"seq":31}
→ {"end":1764000002000000,"op":"talkers","start":1764000002100000,"talkers":[{"id":1,"score":null}]}
← {"code":"bad_request","ok":false}

The last ends before it starts and is refused, logging nothing; the engine holds what it has until it reports it right. Its first span ends at the turn's start and its second at the turn's end, the cut the turn line asked for, so a client knows at seq 27 that the engine labelled the whole turn enrolled-1. With its score null (diarize scores no span under 2 s), that label identifies no one, and the turn counts as unknown: a client acts only on a label whose non-null score it accepts.

An echo engine masking a play as it sounds, the tail heard out:

→ {"kind":"echo","name":"tail","op":"engine","track":"ear-desk"}
← {"ok":true,"ruled":1764000004980000,"seq":19}
← {"pcm":"…","t":1764000005000000}
← {"play":6,"rate":24000,"track":"mouth-desk"}
← {"from":0,"play":6,"samples":480,"start":1764000005019000,"track":"mouth-desk"}
→ {"on":true,"op":"mask","start":1764000005019000}
← {"ok":true,"seq":53}
→ {"op":"ruled","to":1764000005020000}
← {"ok":true}
← … the play's end, frames until 1764000005239000
→ {"on":false,"op":"mask","start":1764000005239000}
← {"ok":true,"seq":55}

A speech engine, its play on a second connection; the client's side is say, {"op":"text","text":"Hello there. "}, {"op":"text","text":"How are you?"}, end, then {"play":6,"reason":"end","say":5,"seq":58,"spoken":25,"text":"Hello there. How are you?","track":"mouth-desk"}:

→ {"kind":"speech","name":"read-aloud","op":"engine","track":"mouth-desk"}
← {"ok":true,"seq":18}
← {"say":5,"text":"Hello there. "}
  (second connection) → {"op":"play","rate":24000,"say":5,"track":"mouth-desk"} ← {"ok":true,"play":6,"seq":52}, then gives
→ {"op":"mark","samples":21600,"say":5,"text":13}
← {"ok":true}
← {"say":5,"text":"How are you?"}
← {"end":5}
→ {"op":"mark","samples":45600,"say":5,"text":25}
← {"ok":true}
  (second connection) → {"op":"end"}, then the play's last line