Skip to main content

Module runtime

Module runtime 

Source
Expand description

Long-running auto-update task + one-shot CLI helpers.

After the WS migration the runtime owns just two background tasks: the WebSocket session (ws::session::spawn_ws_session, which subsumes heartbeats, claim/accept/complete, fail, and log shipping) and the auto-updater (spawn_auto_updater). Per-tick helpers from the old polling loops are gone.

Structs§

CurrentJob
A job in flight. The studio’s job also sits in WorkerObservers::current_job (the heartbeat reports it); every running job, whatever its source, sits in WorkerObservers::active_jobs.
GpuRuntimeStatus
GPU-runtime readiness, probed once at startup so a missing Vulkan loader surfaces as an actionable status (UI + /healthz) before the first image job fails, not after.
HeartbeatStatus
LoopSchedule
Schedule for the long-running loops.
RecentJob
One finished job, retained in the recent-jobs ring for the UI.
RegisterArgs
Bundle of flags from studio-worker register.
WorkerObservers
Bundle of in-process observation slots the WS session writes to and the optional native UI reads from. Default gives empty slots so existing (headless) call sites stay one-liners. Cheap to clone — every field is an Arc.

Enums§

AutoUpdateDecision
What the auto-updater decided this tick.
HeartbeatOutcome
Result of the most recent heartbeat the WS session sent.
JobOutcome
Outcome a finished job ended with. Failures carry the human reason (already surfaced to logs + Sentry).
JobSource
Where a job came from.
RegistrationGate
Outcome of the startup registration gate (ensure_registered).
SessionState
Where the WS session is in its lifecycle, surfaced to the UI so a worker that can’t reach the studio shows why instead of sitting silently. Terminal states (AuthFailed, Fatal) carry a call-to-action the Status tab renders.

Constants§

AUTO_UPDATE_SHUTDOWN_TICK
Cadence at which the auto-updater’s idle wait re-checks the stop flag. Mirrors the WS session’s shutdown tick so a SIGTERM / SIGINT landing during the (up to AUTO_UPDATE_TICK-long) idle window wakes the loop within ~250 ms instead of leaving run_loops’ join blocked for a whole tick.
AUTO_UPDATE_TICK
DEFAULT_LOCAL_API_PORT
Default port for the always-on local image API. Override with STUDIO_WORKER_LOCAL_API_PORT.
HEARTBEAT_INTERVAL
Default WS heartbeat interval, re-exported here so the native UI (and any other downstream readers) get a stable constant without reaching into ws::session.
LOG_SHIP_QUEUE_CAP
Maximum number of entries the WS ship queue (logs: Arc<Mutex<Vec<LogEntry>>>) may hold. The shipper pump only drains while a session is connected, so a long approval wait or reconnect backoff would otherwise grow the queue without bound. On overflow the oldest entries are dropped and a warn-level marker records the loss.
PROMPT_PREVIEW_CHARS
Prompt previews stored in CurrentJob / RecentJob are clipped to this many chars so the in-memory state stays bounded even when LLM prompts are huge.
RECENT_JOBS_CAP
Maximum number of finished jobs kept in WorkerObservers::recent_jobs. Older entries fall off the back of the ring.
RECENT_LOGS_CAP
Maximum number of log entries kept in WorkerObservers::recent_logs for the UI’s Logs tab. The shipping queue (logs: Arc<Mutex<Vec<…>>>) is drained on every WS tick — the display ring is what the UI reads.
REGISTRATION_RESET_POLL
How often the rejection wait checks for a reset or a stop.

Functions§

