Skip to content

The live coordinator ​

The coordinator (src-tauri/src/coordinator.rs) owns everything about what the audience sees. This page explains its design for people working on it. For the operator's view, see Staging, Preview and Live.

The coordinator has four jobs, each protecting against a different failure:

MechanismProtects against
A single lockTwo commands interleaving and leaving a half-updated scene
Command IDsOne key press delivered twice and acting twice
Scene revisions and acknowledgementsNot knowing what the room is actually seeing
Transition IDsAn old timer firing late and replacing a newer scene

It also holds Autopilot to the operator's rules: every move Autopilot asks for is checked under the same lock. See Autopilot's moves.

One lock, in order ​

The state is a single Mutex<LiveState>. Every command takes the lock, changes the state, bumps the revision if the scene changed, broadcasts, and releases. Commits are applied strictly one at a time.

Two details matter:

  • All coordinator and output commands are async. Creating a webview window from a synchronous command deadlocked the main thread on Windows. Making these commands async fixed it (commit 52500e1).
  • The coordinator lock is released before writing history, which takes the database lock. Never hold both at once.

Timers are plain threads that sleep and then call back into the coordinator.

Command IDs ​

live_go, live_step and live_goto take a commandId. The interface generates a fresh crypto.randomUUID() for each user action. The coordinator remembers the last 256 IDs. A repeat is accepted but does nothing, and returns the current revision.

That makes the commands that move content idempotent: a retried or duplicated call can't send the next slide twice. Mode toggles and lower-third commands describe a target state (on: true, mode: "black"), so repeating them is already harmless.

Pinned targets ​

A LiveTarget is {itemId, serviceId?, sectionId?, title, kind, sourceRevision, slides, index}. The coordinator validates it (slides not empty, index in range, current slide ready) and stores it as is. It doesn't look anything up. Live is a snapshot: editing the schedule afterwards can't change it.

Revisions ​

LiveState.revision is a counter that rises with every change to the audience scene. These commands bump it:

  • live_go: once when it commits directly. With a timed transition, once when the breaker shows and once more when the item follows.
  • live_step (when it moves), live_goto, live_mode, live_clear_text, live_set_logo, live_transition, live_overlay, live_hide_overlays, live_clear
  • Autopilot's step or verse jump, when it's carried out
  • the display watch, when the audience display disappears

These still broadcast a frame but don't bump the revision:

  • live_preview has its own previewRevision.
  • live_media uses media.nonce and restartNonce, so each output applies a play, pause or restart exactly once.
  • live_countdown, live_stage_message, output_open and output_close don't change the audience scene.

Sessions and acknowledgements ​

When output_open creates a window it gives it a new session UUID, stored in LiveState.audience or .confidence as OutputInfo.

