Skip to main content

Module runtime

Module runtime 

Source
Expand description

Long-running heartbeat + claim loop, log shipper, auto-update task, and the one-shot CLI helpers.

The four loops (spawn_heartbeat, spawn_claim_loop, spawn_log_shipper, spawn_auto_updater) are thin while !stop wrappers around the testable *_tick helpers below — those are the places real per-iteration logic lives, and they’re 100% unit-tested.

Structs§

CurrentJob
Job in flight right now. Populated by claim_tick before dispatch, cleared once the job finishes (success or failure).
HeartbeatStatus
LoopSchedule
Schedule for the four background loops. Tests dial these intervals down to milliseconds so we can exercise the loop bodies quickly.
RecentJob
One finished job, retained in the recent-jobs ring for the UI.
WorkerObservers
Bundle of in-process observation slots written by the runtime loops and read by the UI. 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.
ClaimOutcome
Outcome of a single claim attempt.
HeartbeatOutcome
Result of the most recent heartbeat_tick.
JobOutcome
Outcome a finished job ended with. Failures carry the human reason (already surfaced to logs + Sentry).

Constants§

AUTO_UPDATE_TICK
CLAIM_INTERVAL_AFTER_NULL
CLAIM_INTERVAL_IDLE
HEARTBEAT_INTERVAL
LOG_FLUSH_INTERVAL
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.

Functions§

auto_update_tick
build_capabilities
check_update
claim_tick
One claim attempt + (when a job is claimed) run-to-completion.
format_check_outcome
format_status
heartbeat_tick
Send one heartbeat. Returns Ok regardless of whether the HTTP call succeeded — failures are captured in the log buffer and in observers.last_heartbeat for the UI.
is_unsupported_kind
log_shipper_tick
Flush all buffered logs to the API. Returns the number of entries shipped (0 if no logs were buffered or the worker isn’t registered).
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.
next_delay_for
Pure helper so the schedule decision is unit-testable.
prompt_for
push_log
register
run
run_loops
Spawn the four loops with the supplied schedule and wait for them to exit. Pulled out of run so tests can drive the loop wrappers with short intervals.
set_enabled
set_threshold
show_config
spawn_auto_updater
spawn_claim_loop
spawn_heartbeat
spawn_log_shipper
status