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
aien-sovereign-core-mv / crates / aien-runtime / tests / compose_task_ipc_test.rs
| 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 | //! NEXT-PHASE-1 cut 1b: RunComposeTask over the runtime socket. No tokenizer |
| 17 | //! is loaded, so the real "model" Skill (the StreamTurn inference path) |
| 18 | //! fails and nothing commits: this proves the routing, the blocking hand-off |
| 19 | //! and the result record, not the model. |
| 20 | #[path = "support/home_guard.rs"] |
| 21 | mod home_guard; |
| 22 | |
| 23 | use aien_inference_abi::MockInferenceBackend; |
| 24 | use aien_kv_cache::create_shared_kv_manager; |
| 25 | use aien_runtime::client::AienRuntimeClient; |
| 26 | use aien_runtime::control::{ControlCommand, ControlResponse}; |
| 27 | use aien_runtime::server::AienRuntimeServer; |
| 28 | use aien_runtime::spine::AienRuntimeSpine; |
| 29 | use aien_scheduler::SchedulerConfig; |
| 30 | use std::time::Duration; |
| 31 | |
| 32 | #[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 33 | async fn run_compose_task_over_socket() { |
| 34 | let _home = home_guard::home_slot(); |
| 35 | let tmp = tempfile::tempdir().unwrap(); |
| 36 | // Only this test binary sets it; one test per binary avoids env races. |
| 37 | std::env::set_var("AIEN_COMPOSE_DIR", tmp.path().join("compose")); |
| 38 | // sc#328: the daemon refuses to start without the (default) desk key. |
| 39 | aien_runtime::approved_auth::DeskKey::create(&aien_runtime::approved_auth::desk_key_path( |
| 40 | &tmp.path().join("compose"), |
| 41 | )) |
| 42 | .unwrap(); |
| 43 | let ws = tmp.path().join("ws"); |
| 44 | std::fs::create_dir_all(&ws).unwrap(); |
| 45 | let socket = tmp.path().join("runtime.sock"); |
| 46 | let cfg = SchedulerConfig { |
| 47 | max_batch_size: 8, |
| 48 | max_batch_tokens: 1024, |
| 49 | prefill_chunk_size: 64, |
| 50 | watermark_blocks: 4, |
| 51 | chunk_prefill: true, |
| 52 | max_prefill_tokens: 1024, |
| 53 | }; |
| 54 | let spine = AienRuntimeSpine::new(64, cfg, create_shared_kv_manager(256, 16)); |
| 55 | let server = AienRuntimeServer::new(spine, &socket); |
| 56 | let handle = tokio::spawn(async move { server.run(MockInferenceBackend::new(1)).await }); |
| 57 | let client = AienRuntimeClient::new(&socket); |
| 58 | let mut alive = false; |
| 59 | for _ in 0..100 { |
| 60 | if client.is_alive().await { |
| 61 | alive = true; |
| 62 | break; |
| 63 | } |
| 64 | tokio::time::sleep(Duration::from_millis(20)).await; |
| 65 | } |
| 66 | assert!(alive); |
| 67 | |
| 68 | let resp = client |
| 69 | .send_command(ControlCommand::RunComposeTask { |
| 70 | context: None, |
| 71 | goal: "propose one change".into(), |
| 72 | workspace: ws.to_str().unwrap().into(), |
| 73 | }) |
| 74 | .await |
| 75 | .unwrap(); |
| 76 | match resp { |
| 77 | ControlResponse::ComposeTaskResult(r) => { |
| 78 | if !aien_omega_compose::LINKED { |
| 79 | panic!("stub build returned a compose result"); |
| 80 | } |
| 81 | assert!( |
| 82 | !r.committed, |
| 83 | "no tokenizer: the model Skill must fail, {r:?}" |
| 84 | ); |
| 85 | assert_eq!(r.proposal, None); |
| 86 | assert_eq!(r.proposer, "model:StreamTurn-path"); |
| 87 | assert_eq!(r.branch_count, 1); |
| 88 | } |
| 89 | ControlResponse::Error(e) => { |
| 90 | if aien_omega_compose::LINKED { |
| 91 | panic!("linked build returned {e}"); |
| 92 | } |
| 93 | assert!(e.contains("not linked"), "{e}"); |
| 94 | } |
| 95 | other => panic!("unexpected {other:?}"), |
| 96 | } |
| 97 | // cut 2: a host note and its recall over the same socket. |
| 98 | let noted = client |
| 99 | .send_command(ControlCommand::ComposeNote { |
| 100 | kind: "constraint".into(), |
| 101 | text: "only the workspace".into(), |
| 102 | links: vec![], |
| 103 | }) |
| 104 | .await |
| 105 | .unwrap(); |
| 106 | match (noted, aien_omega_compose::LINKED) { |
| 107 | (ControlResponse::ComposeNoted(n), true) => { |
| 108 | let back = client |
| 109 | .send_command(ControlCommand::ComposeRecall { |
| 110 | ids: vec![n.id], |
| 111 | prefix: Some(n.id), |
| 112 | }) |
| 113 | .await |
| 114 | .unwrap(); |
| 115 | match back { |
| 116 | ControlResponse::ComposeRecalled(r) => { |
| 117 | assert_eq!(r.machine_id, n.machine_id); |
| 118 | assert_eq!(r.cited.len(), 1); |
| 119 | assert_eq!(r.cited[0].digest, n.digest); |
| 120 | assert_eq!(r.cited[0].text.as_deref(), Some("only the workspace")); |
| 121 | assert!(r.prefix_digest.is_some()); |
| 122 | } |
| 123 | other => panic!("recall: {other:?}"), |
| 124 | } |
| 125 | } |
| 126 | (ControlResponse::Error(e), false) => assert!(e.contains("not linked"), "{e}"), |
| 127 | (other, linked) => panic!("note (linked {linked}): {other:?}"), |
| 128 | } |
| 129 | let _ = client.send_command(ControlCommand::Shutdown).await; |
| 130 | let _ = tokio::time::timeout(Duration::from_secs(5), handle).await; |
| 131 | } |