sail_api/runtime.rs
1//! Version-one exact SMT runtime requests and attributed responses.
2
3use serde::{Deserialize, Serialize};
4
5/// Private local runtime transport, independent of cache and project-job RPC.
6#[cfg(unix)]
7pub mod transport;
8
9/// Public runtime protocol version.
10pub const VERSION: u32 = 1;
11/// Maximum number of independently executed queries in one request.
12pub const MAX_QUERIES: usize = 64;
13/// Maximum total admitted script bytes.
14pub const MAX_INPUT_BYTES: usize = 16 * 1024 * 1024;
15/// Maximum retained bytes in each output stream of one query.
16pub const MAX_OUTPUT_BYTES: usize = 16 * 1024 * 1024;
17/// Aggregate stdout, stderr and duplicated product byte budget for one batch.
18pub const MAX_RETAINED_OUTPUT_BYTES: usize = 128 * 1024 * 1024;
19/// Maximum per-query process safety deadline.
20pub const MAX_WALL_TIME_MS: u64 = 300_000;
21
22/// One versioned runtime invocation.
23#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(deny_unknown_fields)]
25pub struct Request {
26 /// Must equal [`VERSION`].
27 pub version: u32,
28 /// Explicit input family.
29 pub input: Input,
30}
31
32/// Implemented runtime input families.
33#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
34#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
35pub enum Input {
36 /// One attributed native temporal job.
37 Temporal {
38 /// Immutable payload and bounded deadline.
39 job: Box<crate::temporal::Job>,
40 },
41 /// Independent complete SMT transcripts, in caller order.
42 Smt {
43 /// Bounded independent queries.
44 queries: Vec<Query>,
45 },
46}
47
48/// One complete SMT-LIB transcript.
49#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
50#[serde(deny_unknown_fields)]
51pub struct Query {
52 /// Stable, nonempty identity chosen by the caller.
53 pub obligation_id: String,
54 /// Strictly sorted, unique nonempty requirement identities.
55 pub requirement_ids: Vec<String>,
56 /// Requested solver family; capabilities report its current availability.
57 pub backend: String,
58 /// Exact unmodified UTF-8 SMT-LIB input.
59 pub script: String,
60 /// Execution limits, independent of solver answers.
61 #[serde(default)]
62 pub limits: Limits,
63}
64
65/// Bounded process execution and deterministic solver effort.
66#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
67#[serde(deny_unknown_fields)]
68pub struct Limits {
69 /// Backend-specific resource units per check; zero is deliberately not admitted.
70 pub resource_limit: u64,
71 /// Whole-process safety deadline in milliseconds.
72 pub wall_time_ms: u64,
73 /// Maximum exact input bytes for this query.
74 pub input_bytes: usize,
75 /// Maximum bytes retained from each output stream.
76 pub output_bytes: usize,
77}
78
79impl Default for Limits {
80 fn default() -> Self {
81 Self {
82 resource_limit: 2_000_000,
83 wall_time_ms: 30_000,
84 input_bytes: MAX_INPUT_BYTES,
85 output_bytes: MAX_OUTPUT_BYTES,
86 }
87 }
88}
89
90/// A complete versioned invocation response.
91#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
92pub struct Response {
93 /// Equals [`VERSION`].
94 pub version: u32,
95 /// Explicit result family.
96 pub output: Output,
97}
98
99/// Runtime outputs, sharing the request-family discriminator.
100#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
101#[serde(tag = "kind", rename_all = "snake_case")]
102pub enum Output {
103 /// One native temporal execution, including original evidence.
104 Temporal {
105 /// Exact caller attribution and separate execution/native outcomes.
106 result: Box<crate::temporal::Result>,
107 },
108 /// Query results in original caller order.
109 Smt {
110 /// One result for every admitted query.
111 results: Vec<QueryResult>,
112 },
113}
114
115/// Solver answers are separate from process outcomes and proposition validity.
116#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
117#[serde(rename_all = "snake_case")]
118pub enum Answer {
119 /// A satisfying assignment exists.
120 Sat,
121 /// No satisfying assignment exists.
122 Unsat,
123 /// The solver did not decide.
124 Unknown,
125}
126
127/// Whole-transcript execution outcome.
128#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
129#[serde(rename_all = "snake_case")]
130pub enum Outcome {
131 /// Every expected response was validated; checks may still be unknown.
132 Completed,
133 /// Requested backend or exact pinned executable is unavailable.
134 Unavailable,
135 /// Process safety deadline expired without a valid transcript.
136 Timeout,
137 /// Explicit caller cancellation stopped execution.
138 Cancelled,
139 /// An output stream exceeded its retained-byte bound.
140 OutputLimit,
141 /// Process or response integrity failed.
142 Infrastructure,
143}
144
145/// One check and its explicitly requested products.
146#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
147pub struct Check {
148 /// Zero-based index among original top-level commands.
149 pub command_index: usize,
150 /// Raw satisfiability answer.
151 pub answer: Answer,
152 /// Products belonging to this check, in command order.
153 pub products: Vec<Product>,
154}
155
156/// Requested response product.
157#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
158pub struct Product {
159 /// Zero-based original command index.
160 pub command_index: usize,
161 /// Product interpretation.
162 pub kind: ProductKind,
163 /// Exact response expression bytes; complete stdout remains alongside it.
164 pub raw: Vec<u8>,
165}
166
167/// Explicitly supported solver response products.
168#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
169#[serde(rename_all = "snake_case")]
170pub enum ProductKind {
171 /// A satisfying model.
172 Model,
173 /// Values for the requested terms.
174 Values,
175 /// Named assertions forming an unsatisfiable core.
176 UnsatCore,
177 /// Solver's reason for its unknown answer.
178 ReasonUnknown,
179}
180
181/// Exact executable establishing solver responses.
182#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
183pub struct SolverIdentity {
184 /// Explicit solver family.
185 pub backend: String,
186 /// Exact admitted version.
187 pub version: String,
188 /// SHA-256 of executable bytes.
189 pub sha256: String,
190 /// OS and architecture class.
191 pub platform: String,
192}
193
194/// One attributed transcript result.
195#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
196pub struct QueryResult {
197 /// Caller identity, preserved exactly.
198 pub obligation_id: String,
199 /// Caller requirement identities, preserved exactly.
200 pub requirement_ids: Vec<String>,
201 /// Requested backend, preserved even when unavailable.
202 pub backend: String,
203 /// Process outcome; never inferred from a partial output prefix.
204 pub outcome: Outcome,
205 /// Empty unless the complete response plan was validated.
206 pub checks: Vec<Check>,
207 /// Exact bounded standard output bytes.
208 pub stdout: Vec<u8>,
209 /// Exact bounded standard error bytes.
210 pub stderr: Vec<u8>,
211 /// Present only after actual executable identity verification.
212 pub solver: Option<SolverIdentity>,
213 /// Content identity of the exact script.
214 pub script_sha256: String,
215 /// Effective admitted limits.
216 pub limits: Limits,
217 /// True only when complete original solver evidence was reused.
218 pub cache_hit: bool,
219 /// Explicit failure diagnostic, absent for completed transcripts.
220 pub error: Option<Error>,
221}
222
223/// Versioned runtime capabilities; readiness is not a theorem verdict.
224#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
225pub struct Capabilities {
226 /// Native temporal readiness; absent on older SMT-only services.
227 #[serde(default, skip_serializing_if = "Option::is_none")]
228 pub temporal: Option<crate::temporal::Capability>,
229 /// Equals [`VERSION`].
230 pub version: u32,
231 /// Backends implemented by this build.
232 pub backends: Vec<BackendCapability>,
233 /// Complete transcripts support push/pop and multiple checks.
234 pub incremental_transcripts: bool,
235 /// Bounded independent-query submission is implemented.
236 pub batches: bool,
237 /// Maximum query count.
238 pub max_queries: usize,
239}
240
241/// Implementation and actual installation are separate facts.
242#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
243pub struct BackendCapability {
244 /// Backend family.
245 pub backend: String,
246 /// Backend code is implemented.
247 pub implemented: bool,
248 /// Exact usable pinned executable was verified.
249 pub installed: bool,
250 /// Actual verified identity, when available.
251 pub solver: Option<SolverIdentity>,
252 /// Explicit unavailability diagnostic.
253 pub error: Option<Error>,
254}
255
256/// Stable machine-readable error with a human diagnostic.
257#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
258pub struct Error {
259 /// Stable `SAIL6101` admission or `SAIL6102` execution code.
260 pub code: String,
261 /// Stable specific category such as `invalid_request` or `unsupported_command`.
262 pub kind: String,
263 /// Actionable diagnostic.
264 pub message: String,
265}
266
267impl std::fmt::Display for Error {
268 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
269 write!(f, "error[{}]: {}: {}", self.code, self.kind, self.message)
270 }
271}
272
273impl std::error::Error for Error {}