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 / swarm_inspect_scoping_test.rs

124 lines · 4176 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//! Integration test: InspectSwarm reports the requested swarm, not runtime-wide totals.
17
18use aien_inference_abi::MockInferenceBackend;
19use aien_kv_cache::create_shared_kv_manager;
20use aien_runtime::control::{
21 ControlCommand, ControlEnvelope, ControlResponse, LaunchSwarmReq, RuntimeStatusReport,
22};
23use aien_runtime::spine::AienRuntimeSpine;
24use aien_scheduler::SchedulerConfig;
25
26fn envelope(operation_id: u64, command: ControlCommand) -> ControlEnvelope {
27 ControlEnvelope {
28 protocol_version: 1,
29 request_id: operation_id,
30 operation_id: operation_id.into(),
31 operator_session: 1,
32 command,
33 }
34}
35
36fn launch(spine: &mut AienRuntimeSpine, operation_id: u64, branch_count: usize) -> u64 {
37 let req = LaunchSwarmReq {
38 model_handle: 1,
39 branch_count,
40 max_active_sequences: 8,
41 max_tokens_per_branch: 4,
42 root_world_id: 0,
43 priority: 1,
44 prompt_tokens: vec![1, 2, 3],
45 };
46 match spine.handle_control_command(envelope(operation_id, ControlCommand::LaunchSwarm(req))) {
47 ControlResponse::SwarmAccepted { swarm_id, .. } => swarm_id,
48 other => panic!("launch failed: {:?}", other),
49 }
50}
51
52fn inspect(spine: &mut AienRuntimeSpine, operation_id: u64, swarm_id: u64) -> ControlResponse {
53 spine.handle_control_command(envelope(
54 operation_id,
55 ControlCommand::InspectSwarm(swarm_id),
56 ))
57}
58
59fn status(resp: ControlResponse) -> RuntimeStatusReport {
60 match resp {
61 ControlResponse::Status(report) => report,
62 other => panic!("expected Status, got {:?}", other),
63 }
64}
65
66#[tokio::test]
67async fn inspect_swarm_is_scoped_to_the_requested_swarm() {
68 let state_dir = std::env::temp_dir().join(format!("aien-swarm-inspect-{}", std::process::id()));
69 let _ = std::fs::create_dir_all(&state_dir);
70 std::env::set_var("AIEN_RUNTIME_STATE_DIR", &state_dir);
71
72 let scheduler_config = SchedulerConfig {
73 max_batch_size: 64,
74 max_batch_tokens: 4096,
75 prefill_chunk_size: 64,
76 watermark_blocks: 16,
77 chunk_prefill: true,
78 max_prefill_tokens: 4096,
79 };
80 let mut spine =
81 AienRuntimeSpine::new(1024, scheduler_config, create_shared_kv_manager(1024, 16));
82
83 let small = launch(&mut spine, 1, 2);
84 let large = launch(&mut spine, 2, 5);
85
86 let small_status = status(inspect(&mut spine, 3, small));
87 let large_status = status(inspect(&mut spine, 4, large));
88 assert_eq!(
89 small_status.active_sequences, 2,
90 "only this swarm's branches"
91 );
92 assert_eq!(
93 large_status.active_sequences, 5,
94 "only this swarm's branches"
95 );
96 assert_eq!(small_status.active_swarms, 1);
97 assert_eq!(small_status.active_worlds, 2, "one live world per branch");
98 assert!(
99 spine.status_report().active_sequences > small_status.active_sequences,
100 "runtime-wide count must exceed a single swarm's count"
101 );
102
103 let mut backend = MockInferenceBackend::new(1);
104 spine
105 .run_until_complete(&mut backend, 200)
106 .await
107 .expect("run_until_complete");
108
109 let done = status(inspect(&mut spine, 5, small));
110 assert_eq!(
111 done.active_sequences, 0,
112 "completed swarm has no active branches"
113 );
114 assert_eq!(done.active_swarms, 0);
115 assert_eq!(
116 done.active_worlds, 0,
117 "branch worlds are dropped on completion"
118 );
119
120 assert!(matches!(
121 inspect(&mut spine, 6, 999),
122 ControlResponse::Error(_)
123 ));
124}