stateknot_runtime/agent_service/readiness.rs
1// Copyright 2026 StateKnot contributors
2// SPDX-License-Identifier: Apache-2.0
3
4use super::AgentServiceV1;
5use thiserror::Error;
6
7/// Closed dependency-readiness failure; contains no database or deployment details.
8#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
9#[non_exhaustive]
10pub enum AgentServiceReadinessError {
11 /// No public Agent is installed, or an exact executable binding is unavailable.
12 #[error("Agent service deployment is unavailable")]
13 DeploymentUnavailable,
14 /// The actual service pool cannot verify its required `PostgreSQL` schema.
15 #[error("Agent service storage is unavailable")]
16 StorageUnavailable,
17}
18
19impl AgentServiceV1 {
20 /// Checks frozen Agent/executable bindings and the actual store's schema.
21 ///
22 /// Read-only and unauthenticated: this is a trusted host operation, not a
23 /// business endpoint. Does not call initial-state factories, policy decisions,
24 /// or executors. The host must separately check identity/policy dependencies,
25 /// bound this future, and qualify database role privileges before deployment.
26 /// Readiness is an observation, not a guarantee of future request success.
27 ///
28 /// # Errors
29 ///
30 /// Rejects empty/drifted/missing executable deployments or unavailable schema.
31 pub async fn check_readiness(&self) -> Result<(), AgentServiceReadinessError> {
32 if self.deployments.is_empty() {
33 return Err(AgentServiceReadinessError::DeploymentUnavailable);
34 }
35 for identity in self.deployments.bindings.keys() {
36 let binding = self
37 .deployments
38 .resolve(identity)
39 .map_err(|_| AgentServiceReadinessError::DeploymentUnavailable)?;
40 let executable = self
41 .runs
42 .executable_registry()
43 .resolve(&binding.graph)
44 .ok_or(AgentServiceReadinessError::DeploymentUnavailable)?;
45 if executable.graph().input_schema() != binding.descriptor.input_schema()
46 || executable.graph().output_schema() != binding.descriptor.output_schema()
47 {
48 return Err(AgentServiceReadinessError::DeploymentUnavailable);
49 }
50 }
51 self.store
52 .verify_schema()
53 .await
54 .map_err(|_| AgentServiceReadinessError::StorageUnavailable)
55 }
56}