Files
Build-System/docs/build-system/consumer/daemon.md
T

9.1 KiB
Raw Blame History

title, description, section, badge, order, tags, updated
title description section badge order tags updated
Editors and the Build Daemon Run the warm Unix-socket daemon, drive builds and IDE metadata over JSON lines, and understand its bounds Editors & Daemon vbs daemon 2
daemon
socket
protocol
ide
workspace
watch
json
2026-12-06

Editors and the Build Daemon

vbs daemon keeps a warm StateStore and a project file watcher in one long-lived process. Editors and automation send newline-delimited JSON requests over a Unix-domain socket instead of paying descriptor compilation, toolchain probing and dependency resolution on every action.

:::callout{type="warning" title="Daemon availability"} The daemon transport is a POSIX Unix-domain socket. It is compiled out on Windows in 1.0.0. The registry service is also POSIX-only. Linux is the supported daemon host. :::

Start and stop

vbs daemon run --project . --build-dir build
vbs daemon status --project .
vbs daemon stop --project .

The socket defaults to <build>/.vbs/vbs-daemon.sock. The daemon:

  • binds with mode 0600, so only the owning user can connect;
  • probes an existing socket and replaces it only when it is stale;
  • removes only its own socket on shutdown, after checking device and inode;
  • refuses a second live daemon for the same socket;
  • accepts --max-requests N for bounded test runs (0 = unlimited).

vbs daemon info returns version, host, roots, lockfile state, socket path and enabled backends. vbs daemon doctor returns structured host/tool diagnostics. vbs daemon status reports PID, uptime, recorded actions, watched directories, event sequence and pending changes.

Protocol

One request object per line, one response object per line:

printf '%s\n' '{"op":"ping"}' | socat - UNIX-CONNECT:build/.vbs/vbs-daemon.sock
{"ok":true,"op":"ping"}
  • Requests are strict JSON objects with a string op.
  • Maximum request size is 64 KiB; maximum JSON depth is 16.
  • Malformed JSON, a non-object, a missing op or an invalid field type returns a JSON error object with "ok": false; the connection remains usable.
  • Field validation is explicit and bounded. Unknown fields are ignored; invalid values are errors.

The daemon is single-threaded. watch_wait is a bounded long poll (0–5000 ms, default 2000), and other requests queue behind it. A request either completes or returns an explicit error; there is no request cancellation API in 1.0.0. Daemon builds also lower without an input snapshot in 1.0.0, so their action keys and cache records do not match vbs build; expect a warm daemon cache rather than CLI cache reuse.

Request catalog

Operation Purpose Key fields
ping Liveness —
status Warm-store and watcher status —
info Version, host, roots, backends, lockfile —
doctor Structured host/tool diagnostics —
describe Evaluate and summarize a graph profile, member
build Build a graph in-process profile, targets, jobs, member, compiler
test Build and run test targets same as build
deps Resolve/materialize dependencies profile, offline, update, member
graph Export target dependencies profile, format (dot, json, mermaid), member
actions List lowered actions profile, kind, limit, member
target_list Sorted target names/kinds profile, limit, member
target_info One target's kind, sources, outputs, runtime libraries name, profile, member
target_flags Per-unit arguments, defines and compile options name, file, profile, member
workspace_members Declared members without evaluation —
workspace_info Members plus root lockfile presence/size —
install Build and stage an install prefix profile, prefix, component, export flags
uninstall Remove manifest-owned files prefix
pack Deterministic source archive confined to the build root output
clean Remove profile outputs or the whole build root all
init Scaffold a project confined to the project root dir, name, flags
gen_tests Generate a native test registration unit input, output_dir
gc Recover interrupted state and collect CAS garbage max_bytes
recover Run interrupted-state recovery —
shutdown Stop the daemon —

Editor and compilation-database requests:

