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§
- Current
Job - 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 inWorkerObservers::active_jobs. - GpuRuntime
Status - 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. - Heartbeat
Status - Loop
Schedule - Schedule for the long-running loops.
- Recent
Job - One finished job, retained in the recent-jobs ring for the UI.
- Register
Args - Bundle of flags from
studio-worker register. - Worker
Observers - Bundle of in-process observation slots the WS session writes to and
the optional native UI reads from.
Defaultgives empty slots so existing (headless) call sites stay one-liners. Cheap to clone — every field is anArc.
Enums§
- Auto
Update Decision - What the auto-updater decided this tick.
- Heartbeat
Outcome - 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.
- Registration
Gate - Outcome of the startup registration gate (
ensure_registered). - Session
State - 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
stopflag. Mirrors the WS session’s shutdown tick so a SIGTERM / SIGINT landing during the (up toAUTO_UPDATE_TICK-long) idle window wakes the loop within ~250 ms instead of leavingrun_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/RecentJobare 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_logsfor 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_capabilitiesbut lets the caller driveauto_enabledfrom a runtime pause flag (the UI’s Pause/Resume button). The persistedConfigno longer carries that bit — it’s an in-process toggle. - check_
update - clear_
registration - Clear the local registration state, as
register --resetdoes. - 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_tokenare populated (Approved →RegistrationGate::Ready), a stop signal arrives (→RegistrationGate::Stopped), or the operator rejects the worker (→Errwith 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-workeron 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_logbut also appends toWorkerObservers::recent_logsso 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_logsnewer than sequence numberafter, and the newest sequence number. A client passes the returned number back asafternext time to receive only what is new; anafterbeyond 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/uiis the only thing that talks to the studio. - request_
shutdown - Flip the
stopflag and emit a shutdown breadcrumb so an operator tailing the journal sees a clean stop, mirroringlog_startup_banner. Pulled out of the signal task so the shutdown decision is unit-testable without delivering a real OS signal.signalnames whatever woke us (e.g."SIGTERM"). - resolve_
local_ api_ port - Resolve the local API port: a valid
STUDIO_WORKER_LOCAL_API_PORTenv value wins, then the config’slocal_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’sstream_port, elsecrate::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
runso 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.statusis injected (the live caller passessd_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
Nonewhen 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.