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 - Job in flight right now. Populated by the WS session before dispatch, cleared once the job finishes (success or failure).
- 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).
- Registration
Gate - Outcome of the startup registration gate (
ensure_registered).
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 - 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.
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 - 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. - 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"). - 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. - set_
threshold - show_
config - spawn_
auto_ updater - 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. - truncate_
prompt - vram_
threshold_ warning - Operator-facing warning when the configured VRAM threshold exceeds the GPU VRAM the worker actually detected.