The output window:

  1. starts from a local all-black frame at revision 0,
  2. subscribes to live:frame,
  3. fetches live_frame and keeps whichever frame has the higher revision (so it can't miss an event that arrived first),
  4. after each new revision is painted (two animation frames later), calls output_ack(role, session, revision).

output_ack ignores acknowledgements from a session that's been replaced, keeps the highest revision seen, and records the time. The first acknowledgement from a new window reveals it: output windows are created hidden and shown full screen only once they've drawn their first frame, so the audience never sees a white flash. If no acknowledgement arrives within 2.5 seconds, the window is shown anyway.

The control window compares ackRevision with the live revision. That's the On/Sync chip in the top bar and the r12 ✓ next to the Live monitor.

Timed transitions ​

A timed transition shows a breaker first, then commits the queued item when a timer ends.

  1. live_go with transition: {slide, durationMs} (capped at 60 000 ms) creates a TransitionState with a fresh UUID, the breaker slide and the queued target. The frame shows the breaker, and the queued item's first slide becomes nextSlide.
  2. The timer starts when the audience has drawn the breaker: when an acknowledgement at or above the transition's revision arrives. A fallback thread starts it after 400 ms anyway, so a slow output can't hold up the service. With no audience output, it starts at once.
  3. start_transition_timer(id) and complete_transition(id) do nothing unless the current transition still has that id, hasn't already started, and isn't held.

Step 3 is what makes stale timers harmless. If the operator went live with something else, pressed Black, or skipped, the transition was replaced or cleared. When the old timer wakes up, its ID no longer matches and it does nothing.

Cancelled byQueued item
A newer live_goReplaced by the new target
live_gotoDropped
live_mode Black or LogoDropped
live_clearDropped
Audience display lostDropped

live_step is refused during a transition (reason: "transition"). live_transition("skip") commits the queued target now. "stop" makes the breaker itself the live scene, as a synthetic target with itemId held-breaker-<uuid> and kind breaker.

Side effects of going live ​

Every live_go resets mode to Content and turns off Clear Text and Hide Overlays. It also clears the stage message. When the item changes, it also:

  • resumes media if it was stopped or paused,
  • removes lower thirds unless they're marked keepVisible or tied to the new item.

Autopilot's moves ​

Autopilot is a separate app, but it never changes Live itself. It sends small commands over the Link, each with its own command ID and the revision of Live it was decided on, and Altar Studio carries them out only if its rules allow. The checks and the move happen under the coordinator lock, so nothing can change Live in between.

There are three ways Autopilot moves Live:

MoveCarried out byUsed for
Step one slide forwardautopilot_step in coordinator.rsThe next verse of a passage, The Word's next point, a song's next slide
Jump to a slide of the live passageautopilot_gotoA verse number spoken during a reading
Go Live with a new targetThe control window, through live_go with autopilot setOpening a passage from The Word, or going back to the Word slide it left

The third needs slides laid out, which only the control window can do. autopilot.rs decides Live or Preview first: a passage goes Live only in Auto mode, and only when it's planned in the Word item or was opened earlier while that Word item was live. Everything else, suggestions included, goes to Preview. It then sends the request to the control window as autopilot:request, and live_go takes it back by its ID with the rules it must meet. A request the control window hasn't carried out after 6 seconds is refused.

The rules ​

Every move must first pass these checks, in this order. The first that fails is the refusal Autopilot gets back:

RefusalRefused when
duplicateThe command ID was seen before. Autopilot's IDs share the list of the last 256 with the operator's.
staleLive's revision isn't the one Autopilot decided on: something changed since
black, logo, clearTextBlack, Logo or Clear Text is on
transitionA timed breaker is running
nothingLiveNothing is live
operatorActiveThe operator acted on Live less than 4 seconds ago
tooSoonAutopilot's own last move was less than 1.5 seconds ago

Before these, autopilot.rs refuses everything with paused while the operator has paused Autopilot.

Then each move has its own rules:

  • The type must be in Auto. A step or jump needs the live item's type in Auto mode: notEnabled when it's off, suggestOnly in Suggest mode. Scripture follows The Word's mode, but only when it was opened from a Word item. Other scripture is notEnabled.
  • The kind must have earned it. A step in a hymn, song or Word item is refused with notEarned until that kind has earned moving Live on this computer (a track record kept in autopilot_track.rs, or the operator's override). Altar Studio then puts the next slide in Preview as a suggestion instead. Passages opened from The Word don't need it.
  • One slide at a time, never past the end. A step moves exactly one slide forward. At the item's last slide it's refused with lastSlide: Autopilot never moves on to the next item in the schedule. A slide that isn't ready is notReady.
  • Jumps only within a passage. A jump to a verse is allowed only in scripture opened from The Word (notInWord), to a slide that exists (notFound).
  • Opening and returning follow The Word. Both need The Word in Auto mode. A passage opens only from a live Word item or a passage opened from one. A return goes only to the Word item the passage came from, and only to the slide it left or the next one (tooFar).

A carried-out move bumps the revision, is broadcast like any other change, is written to the live history as autopilot:step, autopilot:goto or autopilot:go-live, and starts the 1.5-second gap.

The operator always wins ​

Every operator command on Live (live_go, live_step, live_goto, live_mode, live_clear_text, live_transition and live_clear) records the time and tells Autopilot to hold back for 4 seconds. An Autopilot command decided before it is usually stale too, since the revision has moved on.

The coordinator also remembers whether the last move was Autopilot's or the operator's. Autopilot's decision log uses that to tell a move the operator kept from one they undid.

The Word context ​

To keep Autopilot inside the passage it's following, the coordinator keeps a Word context: the Word item and slide a passage was opened from, whoever opened it.

  • Going Live with scripture from a Word item sets it to that item and slide.
  • Another passage opened during a reading keeps it, so the return still goes to the same Word slide.
  • Going Live with anything else clears it, unless it's the same Word item again.
  • A stopped breaker and live_clear clear it.

Autopilot receives it with the Live state while a passage is live. Nothing in it is sent to the windows: LiveState skips it, along with the operator's and Autopilot's last-move times.

Display loss ​

outputs::spawn_display_watch polls every 2 seconds while an output is assigned. If a window's display key is gone, the window is destroyed. It's never moved to another display. For the audience, the watch also cancels any transition, pauses playing media, sets the mode to Black and bumps the revision. Then it emits output:lost.

Starting state ​

LiveState::default() has nothing live, with mode Content, so outputs draw nothing (black). Output windows begin from a local frame in Black mode until the first real frame arrives.

Testing changes ​

The coordinator's tests (cargo test in src-tauri) cover Autopilot's moves: each rule above, the revision check, the Word context and the earned kinds. The rest of the coordinator has no automated tests. Check changes by hand in the desktop app (npm run tauri dev), with an output open. The browser mock has its own simplified coordinator and won't show backend bugs. Things to try:

  • Double-Enter quickly and repeatedly. Nothing should go live twice.
  • Start a timed transition, then press Black, Skip, Stop or go live with something else. Check the queued item does what the table says.
  • Unplug the output display (or disconnect it in the operating system's display settings) during a transition.
  • With Autopilot on in Auto mode, press PageDown or Black while it's following. It should hold back for 4 seconds, and never move during Black.

To drive Autopilot from a script instead of speaking, use the development aids in Run Altar Studio from source.

Altar Studio by Milton Black. Free and open source.