mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Expose app-server diagnostics through the experimental API (#37470)
## What changed - Add the experimental `server/diagnostics` request, returning the app-server process ID, resident memory, platform-dependent physical footprint, and registered diagnostic gauges. - Export the new protocol types in the generated JSON and TypeScript schemas and document the request. ## Testing - Verify the response includes process measurements and the registered live-thread gauge. - Verify the request is rejected unless `capabilities.experimentalApi` is enabled. GitOrigin-RevId: 099d60a9c421a74ff1a72fe524e0dfeb89cf1057
This commit is contained in:
1 parent
b3278e96cb
commit
5729546839
18 files changed
+298
No files matched your search
@@ -74,6 +74,7 @@ mod safety_check_downgrade;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
mod selected_capability_stack;
|
||||
mod selected_environment;
|
||||
mod server_diagnostics;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
mod session_end;
|
||||
mod skills_list;
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use app_test_support::DEFAULT_CLIENT_NAME;
|
||||
use app_test_support::MockResponsesConfig;
|
||||
use app_test_support::TestAppServer;
|
||||
use app_test_support::create_mock_responses_server_repeating_assistant;
|
||||
use codex_app_server_protocol::ClientInfo;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::InitializeCapabilities;
|
||||
use codex_app_server_protocol::JSONRPCMessage;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::ServerDiagnosticsGauge;
|
||||
use codex_app_server_protocol::ServerDiagnosticsParams;
|
||||
use codex_app_server_protocol::ServerDiagnosticsResponse;
|
||||
use codex_app_server_protocol::ThreadStartParams;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use tempfile::TempDir;
|
||||
use tokio::time::timeout;
|
||||
|
||||
const READ_TIMEOUT: Duration = Duration::from_secs(20);
|
||||
|
||||
#[tokio::test]
|
||||
async fn server_diagnostics_exposes_process_and_registered_thread_gauge() -> Result<()> {
|
||||
let server = create_mock_responses_server_repeating_assistant("Done").await;
|
||||
let codex_home = TempDir::new()?;
|
||||
MockResponsesConfig::new(&server.uri()).write(codex_home.path())?;
|
||||
let mut app_server = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
.build_initialized()
|
||||
.await?;
|
||||
app_server
|
||||
.start_thread(ThreadStartParams::default())
|
||||
.await?;
|
||||
|
||||
let diagnostics: ServerDiagnosticsResponse = app_server
|
||||
.request(|request_id| ClientRequest::ServerDiagnostics {
|
||||
request_id,
|
||||
params: ServerDiagnosticsParams::default(),
|
||||
})
|
||||
.await?;
|
||||
|
||||
assert!(diagnostics.process.id > 0);
|
||||
assert!(diagnostics.process.resident_memory_bytes.is_some());
|
||||
#[cfg(target_os = "macos")]
|
||||
assert!(diagnostics.process.physical_footprint_bytes.is_some());
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
assert_eq!(diagnostics.process.physical_footprint_bytes, None);
|
||||
assert_eq!(
|
||||
diagnostics.gauges,
|
||||
vec![ServerDiagnosticsGauge {
|
||||
name: "core.threads.live".to_string(),
|
||||
value: 1,
|
||||
}]
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn server_diagnostics_requires_experimental_capability() -> Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let mut app_server = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
.build()
|
||||
.await?;
|
||||
let initialization = app_server
|
||||
.initialize_with_capabilities(
|
||||
ClientInfo {
|
||||
name: DEFAULT_CLIENT_NAME.to_string(),
|
||||
title: None,
|
||||
version: "0.1.0".to_string(),
|
||||
},
|
||||
Some(InitializeCapabilities {
|
||||
experimental_api: false,
|
||||
..Default::default()
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
assert!(matches!(initialization, JSONRPCMessage::Response(_)));
|
||||
|
||||
let request_id = app_server
|
||||
.send_raw_request("server/diagnostics", Some(json!({})))
|
||||
.await?;
|
||||
let error = timeout(
|
||||
READ_TIMEOUT,
|
||||
app_server.read_stream_until_error_message(RequestId::Integer(request_id)),
|
||||
)
|
||||
.await??;
|
||||
|
||||
assert_eq!(error.error.code, -32600);
|
||||
assert_eq!(
|
||||
error.error.message,
|
||||
"server/diagnostics requires experimentalApi capability"
|
||||
);
|
||||
assert_eq!(error.error.data, None);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user