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 / swarm_completion_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: swarm lifecycle through the spine with a mock backend. |
| 17 | //! Natural completion must reclaim the root sequence and all branch worlds. |
| 18 | |
| 19 | use aien_inference_abi::MockInferenceBackend; |
| 20 | use aien_kv_cache::create_shared_kv_manager; |
| 21 | use aien_runtime::control::LaunchSwarmReq; |
| 22 | use aien_runtime::spine::AienRuntimeSpine; |
| 23 | use aien_scheduler::SchedulerConfig; |
| 24 | |
| 25 | #[tokio::test] |
| 26 | async fn swarm_natural_completion_reclaims_everything() { |
| 27 | let state_dir = std::env::temp_dir().join(format!("aien-swarm-test-{}", std::process::id())); |
| 28 | let _ = std::fs::create_dir_all(&state_dir); |
| 29 | std::env::set_var("AIEN_RUNTIME_STATE_DIR", &state_dir); |
| 30 | |
| 31 | let kv_manager = create_shared_kv_manager(1024, 16); |
| 32 | let scheduler_config = SchedulerConfig { |
| 33 | max_batch_size: 64, |
| 34 | max_batch_tokens: 4096, |
| 35 | prefill_chunk_size: 64, |
| 36 | watermark_blocks: 16, |
| 37 | chunk_prefill: true, |
| 38 | max_prefill_tokens: 4096, |
| 39 | }; |
| 40 | let mut spine = AienRuntimeSpine::new(1024, scheduler_config, kv_manager); |
| 41 | |
| 42 | let launch = LaunchSwarmReq { |
| 43 | model_handle: 1, |
| 44 | branch_count: 4, |
| 45 | max_active_sequences: 8, |
| 46 | max_tokens_per_branch: 4, |
| 47 | root_world_id: 0, |
| 48 | priority: 1, |
| 49 | prompt_tokens: vec![1, 2, 3], |
| 50 | }; |
| 51 | let swarm_id = spine.handle_control_command(aien_runtime::control::ControlEnvelope { |
| 52 | protocol_version: 1, |
| 53 | request_id: 1, |
| 54 | operation_id: 100, |
| 55 | operator_session: 1, |
| 56 | command: aien_runtime::control::ControlCommand::LaunchSwarm(launch), |
| 57 | }); |
| 58 | println!("launch response: {:?}", swarm_id); |
| 59 | |
| 60 | let mut backend = MockInferenceBackend::new(1); |
| 61 | let metrics = spine |
| 62 | .run_until_complete(&mut backend, 200) |
| 63 | .await |
| 64 | .expect("run_until_complete"); |
| 65 | println!("steps executed: {}", metrics.len()); |
| 66 | |
| 67 | let status = spine.status_report(); |
| 68 | println!( |
| 69 | "final: active_sequences={} active_swarms={} active_worlds={} cow_faults={}", |
| 70 | status.active_sequences, status.active_swarms, status.active_worlds, status.cow_faults |
| 71 | ); |
| 72 | |
| 73 | assert_eq!( |
| 74 | status.active_sequences, 0, |
| 75 | "root sequence must be reclaimed after branches finish" |
| 76 | ); |
| 77 | assert_eq!(status.active_swarms, 0, "swarm must reach Completed"); |
| 78 | assert_eq!( |
| 79 | status.active_worlds, 1, |
| 80 | "branch worlds must drop; only the swarm root world remains" |
| 81 | ); |
| 82 | } |