mirror of
https://github.com/openai/codex.git
synced 2026-10-27 00:00:53 +00:00
## Why Environment context is model-visible state, but it is currently assembled from transient turn values and diffed through environment-specific paths. That makes initial injection, turn-to-turn updates, and changes that happen within a turn use different baselines. This PR introduces the smallest useful model world-state slice: environments only, with one in-memory baseline and one renderer for full state and diffs. ## What changed - Add a typed `WorldState` container whose sections render fragments relative to an optional previous value. Full rendering uses the same diff path with no previous state. - Replace the parallel `EnvironmentContext` representation with an `EnvironmentsState` section keyed by environment ID and rendered in deterministic order. - Preserve the legacy single-environment output while supporting multiple environments, starting environments, unavailable tombstones, and changes to persisted turn-context values. - Store the latest complete `WorldState` on `ContextManager` and use it for both turn-boundary and mid-turn environment diffs. - Build initial and post-compaction context from the same world-state builder, then retain the rendered state as the next baseline. - Seed the in-memory baseline from the latest `TurnContextItem` when resuming an existing rollout; the world state itself is not serialized. - Keep non-world settings updates on their existing path and merge rendered world-state fragments at the session consumer. ## Known limitation A legacy `TurnContextItem` only reconstructs the primary environment as `local`; it cannot faithfully recover a remote-primary environment ID after resume. Live state uses the exact environment IDs once a complete baseline is established. ## Test plan - `just test -p codex-core world_state` - `just test -p codex-core record_context_updates` - `just test -p codex-core deferred_executor_` - `just test -p codex-core build_initial_context` - `just test -p codex-core rollout_reconstruction` - `just test -p codex-core process_compacted_history_reinjects_full_initial_context`
80 lines
3.9 KiB
Rust
80 lines
3.9 KiB
Rust
//! Context fragments injected into model input.
|
|
|
|
mod approved_command_prefix_saved;
|
|
mod apps_instructions;
|
|
mod available_plugins_instructions;
|
|
mod available_skills_instructions;
|
|
mod collaboration_mode_instructions;
|
|
mod contextual_user_message;
|
|
mod current_time_reminder;
|
|
mod environment_context;
|
|
mod guardian_followup_review_reminder;
|
|
mod hook_additional_context;
|
|
mod image_generation_instructions;
|
|
mod inter_agent_completion_message;
|
|
mod internal_model_context;
|
|
mod legacy_apply_patch_exec_command_warning;
|
|
mod legacy_model_mismatch_warning;
|
|
mod legacy_unified_exec_process_limit_warning;
|
|
mod model_switch_instructions;
|
|
mod multi_agent_mode_instructions;
|
|
mod network_rule_saved;
|
|
mod permissions_instructions;
|
|
mod personality_spec_instructions;
|
|
mod plugin_instructions;
|
|
mod realtime_end_instructions;
|
|
mod realtime_start_instructions;
|
|
mod realtime_start_with_instructions;
|
|
mod recommended_plugins_instructions;
|
|
mod rollout_budget;
|
|
mod subagent_notification;
|
|
mod token_budget_context;
|
|
mod turn_aborted;
|
|
mod user_instructions;
|
|
mod user_shell_command;
|
|
pub(crate) mod world_state;
|
|
|
|
pub(crate) use approved_command_prefix_saved::ApprovedCommandPrefixSaved;
|
|
pub(crate) use apps_instructions::AppsInstructions;
|
|
pub(crate) use available_plugins_instructions::AvailablePluginsInstructions;
|
|
pub use available_skills_instructions::AvailableSkillsInstructions;
|
|
pub(crate) use codex_context_fragments::AdditionalContextDeveloperFragment;
|
|
pub(crate) use codex_context_fragments::AdditionalContextUserFragment;
|
|
pub use codex_context_fragments::ContextualUserFragment;
|
|
pub(crate) use codex_context_fragments::FragmentRegistration;
|
|
pub(crate) use codex_context_fragments::FragmentRegistrationProxy;
|
|
pub(crate) use codex_core_skills::SkillInstructions;
|
|
pub(crate) use collaboration_mode_instructions::CollaborationModeInstructions;
|
|
pub(crate) use contextual_user_message::is_contextual_user_fragment;
|
|
pub(crate) use contextual_user_message::parse_visible_hook_prompt_message;
|
|
pub(crate) use current_time_reminder::CurrentTimeReminder;
|
|
pub(crate) use guardian_followup_review_reminder::GuardianFollowupReviewReminder;
|
|
pub(crate) use hook_additional_context::HookAdditionalContext;
|
|
pub(crate) use image_generation_instructions::ImageGenerationInstructions;
|
|
pub use image_generation_instructions::extension_image_generation_output_hint;
|
|
pub(crate) use inter_agent_completion_message::InterAgentCompletionMessage;
|
|
pub use internal_model_context::InternalContextSource;
|
|
pub use internal_model_context::InternalModelContextFragment;
|
|
pub use internal_model_context::InvalidInternalContextSource;
|
|
pub(crate) use legacy_apply_patch_exec_command_warning::LegacyApplyPatchExecCommandWarning;
|
|
pub(crate) use legacy_model_mismatch_warning::LegacyModelMismatchWarning;
|
|
pub(crate) use legacy_unified_exec_process_limit_warning::LegacyUnifiedExecProcessLimitWarning;
|
|
pub(crate) use model_switch_instructions::ModelSwitchInstructions;
|
|
pub(crate) use multi_agent_mode_instructions::MultiAgentModeInstructions;
|
|
pub(crate) use network_rule_saved::NetworkRuleSaved;
|
|
pub use permissions_instructions::PermissionsInstructions;
|
|
pub(crate) use personality_spec_instructions::PersonalitySpecInstructions;
|
|
pub(crate) use plugin_instructions::PluginInstructions;
|
|
pub(crate) use realtime_end_instructions::RealtimeEndInstructions;
|
|
pub(crate) use realtime_start_instructions::RealtimeStartInstructions;
|
|
pub(crate) use realtime_start_with_instructions::RealtimeStartWithInstructions;
|
|
pub(crate) use recommended_plugins_instructions::RecommendedPluginsInstructions;
|
|
pub(crate) use rollout_budget::RolloutBudgetContext;
|
|
pub(crate) use subagent_notification::SubagentNotification;
|
|
pub(crate) use token_budget_context::TokenBudgetContext;
|
|
pub(crate) use token_budget_context::TokenBudgetRemainingContext;
|
|
pub(crate) use token_budget_context::TokenBudgetReminder;
|
|
pub(crate) use turn_aborted::TurnAborted;
|
|
pub(crate) use user_instructions::UserInstructions;
|
|
pub(crate) use user_shell_command::UserShellCommand;
|