interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-runtime / tests / requirements_deadline_test.rs

108 lines · 4265 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! A document task whose first attempt fails a stated requirement and whose
17//! second attempt passes: both attempts happen inside the ONE per-task document
18//! deadline (a short injected budget), and the bytes saved are the bytes approved.
19//! Own test binary: it sets a process-global environment variable.
20//!
21//! Driven through `ComposeBridge::run_task` (tests/support/compose_harness.rs):
22//! the limits handed to the document proposer, the attempts and the report.
23#[path = "support/compose_harness.rs"]
24mod compose_harness;
25#[path = "support/home_guard.rs"]
26mod home_guard;
27
28use aien_runtime::check_file_proposal;
29use aien_runtime::compose::compose_budgets_from_env;
30use aien_runtime::requirements::extract;
31use compose_harness::{reply, Asked, Harness};
32use std::sync::Arc;
33use std::time::{Duration, Instant};
34
35const DOC_BUDGET_ENV: &str = "AIEN_COMPOSE_DOC_BUDGET_MS";
36
37fn doc(n: usize) -> String {
38 let mut s = String::from("filename: DOC.md\n");
39 for i in 0..n {
40 s.push_str(&format!("line {i}\n"));
41 }
42 s
43}
44
45/// Clears the budget variable when dropped (also on a failed assertion).
46struct DocBudget;
47
48impl Drop for DocBudget {
49 fn drop(&mut self) {
50 std::env::remove_var(DOC_BUDGET_ENV);
51 }
52}
53
54#[test]
55#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
56fn requirement_retry_stays_inside_the_single_document_deadline_and_saves_approved_bytes() {
57 let _home = home_guard::home_slot();
58 std::env::set_var(DOC_BUDGET_ENV, "6000");
59 let _clear = DocBudget;
60 let budget = compose_budgets_from_env().unwrap().doc;
61 assert_eq!(budget, Duration::from_millis(6000));
62 // The per-attempt budget of this document task: min(30 s, 6 s / 2) = 3 s.
63 let reqs = extract("write DOC.md in at least 20 lines");
64 assert_eq!(reqs.len(), 1);
65
66 // The bridge reads the budget when it opens its home, at the first run.
67 let h = Harness::new(Arc::new(|n, _: &str, _: Duration| {
68 std::thread::sleep(Duration::from_millis(300));
69 // First attempt: 5 lines (unmet). Second: 25 lines.
70 reply(&doc(if n == 1 { 5 } else { 25 }))
71 }));
72 let t0 = Instant::now();
73 let r = h.run("write DOC.md in at least 20 lines").unwrap();
74 assert!(t0.elapsed() < budget, "both attempts inside one deadline");
75
76 // The shared deadline, observed from the document proposer.
77 let c = h.calls();
78 assert!(c.iter().all(|c| c.asked == Asked::Document), "{c:?}");
79 let limits: Vec<Duration> = c.iter().map(|c| c.limit).collect();
80 assert_eq!(limits.len(), 2);
81 assert!(limits[0] <= budget, "{limits:?}");
82 assert!(
83 limits[1] < limits[0],
84 "retry gets what is left, not a fresh budget: {limits:?}"
85 );
86 // Attempt 2 started, so at least the 3 s per-attempt budget was left.
87 assert!(limits[1] >= Duration::from_secs(3), "{limits:?}");
88 let attempts = &r.proposal_attempts;
89 assert_eq!(attempts.len(), 2);
90 assert_eq!(attempts[0].outcome, "refused");
91 assert_eq!(attempts[0].unmet_requirements.len(), 1);
92 assert_eq!(attempts[1].outcome, "parsed");
93
94 // The real run: committed, saved == approved.
95 assert!(r.committed, "{r:?}");
96 assert_eq!(attempts[1].aegis.as_deref(), Some("pass"));
97 let saved = check_file_proposal(&r.proposal.clone().unwrap()).unwrap();
98 assert_eq!(
99 r.proposal_content_sha256.clone().unwrap(),
100 aien_omega_compose::hex(&<sha2::Sha256 as sha2::Digest>::digest(
101 saved.content.as_bytes()
102 ))
103 );
104 assert_eq!(
105 saved.content,
106 doc(25).strip_prefix("filename: DOC.md\n").unwrap()
107 );
108}