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 / runtime_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 | //! Integration test for AienRuntimeServer and AienRuntimeClient over local UNIX domain socket. |
| 17 | |
| 18 | use aien_inference_abi::MockInferenceBackend; |
| 19 | use aien_kv_cache::create_shared_kv_manager; |
| 20 | use aien_runtime::client::AienRuntimeClient; |
| 21 | use aien_runtime::control::LaunchSwarmReq; |
| 22 | use aien_runtime::server::AienRuntimeServer; |
| 23 | use aien_runtime::spine::AienRuntimeSpine; |
| 24 | use aien_scheduler::SchedulerConfig; |
| 25 | use std::time::Duration; |
| 26 | use tempfile::TempDir; |
| 27 | |
| 28 | #[tokio::test] |
| 29 | async fn test_runtime_server_client_ipc_lifecycle() { |
| 30 | let temp_dir = TempDir::new().expect("Failed to create tempdir"); |
| 31 | let socket_path = temp_dir.path().join("runtime.sock"); |
| 32 | // sc#328: the daemon refuses to start without the (default) desk key. |
| 33 | std::env::set_var("AIEN_COMPOSE_DIR", temp_dir.path().join("compose")); |
| 34 | aien_runtime::approved_auth::DeskKey::create(&aien_runtime::approved_auth::desk_key_path( |
| 35 | &temp_dir.path().join("compose"), |
| 36 | )) |
| 37 | .unwrap(); |
| 38 | |
| 39 | let kv_manager = create_shared_kv_manager(1024, 16); |
| 40 | let scheduler_config = SchedulerConfig { |
| 41 | max_batch_size: 64, |
| 42 | max_batch_tokens: 4096, |
| 43 | prefill_chunk_size: 64, |
| 44 | watermark_blocks: 16, |
| 45 | chunk_prefill: true, |
| 46 | max_prefill_tokens: 4096, |
| 47 | }; |
| 48 | |
| 49 | let spine = AienRuntimeSpine::new(1024, scheduler_config, kv_manager); |
| 50 | let server = AienRuntimeServer::new(spine, &socket_path); |
| 51 | |
| 52 | // Run server in background task |
| 53 | let server_handle = tokio::spawn(async move { |
| 54 | let backend = MockInferenceBackend::new(1); |
| 55 | server.run(backend).await |
| 56 | }); |
| 57 | |
| 58 | // Wait for server to bind socket |
| 59 | let client = AienRuntimeClient::new(&socket_path); |
| 60 | let mut alive = false; |
| 61 | for _ in 0..50 { |
| 62 | if client.is_alive().await { |
| 63 | alive = true; |
| 64 | break; |
| 65 | } |
| 66 | tokio::time::sleep(Duration::from_millis(20)).await; |
| 67 | } |
| 68 | assert!(alive, "Runtime server failed to bind and become alive"); |
| 69 | |
| 70 | // 1. Initial status query |
| 71 | let initial_status = client.get_status().await.expect("Failed to get status"); |
| 72 | assert_eq!(initial_status.active_sequences, 0); |
| 73 | assert_eq!(initial_status.active_swarms, 0); |
| 74 | |
| 75 | // 2. Launch swarm over socket IPC |
| 76 | let prompt_tokens: Vec<u32> = (1..=32).collect(); |
| 77 | let launch_req = LaunchSwarmReq { |
| 78 | model_handle: 1, |
| 79 | branch_count: 8, |
| 80 | max_active_sequences: 8, |
| 81 | max_tokens_per_branch: 8, |
| 82 | root_world_id: 0, |
| 83 | priority: 1, |
| 84 | prompt_tokens, |
| 85 | }; |
| 86 | |
| 87 | let swarm_id = client |
| 88 | .launch_swarm(launch_req) |
| 89 | .await |
| 90 | .expect("Failed to launch swarm over IPC"); |
| 91 | assert_eq!(swarm_id, 1); |
| 92 | |
| 93 | // 3. Allow background engine worker to execute branch steps |
| 94 | let mut completed = false; |
| 95 | for _ in 0..100 { |
| 96 | let status = client.get_status().await.expect("Failed to query status"); |
| 97 | // Root sequence remains as context anchor, child branches finish |
| 98 | if status.active_sequences <= 1 { |
| 99 | completed = true; |
| 100 | break; |
| 101 | } |
| 102 | tokio::time::sleep(Duration::from_millis(20)).await; |
| 103 | } |
| 104 | assert!(completed, "Swarm branches did not complete within budget"); |
| 105 | |
| 106 | // 4. Shutdown server cleanly over IPC |
| 107 | client |
| 108 | .shutdown() |
| 109 | .await |
| 110 | .expect("Failed to send shutdown command"); |
| 111 | |
| 112 | server_handle |
| 113 | .await |
| 114 | .expect("Server task panicked") |
| 115 | .expect("Server exited with error"); |
| 116 | assert_eq!((), ()); |
| 117 | |
| 118 | // Verify socket file was cleaned up on clean exit |
| 119 | assert!( |
| 120 | !socket_path.exists(), |
| 121 | "Socket file should be unlinked after shutdown" |
| 122 | ); |
| 123 | } |