Skip to main content

Crate sqry_daemon

Crate sqry_daemon 

Source
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.toml into a config::DaemonConfig with 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)WorkspaceManager owns LoadedWorkspace state (§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 by sqry-cli / sqry-lsp --daemon / sqry-mcp --daemon to 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::SharedHook;
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§

CancelRebuildResult
daemon/cancel_rebuild success result payload.
DaemonHello
Pre-handshake header sent as the very first frame by a CLI client. The server responds with DaemonHelloResponse before the JSON-RPC request loop begins.
DaemonHelloResponse
Server’s reply to DaemonHello. If compatible is false the server closes the connection immediately after the frame is sent.
JsonRpcError
JSON-RPC 2.0 error payload.
JsonRpcRequest
JSON-RPC 2.0 request.
JsonRpcResponse
JSON-RPC 2.0 response. id is Option<JsonRpcId> with no skip_serializing_if — the None case serialises as JSON null, which is exactly what the spec demands for parse-error and invalid-request responses.
JsonRpcVersion
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.
RebuildResult
daemon/rebuild success result payload (schema_version 2 — see cluster-G §2.4).
ResponseEnvelope
Uniform successful-response wrapper. Every successful method response is serialised as ResponseEnvelope<T> at the JSON-RPC result field — clients can rely on the ResponseMeta shape being present on every successful reply regardless of method.
ResponseMeta
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-side ServeVerdict for tool-method responses.

Enums§

JsonRpcId
JSON-RPC id: null, integer (signed or unsigned), or string. I64 covers i64::MIN..=i64::MAX; U64 covers i64::MAX + 1..=u64::MAX. Serde’s untagged deserialize tries variants in order so 0..=i64::MAX lands in I64 and i64::MAX + 1..=u64::MAX in U64.
JsonRpcPayload
Tagged success-or-error payload. Serde untagged so the wire form is {... "result": ...} or {... "error": ...}, never both.
WorkspaceState
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_adapter tool execution that don’t map to a more specific DaemonError variant.
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 kind is always "query_too_broad". Reuses -32602 per the existing wire-bridge convention; kind is the discriminator (per B_cost_gate.md §3 “Why -32602, not a new -32xxx code”).
JSONRPC_RESET_CANCELLATION_DISPATCHED
JSON-RPC error code: daemon/reset was invoked on a workspace whose state is Rebuilding; cancellation has been dispatched and the caller is expected to retry after retry_after_ms for the state to settle into Failed / Unloaded (then a follow-up reset completes).
JSONRPC_RESET_WHILE_LOADING
JSON-RPC error code: daemon/reset was invoked on a workspace whose state is Loading and 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::bind so the failure mode is a precise diagnostic instead of a generic EACCES from the eventual bind.
JSONRPC_TOOL_TIMEOUT
JSON-RPC error code: per-tool invocation exceeded DaemonConfig::tool_timeout_secs. Emitted by tool_core::classify_and_execute (Task 8 Phase 8c U6) when the tokio::time::timeout(tool_timeout, spawn_blocking(run)) outer timer fires. The detached JoinHandle is 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 fresh get_or_load first.
JSONRPC_WORKSPACE_INCOMPATIBLE_GRAPH
JSON-RPC error code: the on-disk graph snapshot or manifest cannot be loaded safely by this binary. Distinct from WorkspaceBuildFailed because 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/reset refused because the targeted workspace is pinned and the caller did not pass force = 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.