Expand description
sqry-daemon — long-lived code-graph service.
The daemon (sqryd binary) owns one or more loaded code graphs in memory,
watches source trees for changes, and serves CLI / LSP / MCP clients over a
shared Unix-domain socket (named pipe on Windows). The goal is to amortise
graph-load cost across every sqry invocation on a machine while preserving
the semantic guarantees of direct-mode sqry (bijective per-file buckets,
tombstone compaction, ArcSwap publish, etc.).
§Architecture at a glance
config— parses~/.config/sqry/daemon.tomlinto aconfig::DaemonConfigwith every tuning knob from the Amendment-2 design (memory limits, working-set multipliers, stale-serve age cap, debounce timing, interner compaction threshold, log rotation, socket path).workspace(Task 6) —WorkspaceManagerownsLoadedWorkspacestate (§G admission accounting, §H rebuild plumbing, §F bijection check).rebuild(Task 7) — per-workspace rebuild lane + coalescing (§J).ipc(Task 8) — JSON-RPC over UDS with a standard response envelope.lifecycle(Task 9) — pidfile locking, signal handling, service unit generators.- [
client] (Task 10) — client library used bysqry-cli/sqry-lsp --daemon/sqry-mcp --daemonto connect to a running daemon and auto-start one if necessary.
Only config and the public error type DaemonError are in the surface
today; later tasks in this plan land the other modules in order.
Re-exports§
pub use config::DEFAULT_IPC_SHUTDOWN_DRAIN_SECS;pub use config::DaemonConfig;pub use config::ESTIMATE_FINAL_PER_FILE_BYTES;pub use config::ESTIMATE_STAGING_PER_FILE_BYTES;pub use config::INTERNER_BUILDER_OVERHEAD_RATIO;pub use config::SocketConfig;pub use config::WORKING_SET_MULTIPLIER;pub use config::WorkspaceConfig;pub use error::DaemonError;pub use error::DaemonResult;pub use ipc::IpcServer;pub use rebuild::RebuildDispatcher;pub use rebuild::RebuildMode;pub use rebuild::decide_mode;pub use workspace::BACKOFF_SCHEDULE;pub use workspace::DaemonStatus;pub use workspace::LoadedWorkspace;pub use workspace::MemoryStatus;pub use workspace::NoOpHook;pub use workspace::OldGraphToken;pub use workspace::PendingRebuild;pub use workspace::RealWorkspaceBuilder;pub use workspace::RebuildReservation;pub use workspace::ServeVerdict;pub use workspace::SqrydHook;pub use workspace::StalenessVerdict;pub use workspace::WorkingSetInputs;pub use workspace::WorkspaceBuilder;pub use workspace::WorkspaceKey;pub use workspace::WorkspaceManager;pub use workspace::WorkspaceStatus;pub use workspace::backoff_delay_for;pub use workspace::classify_staleness;pub use workspace::noop_hook;pub use workspace::spawn_hook;pub use workspace::working_set_estimate;
Modules§
- config
- Daemon configuration.
- entrypoint
- Task 9 U10 — production sqryd binary entry point.
- error
- Daemon-wide error type.
- ipc
- IPC surface of the sqryd daemon.
- lifecycle
- Task 9 — daemon binary lifecycle: pidfile locking, signal handling, service unit generators, log rotation, and auto-spawn primitives.
- mcp_
host - Phase 8c U8 — in-daemon MCP host.
- rebuild
- Rebuild dispatcher for the sqryd daemon (Task 7 Phase 7a + 7b1).
- workspace
- Workspace management — state machine + admission accounting.
Structs§
- Cancel
Rebuild Result daemon/cancel_rebuildsuccess result payload.- Daemon
Hello - Pre-handshake header sent as the very first frame by a CLI client.
The server responds with
DaemonHelloResponsebefore the JSON-RPC request loop begins. - Daemon
Hello Response - Server’s reply to
DaemonHello. Ifcompatibleisfalsethe server closes the connection immediately after the frame is sent. - Json
RpcError - JSON-RPC 2.0 error payload.
- Json
RpcRequest - JSON-RPC 2.0 request.
- Json
RpcResponse - JSON-RPC 2.0 response.
idisOption<JsonRpcId>with noskip_serializing_if— theNonecase serialises as JSONnull, which is exactly what the spec demands for parse-error and invalid-request responses. - Json
RpcVersion - JSON-RPC
"2.0"version tag. Manual serde impls enforce exact string match on the wire so malformed requests never leak into the method dispatcher. - Rebuild
Result daemon/rebuildsuccess result payload (schema_version 2 — see cluster-G §2.4).- Response
Envelope - Uniform successful-response wrapper. Every successful method
response is serialised as
ResponseEnvelope<T>at the JSON-RPCresultfield — clients can rely on theResponseMetashape being present on every successful reply regardless of method. - Response
Meta - Metadata attached to every successful response. For Phase 8a
management methods the staleness fields are always absent
(
stale = false, no last_good_at, no last_error,workspace_state = None). Phase 8b populates them from the server-sideServeVerdictfor tool-method responses.
Enums§
- Json
RpcId - JSON-RPC id:
null, integer (signed or unsigned), or string.I64coversi64::MIN..=i64::MAX;U64coversi64::MAX + 1..=u64::MAX. Serde’s untagged deserialize tries variants in order so0..=i64::MAXlands inI64andi64::MAX + 1..=u64::MAXinU64. - Json
RpcPayload - Tagged success-or-error payload. Serde
untaggedso the wire form is{... "result": ...}or{... "error": ...}, never both. - Workspace
State - Six-state workspace lifecycle per plan Task 6 Step 1 and Amendment 2 §G.5 / §G.7.
Constants§
- ENVELOPE_
VERSION - Version of the daemon wire envelope (
DaemonHelloResponse.envelope_version). - JSONRPC_
INTERNAL_ ERROR - JSON-RPC 2.0 standard “Internal error” code. Catch-all for errors
bubbling from
sqry_mcp::daemon_adaptertool execution that don’t map to a more specificDaemonErrorvariant. - JSONRPC_
INVALID_ PARAMS - JSON-RPC 2.0 standard “Invalid params” error code.
- JSONRPC_
MEMORY_ BUDGET_ EXCEEDED - JSON-RPC error code: admission control could not satisfy a reservation after evicting every non-pinned workspace.
- JSONRPC_
QUERY_ TOO_ BROAD - JSON-RPC error code: pre-flight cost gate rejected a query because
its evaluator cost is structurally unbounded (no scope filter, no
regex anchoring, predicate shape would scan the full arena). Wire
kindis always"query_too_broad". Reuses-32602per the existing wire-bridge convention;kindis the discriminator (perB_cost_gate.md§3 “Why -32602, not a new -32xxx code”). - JSONRPC_
RESET_ CANCELLATION_ DISPATCHED - JSON-RPC error code:
daemon/resetwas invoked on a workspace whose state isRebuilding; cancellation has been dispatched and the caller is expected to retry afterretry_after_msfor the state to settle intoFailed/Unloaded(then a follow-up reset completes). - JSONRPC_
RESET_ WHILE_ LOADING - JSON-RPC error code:
daemon/resetwas invoked on a workspace whose state isLoadingand cannot be safely interrupted yet. Caller should retry once the load completes. - JSONRPC_
SOCKET_ SETUP - JSON-RPC error code: socket parent directory cannot be created or
is not writable by the daemon’s uid. Surfaced before
IpcServer::bindso the failure mode is a precise diagnostic instead of a genericEACCESfrom the eventual bind. - JSONRPC_
TOOL_ TIMEOUT - JSON-RPC error code: per-tool invocation exceeded
DaemonConfig::tool_timeout_secs. Emitted bytool_core::classify_and_execute(Task 8 Phase 8c U6) when thetokio::time::timeout(tool_timeout, spawn_blocking(run))outer timer fires. The detachedJoinHandleis dropped — the OS thread may continue executing the tool closure but its result is discarded. - JSONRPC_
WORKSPACE_ BUILD_ FAILED - JSON-RPC error code: workspace build failed and no prior good graph exists.
- JSONRPC_
WORKSPACE_ EVICTED - JSON-RPC error code: the workspace was evicted or removed between a
rebuild dispatch and its admission / publish commit. Callers must treat
this as a terminal signal on the affected
WorkspaceKey— subsequent dispatches require a freshget_or_loadfirst. - JSONRPC_
WORKSPACE_ INCOMPATIBLE_ GRAPH - JSON-RPC error code: the on-disk graph snapshot or manifest cannot be
loaded safely by this binary. Distinct from
WorkspaceBuildFailedbecause it represents a path-policy / compatibility verdict (unknown plugin ids, unsupported snapshot format) rather than a transient build failure — clients react differently (rebuild vs. upgrade vs. retry). - JSONRPC_
WORKSPACE_ OVERSIZE - JSON-RPC error code: the freshly-built graph exceeds the daemon’s
memory budget by itself (post-build oversize) — even after every
other workspace would be evicted, the daemon cannot host this
graph. Distinct from
MemoryBudgetExceeded(-32003), which is a projected admission failure on a pre-build estimate. - JSONRPC_
WORKSPACE_ PINNED - JSON-RPC error code:
daemon/resetrefused because the targeted workspace is pinned and the caller did not passforce = true. Pinning is a per-workspace operator override; callers must opt in explicitly to drop a pinned workspace. - JSONRPC_
WORKSPACE_ STALE_ EXPIRED - JSON-RPC error code: the workspace is serving a Failed state, but the last
successful build is older than
stale_serve_max_age_hours.