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§
- Current
Job - Job in flight right now. Populated by
claim_tickbefore dispatch, cleared once the job finishes (success or failure). - Heartbeat
Status - Loop
Schedule - Schedule for the four background loops. Tests dial these intervals down to milliseconds so we can exercise the loop bodies quickly.
- Recent
Job - One finished job, retained in the recent-jobs ring for the UI.
- Worker
Observers - Bundle of in-process observation slots written by the runtime
loops and read by the UI.
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.
- Claim
Outcome - Outcome of a single claim attempt.
- Heartbeat
Outcome - 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/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.
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_heartbeatfor 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-workeron 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
runso 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