From 2810b8a01d0c4aab6358b35b121df810f153155d Mon Sep 17 00:00:00 2001 From: AIEN Atlas Date: Tue, 22 Sep 2026 09:35:50 -0500 Subject: [PATCH 1/2] fix(cli): explicit native-first chat backend with remote adapter fallback Adds ChatBackend enum and resolve_chat_backend. Native runtime socket is canonical when present. 18006 stays only as explicit compatibility adapter. AIEN_CHAT_BACKEND overrides. Each turn logs the active path. Co-authored-by: Drake Stapleton --- crates/aien-cli/src/client.rs | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/crates/aien-cli/src/client.rs b/crates/aien-cli/src/client.rs index fbe8cf7b..32b2a4b6 100644 --- a/crates/aien-cli/src/client.rs +++ b/crates/aien-cli/src/client.rs @@ -8,6 +8,48 @@ use std::time::Duration; pub const DEFAULT_ENDPOINT: &str = "http://127.0.0.1:18006/v1/chat/completions"; pub const DEFAULT_MODEL: &str = "atlas-lightning-omni"; +/// Explicit chat execution path. Native runtime is canonical. +/// The 18006 HTTP service remains only as a compatibility adapter. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ChatBackend { + NativeRuntime, + RemoteAdapter(String), +} + +pub fn resolve_chat_backend() -> ChatBackend { + if let Ok(mode) = std::env::var("AIEN_CHAT_BACKEND") { + let mode = mode.trim().to_lowercase(); + if mode == "remote" { + let ep = std::env::var("AIEN_MODEL_ENDPOINT") + .ok() + .filter(|s| !s.trim().is_empty()) + .unwrap_or_else(|| DEFAULT_ENDPOINT.to_string()); + return ChatBackend::RemoteAdapter(ep); + } + if mode == "native" { + return ChatBackend::NativeRuntime; + } + } + let sock = aien_runtime::client::AienRuntimeClient::default_socket_path(); + if sock.exists() { + ChatBackend::NativeRuntime + } else { + ChatBackend::RemoteAdapter( + std::env::var("AIEN_MODEL_ENDPOINT") + .ok() + .filter(|s| !s.trim().is_empty()) + .unwrap_or_else(|| DEFAULT_ENDPOINT.to_string()), + ) + } +} + +pub fn describe_chat_backend(backend: &ChatBackend) -> String { + match backend { + ChatBackend::NativeRuntime => "native runtime (canonical)".to_string(), + ChatBackend::RemoteAdapter(ep) => format!("remote adapter (compatibility): {}", ep), + } +} + pub fn get_system_prompt() -> String { let mut p = String::from("You are AIEN. Drake is the operator. This Spark desk is ours.\n"); p.push_str("You are an autonomous operator-builder running on NVIDIA DGX Spark Grace Blackwell GB10 hardware.\n"); @@ -91,16 +133,23 @@ pub struct ChatClient { client: Client, endpoint: String, model: String, + backend: ChatBackend, } impl ChatClient { pub fn new(endpoint: Option, model: Option) -> Self { + let explicit_endpoint = endpoint.is_some(); let ep = endpoint .or_else(|| std::env::var("AIEN_MODEL_ENDPOINT").ok()) .unwrap_or_else(|| DEFAULT_ENDPOINT.to_string()); let md = model .or_else(|| std::env::var("AIEN_MODEL_NAME").ok()) .unwrap_or_else(|| DEFAULT_MODEL.to_string()); + let backend = if explicit_endpoint { + ChatBackend::RemoteAdapter(ep.clone()) + } else { + resolve_chat_backend() + }; let client = Client::builder() .connect_timeout(Duration::from_secs(10)) .read_timeout(Duration::from_secs(120)) @@ -110,6 +159,7 @@ impl ChatClient { client, endpoint: ep, model: md, + backend, } } @@ -128,6 +178,7 @@ impl ChatClient { stream_to_stdout: bool, max_tokens: usize, ) -> Result { + eprintln!("Chat path: {}", describe_chat_backend(&self.backend)); let payload = json!({ "model": self.model, "messages": messages, From 0fa4dedd4585e57d34c79bd3010f80794c3bc097 Mon Sep 17 00:00:00 2001 From: AIEN Atlas Date: Tue, 22 Sep 2026 09:59:13 -0500 Subject: [PATCH 2/2] fix(cli): structured per request chat path telemetry Every turn emits one JSON line with path, backend, endpoint, model, runtime socket presence, and require_blackwell flag. Adapter traffic can no longer be mistaken for native success. Co-authored-by: Drake Stapleton --- crates/aien-cli/src/client.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/aien-cli/src/client.rs b/crates/aien-cli/src/client.rs index 32b2a4b6..c5980976 100644 --- a/crates/aien-cli/src/client.rs +++ b/crates/aien-cli/src/client.rs @@ -50,6 +50,31 @@ pub fn describe_chat_backend(backend: &ChatBackend) -> String { } } +/// Structured per request telemetry. A benchmark or test is only evidence of +/// the native runtime when path is native_runtime. Adapter traffic must never +/// be mistaken for native success. +pub fn emit_chat_telemetry(backend: &ChatBackend, model: &str) { + let (path, endpoint) = match backend { + ChatBackend::NativeRuntime => ("native_runtime", ""), + ChatBackend::RemoteAdapter(ep) => ("remote_adapter", ep.as_str()), + }; + let runtime_socket_present = + aien_runtime::client::AienRuntimeClient::default_socket_path().exists(); + let require_blackwell = std::env::var("AIEN_REQUIRE_BLACKWELL") + .map(|v| v.trim() == "1" || v.trim().eq_ignore_ascii_case("true")) + .unwrap_or(false); + let record = serde_json::json!({ + "event": "chat_path", + "path": path, + "backend": describe_chat_backend(backend), + "endpoint": endpoint, + "model": model, + "runtime_socket_present": runtime_socket_present, + "require_blackwell": require_blackwell, + }); + eprintln!("{}", record); +} + pub fn get_system_prompt() -> String { let mut p = String::from("You are AIEN. Drake is the operator. This Spark desk is ours.\n"); p.push_str("You are an autonomous operator-builder running on NVIDIA DGX Spark Grace Blackwell GB10 hardware.\n"); @@ -178,7 +203,7 @@ impl ChatClient { stream_to_stdout: bool, max_tokens: usize, ) -> Result { - eprintln!("Chat path: {}", describe_chat_backend(&self.backend)); + emit_chat_telemetry(&self.backend, &self.model); let payload = json!({ "model": self.model, "messages": messages,