7.7 KiB
title, description, section, badge, order, tags, updated
| title | description | section | badge | order | tags | updated | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Remote Cache and Distributed Workers | Share cached actions through the registry CAS, drain the action queue with vbs worker, and understand the trust boundaries | Remote & CI | remote | 1 |
|
2026-12-06 |
Remote Cache and Distributed Workers
A vbs-registry instance can act as a shared HTTP action cache and as a broker for remote execution. Both use the same bearer-authenticated transport and the same content-addressed storage as packages.
:::callout{type="warning" title="Trust boundary"}
Remote cache records and remote action specs are trusted input. A worker executes a command from a registry-provided action record with its own privileges and inherited environment. Do not point a worker at an untrusted registry; the protocol is not a sandbox.
:::
Shared action cache
vbs build --remote-cache https://cache.example.com
vbs build --remote-cache https://cache.example.com \
--remote-cache-token-env MY_CACHE_TOKEN
Environment form:
export VBS_REMOTE_CACHE=https://cache.example.com
export VBS_REMOTE_CACHE_TOKEN=...
vbs build
What happens
- The local cache is checked first.
- On a local miss, VBS asks
GET /api/v1/cas/actions/<action-key>. - A hit must match the declared output count, have every output blob available and verified, and pass discovered-input/lookup-guard checks.
- Missing blobs are fetched with
GET /api/v1/cas/blobs/<sha256>and re-hashed before use. - After a local success, blobs are uploaded first, then the action record (
PUT /api/v1/cas/blobs/...,PUT /api/v1/cas/actions/...). Upload is best-effort; a cache outage does not fail a successful local build.
Action keys are normalized to be build-directory independent: ${SNAPSHOT}, ${PROFILE}, ${BUILD} and ${PROJECT} replace absolute prefixes. The key still includes profile identity, toolchain identity, action id/kind, argv, response-file content, environment, declared input digests and the nondeterministic flag. Cross-toolchain reuse is intentionally impossible.
:::callout{type="info" title="Offline is not the same as isolated"}
--offline disables registry package resolution, not remote-cache traffic. If a build must not contact a remote cache, unset VBS_REMOTE_CACHE and omit --remote-cache. Use --no-cache to bypass both local reads and remote reads in one run; successes are still recorded locally and uploaded.
:::
The cache stores full output blobs, so the token holder can read build products. Use a private registry, a dedicated cache instance and short-lived tokens when products are sensitive.
Remote execution model
The registry maintains:
- worker registration and heartbeat records;
- an in-memory FIFO action queue;
- exclusive leases with a TTL and a lease token;
- action records and output blobs in the action-cache CAS.
Leases, workers, sessions and the queue are in-memory. Restarting the registry invalidates them and drops queued work; published blobs and action records persist in the data directory.
Direct worker mode
vbs worker --registry https://cache.example.com \
--action-key <64-hex-key> \
--record build/action-record.json \
--lease-seconds 300
- Register a worker.
- Lease the exact action key. The registry returns the record inline when the key exists.
- Publish every referenced output blob and the record to the CAS.
- Submit the result with the lease token.
Use direct mode when an orchestrator already knows the action key and the record.
Queue worker mode
vbs worker --queue --registry https://cache.example.com
vbs worker --queue --once
vbs worker --queue --idle-timeout 60 --parallel 4
--queueleases the next queued action, executes or publishes it, submits the result, and repeats.--oncestops after one action.--idle-timeout SECONDSkeeps watching an empty queue before exiting;0exits immediately.--parallel N(1–32) runs N concurrent lease/execute loops in one process. The registry leases an action to exactly one worker, so loops do not duplicate work.- Transient lease failures are retried three times before the worker exits.
If an action is already built locally, the worker exports the local action record. Otherwise it fetches the record from the CAS and executes the action spec:
{
"command": ["sh", "-c", "cat input.txt > output.txt"],
"working_directory": "/path/to/project",
"inputs": {
"input.txt": {"sha256": "…", "size": 12, "mode": 420}
},
"output_paths": ["output.txt"]
}
Inputs are downloaded and digest-verified, outputs are uploaded, and the result is submitted only after the required blobs exist. A missing command skips the action with a warning; a failed execution leaves the lease to expire rather than submitting a false success. There is no retry/backoff or capacity-aware scheduling in 1.0.0.
:::callout{type="warning" title="Size the lease above the execution"}
The worker CLI does not renew leases while an action runs. Set --lease-seconds larger than --exec-timeout (default 600) or a long action can finish after its lease expired and fail its result upload with 409 not_leased. The registry exposes a renewal endpoint and client API; the CLI loop does not call it yet.
:::
Registry-side endpoints
| Method + path | Purpose |
|---|---|
PUT/GET /api/v1/cas/blobs/<sha256> |
Store/fetch a content-addressed blob |
PUT/GET /api/v1/cas/actions/<action-key> |
Store/fetch an action record |
POST /api/v1/workers |
Register a worker |
POST /api/v1/workers/<id>/heartbeat |
Refresh worker liveness (owner/admin) |
GET /api/v1/workers |
List workers |
POST /api/v1/queue |
Enqueue action keys (publish scope or admin) |
GET /api/v1/queue |
List pending and leased keys |
POST /api/v1/queue/lease |
Lease the oldest unleased key |
POST /api/v1/actions/lease |
Lease a specific key and return its record |
POST /api/v1/actions/<key>/renew |
Extend a lease with its token |
POST /api/v1/actions/<key>/result |
Upload a result record and complete the lease |
All worker, lease and result endpoints require an authenticated principal. Enqueueing on POST /api/v1/queue additionally requires the publish scope or admin. The endpoints do not check ownership of a supplied worker id, so treat registry accounts as trusted build infrastructure; do not give a shared worker token to an untrusted user.
CI pattern
# 1. Start a private registry with a bootstrap admin.
export VBS_REGISTRY_ADMIN_PASSWORD='...'
vbs-registry --data-dir /var/lib/vbs-registry --bind 127.0.0.1 --port 8080 &
# 2. Create a publish-scoped token through the API or web UI.
# 3. Warm the cache.
vbs build --locked --remote-cache http://127.0.0.1:8080
# 4. A second clean checkout reuses verified actions.
git clone ... clean && cd clean
vbs build --locked --remote-cache http://127.0.0.1:8080
Use a separate build directory per job, but the same toolchain/profile identity. A cold build populates the cache; a second clean build reports cached actions instead of recompiling.
Limits
| Item | 1.0.0 behavior |
|---|---|
| Cache key reuse | Same toolchain/profile/inputs only |
| Cache verification | SHA-256 on every blob read |
| Upload failures | Warning only; local build still succeeds |
--offline |
Does not disable remote cache |
| Worker lease renewal | API exists; CLI does not renew |
| Worker scheduling | FIFO, no affinity, no capacity awareness |
| Worker restart | Queue, leases, workers and sessions are lost |
| Sandboxing | None; action specs run with worker privileges |
Next: run the registry service or read the registry internals.