diff --git a/codex-rs/core/src/context/world_state/command_sessions.rs b/codex-rs/core/src/context/world_state/command_sessions.rs index b7e662a821..95cccb942f 100644 --- a/codex-rs/core/src/context/world_state/command_sessions.rs +++ b/codex-rs/core/src/context/world_state/command_sessions.rs @@ -58,45 +58,27 @@ impl WorldStateSection for CommandSessionsState { true } + fn matches_legacy_fragment(role: &str, text: &str) -> bool { + Self::matches_retained_fragment(role, text) + } + fn matches_retained_fragment(role: &str, text: &str) -> bool { role == "developer" && Self::matches_text(text) } - fn render_diff( - &self, - previous: PreviousSectionState<'_, Self::Snapshot>, - ) -> SectionTransition { - if matches!(previous, PreviousSectionState::Known(previous) if previous == self) { - return (None, Vec::new()); - } - ( - Some(self.clone()), - vec![WorldStateUpdate::fragment(self.clone())], - ) - } -} - -/// Clears stale handles when disabled, or preserves live handles when polling is unavailable. -#[derive(Default)] -pub(crate) struct DisabledCommandSessionsState(pub(crate) CommandSessionsState); - -impl WorldStateSection for DisabledCommandSessionsState { - const ID: &'static str = CommandSessionsState::ID; - type Snapshot = CommandSessionsState; - - fn matches_legacy_fragment(role: &str, text: &str) -> bool { - CommandSessionsState::matches_retained_fragment(role, text) - } - fn render_diff( &self, previous: PreviousSectionState<'_, Self::Snapshot>, ) -> SectionTransition { match previous { - PreviousSectionState::Absent if self.0.sessions.is_empty() => (None, Vec::new()), + PreviousSectionState::Absent if self.sessions.is_empty() => (None, Vec::new()), + PreviousSectionState::Known(previous) if previous == self => (None, Vec::new()), PreviousSectionState::Absent | PreviousSectionState::Unknown - | PreviousSectionState::Known(_) => self.0.render_diff(previous), + | PreviousSectionState::Known(_) => ( + Some(self.clone()), + vec![WorldStateUpdate::fragment(self.clone())], + ), } } } diff --git a/codex-rs/core/src/context/world_state/mod.rs b/codex-rs/core/src/context/world_state/mod.rs index e3d64da9d8..f1922d045f 100644 --- a/codex-rs/core/src/context/world_state/mod.rs +++ b/codex-rs/core/src/context/world_state/mod.rs @@ -49,7 +49,6 @@ pub(crate) use collaboration_mode::CollaborationModeState; pub(crate) use command_sessions::CommandSession; pub(crate) use command_sessions::CommandSessionStatus; pub(crate) use command_sessions::CommandSessionsState; -pub(crate) use command_sessions::DisabledCommandSessionsState; pub(crate) use compact_permissions::CompactPermissionsState; pub(crate) use context_window_guidance::ContextWindowGuidanceState; pub(crate) use environment::EnvironmentsState; diff --git a/codex-rs/core/src/session/world_state.rs b/codex-rs/core/src/session/world_state.rs index 3b18c0ea3d..bed6c9f0c8 100644 --- a/codex-rs/core/src/session/world_state.rs +++ b/codex-rs/core/src/session/world_state.rs @@ -211,29 +211,12 @@ impl Session { String::new() }; let mut world_state = WorldState::default(); - if turn_context - .config - .features - .enabled(Feature::CommandSessionsWorldState) - { - let mut sessions = - crate::unified_exec::command_sessions_state(&self.services.unified_exec_manager) - .await; - if step_context - .tool_router - .exposes_tool(&ToolName::plain("write_stdin")) - { - world_state.add_section(sessions); - } else { - sessions.polling_unavailable = true; - world_state.add_section(crate::context::world_state::DisabledCommandSessionsState( - sessions, - )); - } - } else { - world_state - .add_section(crate::context::world_state::DisabledCommandSessionsState::default()); - } + let mut sessions = + crate::unified_exec::command_sessions_state(&self.services.unified_exec_manager).await; + sessions.polling_unavailable = !step_context + .tool_router + .exposes_tool(&ToolName::plain("write_stdin")); + world_state.add_section(sessions); let extension_metrics = super::extension_metrics::from_session_telemetry( step_context.session_telemetry.clone(), ); diff --git a/codex-rs/core/tests/suite/scenarios_command_sessions_tests.rs b/codex-rs/core/tests/suite/scenarios_command_sessions_tests.rs index 21496b6e9b..d581f53c9f 100644 --- a/codex-rs/core/tests/suite/scenarios_command_sessions_tests.rs +++ b/codex-rs/core/tests/suite/scenarios_command_sessions_tests.rs @@ -36,7 +36,6 @@ async fn command_sessions_world_state_tracks_retained_processes() -> Result<()> Feature::CodeMode, Feature::CodeModeOnly, Feature::CodeModeHost, - Feature::CommandSessionsWorldState, ] { config .features diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__command_sessions__command_sessions_world_state.snap b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__command_sessions__command_sessions_world_state.snap index eab992915d..ce928ae13b 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__command_sessions__command_sessions_world_state.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__command_sessions__command_sessions_world_state.snap @@ -23,12 +23,8 @@ Scenario: A Code Mode script drops its command handle. WorldState retains it whi - function/wait_agent 01:message/developer: -02:message/developer[2]: - [01] - Current command sessions for this thread (supersedes earlier snapshots). Exited sessions retain results ... busy with a tool interaction or result finalization. [hash=e247ea1c0c96e976] - None. - - [02] +02:message/developer: + 03:message/developer: 04:message/developer: @@ -74,12 +70,8 @@ Scenario: A Code Mode script drops its command handle. WorldState retains it whi - function/wait_agent 01:message/developer: -02:message/developer[2]: - [01] - Current command sessions for this thread (supersedes earlier snapshots). Exited sessions retain results ... busy with a tool interaction or result finalization. [hash=e247ea1c0c96e976] - None. - - [02] +02:message/developer: + 03:message/developer: 04:message/developer: diff --git a/codex-rs/features/src/lib.rs b/codex-rs/features/src/lib.rs index 5ff59b4251..ce1aaa78dd 100644 --- a/codex-rs/features/src/lib.rs +++ b/codex-rs/features/src/lib.rs @@ -330,7 +330,7 @@ pub enum Feature { ToolSearchAlwaysDeferMcpTools, /// Describe deferred tool namespaces in the model-visible world state. DeferredToolWorldState, - /// Publish retained command sessions through incremental world state. + /// Removed compatibility flag. World state always tracks retained command sessions. CommandSessionsWorldState, /// Track top-level tool definitions in world state and emit incremental context updates. IncrementalTools, @@ -1972,7 +1972,7 @@ pub const FEATURES: &[FeatureSpec] = &[ FeatureSpec { id: Feature::CommandSessionsWorldState, key: "command_sessions_world_state", - stage: Stage::UnderDevelopment, + stage: Stage::Removed, default_enabled: false, }, FeatureSpec {