auto_update_tick
build_capabilities
build_capabilities_with
Same as build_capabilities but lets the caller drive auto_enabled from a runtime pause flag (the UI’s Pause/Resume button). The persisted Config no longer carries that bit — it’s an in-process toggle.
check_update
clear_registration
Clear the local registration state, as register --reset does.
ensure_local_api_token
Ensure the per-install local API bearer token exists, minting and persisting one on first launch. A failed persist is warn-logged but non-fatal: the in-memory token still guards this session and the discovery file still tells clients what it is.
ensure_registered
Loop auto_register::tick on a 30s cadence until worker_id + auth_token are populated (Approved → RegistrationGate::Ready), a stop signal arrives (→ RegistrationGate::Stopped), or the operator rejects the worker (→ Err with recovery guidance).
format_check_outcome
format_status
is_unsupported_kind
log_startup_banner
Emit a one-shot startup banner so operators can confirm which config the worker actually loaded. Without this the only thing in journalctl -u studio-worker on a healthy boot is whatever the loops happen to log on their first tick.
prompt_for
push_log
push_log_with_observers
Same as push_log but also appends to WorkerObservers::recent_logs so the UI’s Logs tab keeps a rolling display window. The WS session uses this variant so operators don’t see the Logs tab blank out every second when the shipping queue gets drained.
recent_logs_after
Entries of recent_logs newer than sequence number after, and the newest sequence number. A client passes the returned number back as after next time to receive only what is new; an after beyond the newest number (the daemon restarted) answers the whole ring.
record_local_job
Record a finished local-API job into the local-queue ring.
record_recent_job
register
Persist registration metadata for the next launch. No HTTP — the auto-register orchestration inside run / ui is the only thing that talks to the studio.
request_shutdown
Flip the stop flag and emit a shutdown breadcrumb so an operator tailing the journal sees a clean stop, mirroring log_startup_banner. Pulled out of the signal task so the shutdown decision is unit-testable without delivering a real OS signal. signal names whatever woke us (e.g. "SIGTERM").
resolve_local_api_port
Resolve the local API port: a valid STUDIO_WORKER_LOCAL_API_PORT env value wins, then the config’s local_api_port, then the built-in default. An invalid env value used to be silently ignored; now it warn-logs what it fell back to so a typo’d unit file can’t quietly move the API. Pure so every branch is unit-testable.
resolve_stream_port
The LAN stream listener’s port: STUDIO_WORKER_STREAM_PORT, else the config’s stream_port, else crate::stt_stream::server::DEFAULT_STREAM_PORT.
restore_unshipped
Put a drained-but-unsent batch back at the front of the ship queue so it survives for the next session attempt. Entries that arrived while the batch was in flight stay behind it (newest last). The combined queue is clipped to LOG_SHIP_QUEUE_CAP, dropping the oldest entries first.
run
run_loops
Spawn the WS session + auto-updater, wait for them. Pulled out of run so tests can drive with a different schedule.
serve_studio
Register with the studio, then run the studio loops. A rejection does not end the daemon: it keeps serving locally and waits for a registration reset (from the tray UI) or a stop.
set_gpu_runtime_status
Probe the GPU runtime and record it in observers, warn-logging the remedy when it’s missing. status is injected (the live caller passes sd_provision::vulkan_runtime_status()) so the observer-write + logging are testable without a real GPU stack.
set_session_state
Record the WS lifecycle state for the UI to read.
set_threshold
show_config
spawn_auto_updater
spawn_local_api
Build the engine + catalog and start the local image API server on a background thread. Returns the thread handle, or None when it could not start (logged, non-fatal — the studio session keeps running).
status
summarize_capabilities
One-line, operator-facing summary of what this worker advertises to the studio on the WS handshake. Logged once per session attempt so the worker’s own logs (and the studio’s shipped-log view) record exactly which task kinds, models, and VRAM budget were offered — the missing complement to log_startup_banner, which only covers the loaded config. Without it, an operator chasing “why won’t my worker claim image jobs” has no record of what the worker told the studio it could do. Pure so the formatting is unit-tested without a live session.
sync_studio_model
Mirror a model seen on a studio job offer into the shared local catalog so the local API can serve it too. Persists atomically when the catalog changed; a local-origin entry of the same id is never clobbered. Best-effort: a persist failure is warn-logged but never fails the job.
truncate_prompt
vram_threshold_warning
Operator-facing warning when the configured VRAM threshold exceeds the GPU VRAM the worker actually detected.