Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Expose the last accepted environment ready report (#42403)

Anton Panasenko1281778e3273
diff --git a/codex-rs/exec-server/src/environment.rs b/codex-rs/exec-server/src/environment.rs
index a63938be58..96ea0de073 100644
--- a/codex-rs/exec-server/src/environment.rs
+++ b/codex-rs/exec-server/src/environment.rs
@@ -853,6 +853,15 @@ impl Environment {
transition_error.map_or(Ok(()), Err)
}
+ /// Returns a snapshot of the last accepted Ready report.
+ ///
+ /// `None` means no Ready report has been accepted, including for ordinary environments.
+ /// A report with no capability roots is distinct from `None`. The snapshot does not change
+ /// when later reports arrive and does not indicate whether the connection is healthy.
+ pub fn last_ready_info(&self) -> Option<Arc<EnvironmentReadyInfo>> {
+ self.ready_info.load_full()
+ }
+
/// Returns the capability roots most recently reported for this environment.
pub fn selected_capability_roots(&self) -> Vec<SelectedCapabilityRoot> {
self.ready_info
diff --git a/codex-rs/exec-server/tests/deferred_environment.rs b/codex-rs/exec-server/tests/deferred_environment.rs
index 123e55e8b7..e7bc32d243 100644
--- a/codex-rs/exec-server/tests/deferred_environment.rs
+++ b/codex-rs/exec-server/tests/deferred_environment.rs
@@ -91,6 +91,7 @@ async fn materialize_then_report_ready_reuses_the_pending_environment() -> anyho
let pending_provider = Arc::new(FailingNoiseConnectProvider::default());
let pending = manager
.materialize_pending_noise_environment("tools".to_string(), pending_provider.clone())?;
+ assert_eq!(pending.last_ready_info(), None);
let mut pending_readiness = Box::pin(pending.wait_until_ready());
assert!(poll!(&mut pending_readiness).is_pending());
let ready = manager
@@ -132,6 +133,7 @@ async fn ordinary_environment_ignores_provisioning_reports() -> anyhow::Result<(
assert!(Arc::ptr_eq(&existing_environment, &current_environment));
assert!(reported.is_none());
assert!(existing_environment.selected_capability_roots().is_empty());
+ assert_eq!(existing_environment.last_ready_info(), None);
Ok(())
}
@@ -226,6 +228,7 @@ async fn repeated_failure_preserves_the_first_error_until_ready() -> anyhow::Res
error.to_string()
);
assert!(failed.selected_capability_roots().is_empty());
+ assert_eq!(failed.last_ready_info(), None);
assert_eq!(provider.calls(), 0);
let selected = ready_info("selected-root", "tools")?;
let ready = manager
@@ -236,6 +239,7 @@ async fn repeated_failure_preserves_the_first_error_until_ready() -> anyhow::Res
)?
.expect("successful provisioning should recover the same environment");
assert!(Arc::ptr_eq(&failed, &ready));
+ assert_eq!(failed.last_ready_info().as_deref(), Some(&selected));
assert_eq!(
failed.selected_capability_roots(),
selected.selected_capability_roots
@@ -325,6 +329,50 @@ async fn existing_environment_overwrites_reported_readiness() -> anyhow::Result<
Ok(())
}
+#[tokio::test]
+async fn last_ready_info_preserves_snapshots_through_replacement_and_clear() -> anyhow::Result<()> {
+ let manager = environment_manager_without_environments();
+ let provider = Arc::new(FailingNoiseConnectProvider::default());
+ let selected = ready_info("selected-root", "tools")?;
+ let environment = manager
+ .report_environment_provisioning_status(
+ "tools".to_string(),
+ Ok(selected.clone()),
+ provider.clone(),
+ )?
+ .expect("readiness report should create the environment");
+ let snapshot = environment.last_ready_info();
+ assert_eq!(snapshot.as_deref(), Some(&selected));
+
+ for replacement in [
+ ready_info("different-root", "tools")?,
+ EnvironmentReadyInfo::default(),
+ ] {
+ manager.report_environment_provisioning_status(
+ "tools".to_string(),
+ Ok(replacement.clone()),
+ provider.clone(),
+ )?;
+ assert_eq!(environment.last_ready_info().as_deref(), Some(&replacement));
+ assert_eq!(snapshot.as_deref(), Some(&selected));
+ }
+
+ let error = manager
+ .report_environment_provisioning_status(
+ "tools".to_string(),
+ Ok(ready_info("invalid-root", "other")?),
+ provider.clone(),
+ )
+ .unwrap_err();
+ assert!(matches!(error, ExecServerError::Protocol(_)));
+ assert_eq!(
+ environment.last_ready_info().as_deref(),
+ Some(&EnvironmentReadyInfo::default())
+ );
+ assert_eq!(provider.calls(), 0);
+ Ok(())
+}
+
#[tokio::test]
async fn invalid_ready_report_fails_the_provisioning_gate() -> anyhow::Result<()> {
let manager = environment_manager_without_environments();