mirror of
https://github.com/openai/codex.git
synced 2026-10-26 07:58:43 +00:00
Add process diagnostics snapshots (#37434)
## What changed - Add a `codex-diagnostics` crate that snapshots the process ID, available resident-memory measurements, and registered process-wide gauges. - Provide guards that update gauges for the lifetime of measured objects. - Track live `CodexThread` instances with the `core.threads.live` gauge. ## Testing - Add unit coverage for gauge registration, guard lifetimes, process memory snapshots, and live-thread reporting. GitOrigin-RevId: 3236b086bd4ebe31ed4768ab87a5fa288b0891b0
This commit is contained in:
@@ -9,6 +9,8 @@ use crate::session::session::Session;
|
||||
use crate::user_message_admission::PendingUserMessageAdmissionState;
|
||||
use crate::user_message_admission::UserMessageAdmission;
|
||||
use crate::user_message_admission::UserMessageAdmissionError;
|
||||
use codex_diagnostics::Gauge;
|
||||
use codex_diagnostics::GaugeGuard;
|
||||
use codex_exec_server::SelectedCapabilityRootsStatus;
|
||||
use codex_extension_api::ThreadIdleCause;
|
||||
use codex_features::Feature;
|
||||
@@ -65,6 +67,8 @@ use tokio_util::sync::CancellationToken;
|
||||
|
||||
use codex_rollout::state_db::StateDbHandle;
|
||||
|
||||
static LIVE_THREADS: Gauge = Gauge::new("core.threads.live");
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ThreadConfigSnapshot {
|
||||
pub model: String,
|
||||
@@ -197,6 +201,7 @@ pub struct CodexThread {
|
||||
session_configured: SessionConfiguredEvent,
|
||||
rollout_path: Option<PathBuf>,
|
||||
out_of_band_elicitations: Mutex<OutOfBandElicitations>,
|
||||
_diagnostics_guard: GaugeGuard,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -230,6 +235,7 @@ impl CodexThread {
|
||||
session_configured,
|
||||
rollout_path,
|
||||
out_of_band_elicitations: Mutex::new(OutOfBandElicitations::default()),
|
||||
_diagnostics_guard: LIVE_THREADS.track(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -800,6 +800,12 @@ async fn start_thread_keeps_internal_threads_hidden_from_normal_lookups() {
|
||||
|
||||
assert_eq!(manager.list_thread_ids().await, Vec::new());
|
||||
assert!(manager.get_thread(thread.thread_id).await.is_err());
|
||||
assert!(
|
||||
codex_diagnostics::snapshot()
|
||||
.gauges
|
||||
.iter()
|
||||
.any(|gauge| gauge.name == "core.threads.live" && gauge.value > 0)
|
||||
);
|
||||
|
||||
let report = manager
|
||||
.shutdown_all_threads_bounded(Duration::from_secs(10))
|
||||
|
||||
Reference in New Issue
Block a user