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
Job in flight right now. Populated by the WS session before dispatch, cleared once the job finishes (success or failure).
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).
RegistrationGate
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 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
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.

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
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.
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").
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.
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.