Operation Purpose
ide_query Publish/select the profile database and return IDE workspace/target JSON
ide_generate Write .clangd, .vscode/, .zed/, .idea/ presets
ide_configs Report which editor configuration files exist
editor_status Active selection: ticket, profile, build root, generation, compdb path and entry count
compdb_export Publish the profile database and return its path/entry count
compdb_use Switch the active editor profile to a published database
compdb_entries Bounded entries filtered by file suffix and limit
compdb_generations Immutable generations for a profile with active selection and counts
compdb_stale Mark a profile generation stale with a bounded reason
watch_poll Drain buffered changes immediately; optional prefix filter
watch_wait Bounded long poll for changes; optional prefix and timeout_ms

Watch protocol example

{"op":"watch_wait","prefix":"src/","timeout_ms":2000}
{"ok":true,"op":"watch_wait","sequence":42,"watch_events":7,
 "changed":["src/main.cpp"],"timed_out":false}

watch_poll additionally reports overflowed and rescan_required when the watcher could not guarantee an exhaustive event list. Buffered paths are capped at 4096; a prefix filter returns matching paths and retains non-matching ones for a later request.

Build request example

{"op":"build","profile":"debug","targets":["app"],"jobs":8}
{"ok":true,"op":"build","profile":"debug","targets":["app"],
 "actions":12,"executed":0,"cached":12,"failed":0}

The response also carries a diagnostic on failure and a bounded failed_actions list. Dependency materialization happens inside the daemon for build, test, deps and install, using the same resolver as the CLI; the response reports the dependency context.

Workspaces

  • describe accepts an optional member. A workspace root without member returns a bounded per-member summary; an unknown member is rejected.
  • build with no member builds every member in declared order against the shared root lock and CAS and returns per-member outcomes plus aggregate executed/cached/failed.
  • test does the same for declared test targets.
  • ide_query, ide_generate and compdb_export require member for a workspace root and reject it for a plain project.
  • workspace_members lists members without evaluating them; workspace_info adds root lockfile metadata.

Bounds and limitations

Limit Value
Request size 64 KiB
JSON depth 16
Describe target names 128 entries × 200 bytes
Describe/evaluate timeout 10 s
Build target list 64 targets
Compilation-database entries 500
Compilation-database generations 128
Install file list 128 paths × 512 bytes
Actions list 1000
Pending watch paths 4096
Long-poll timeout 5000 ms
Registry/editor build requests One at a time (single-threaded)

The daemon is not a sandbox. It evaluates trusted build.cpp code with the user's privileges, like the CLI. It does not add authentication on top of filesystem permissions; protect the build root and socket like any other user-owned development artifact.

Additional 1.0.0 limits:

  • Daemon build/deps materialize dependencies but do not publish updated vbs.lock contexts; run the CLI for lock updates.
  • Metadata-only requests (describe, actions, target_info, target_flags, ide_query, ide_generate) lower without provider imports, so a project that links imported dependency targets can fail with an unresolved-target error. Use vbs build or the CLI IDE commands to populate provider metadata first.
  • Daemon test is a reduced runner: no labels, resources, fixtures, Wine, JUnit, coverage or CDash, and no per-case reporting.
  • Daemon clean --all removes the live build root while the daemon keeps running; later requests can fail until it is restarted.
  • compdb_export, compdb_entries, compdb_use, editor_status and ide_configs are root-scoped and are not member-aware.

When to use the daemon

:::cards @@card[Long editor sessions|badge=IDE] Keep descriptor, toolchain and compdb work warm while the editor polls for changes. @@card[Repeated builds|badge=build] Reuse the warm state store and watcher across actions instead of restarting vbs. @@card[Remote workers|href=/build-system/consumer/remote-ci|badge=CI] The registry worker protocol and remote cache cover distributed execution; the daemon is local. @@card[Scripting|badge=JSON] Any language that can open a Unix socket can query targets, flags, entries and graphs. :::

Next: run tests and reports or use a remote cache.