Worker Contract (v0.2)
A worker is a process running on a GPU node that registers with the router, heartbeats, leases queued jobs, runs them, and reports results. This is the real external integration surface.
Every /workers/* call (except register) carries the worker_token as a bearer token. The
router authenticates via HTTPBearer in core/security.py (require_worker): a missing/invalid
token → 401; a banned worker → 403.
Lifecycle
Section titled “Lifecycle”-
Register —
POST /workers/registerwithWorkerRegisterRequest {node_id, name, hostname, endpoint_url?, capabilities, tags, version, heartbeat_interval_seconds}. ReturnsWorkerRegisterResponse {worker_id, worker_token, status}; mints aworker_registeredreceipt. Theworker_tokenis the long-lived bearer credential. -
Heartbeat —
POST /workers/heartbeatwith{status, capabilities?, current_jobs, metrics}. Returns{ok, worker_id, server_time, next_heartbeat_seconds}. -
Lease —
POST /workers/jobs/leasewith{supported_job_types[], supported_gpu_skus[], max_jobs}. The router matches capabilities to the oldest queued job and returnsWorkerLeaseResponse {lease_id, lease_token, job, expires_at, message}. Thelease_tokenhas a 600-second TTL; the server stores only its hash. -
Accept —
POST /workers/jobs/{id}/acceptwith{lease_token}→ job moves torunning. -
Status —
POST /workers/jobs/{id}/statuswith{lease_token, event_type, message?, payload}. -
Logs —
POST /workers/jobs/{id}/logswith{lease_token, message, payload}. -
Artifacts —
POST /workers/jobs/{id}/artifactswith{lease_token, artifact_type, name, uri, checksum_sha256?, size_bytes?, metadata}; mints anartifact_reportedreceipt. -
Complete —
POST /workers/jobs/{id}/completewith{lease_token, output_uri?, metrics, final_message?}. Computesactual_hoursandactual_cost_usdvia server-side pricing; mints the completion receipts and sets the job’sreceipt_id. -
Fail —
POST /workers/jobs/{id}/failwith{lease_token, error_code?, message, payload}. No charge in v0.2.
Every lease-bearing call verifies the lease with hmac.compare_digest against the stored hash and
checks it has not expired. See Routing Model for the lease
state machine and Receipt Capture for the receipts minted.
🐝 Operator-grade · books and records · to the shed.