Add experimental context management activation (#42385)

## What changed

- Add the under-development `features.context_management.experimental_mode` configuration and schema.
- For eligible ChatGPT Plus, Pro, and Pro Lite sessions using the Codex backend, enable token-budget context, history notes, and the `new_context` tool when experimental context management is configured.
- Keep the feature disabled for custom providers, provider credentials, non-Codex endpoints, and temporary structured threads.

## Testing

- Cover subscription eligibility, backend restrictions, configuration resolution, token-budget guidance, and temporary-thread overrides.

GitOrigin-RevId: 19402af19c4d69e09a7cdb3687ee7d233f6a562a
(cherry picked from commit cff76fa96f)
This commit is contained in:
pmccrary-oai
2026-09-02 16:49:37 -07:00
committed by Roy Han
parent 6f70e3d3a6
commit 05ae59c414
11 changed files with 236 additions and 16 deletions
+14
View File
@@ -293,6 +293,20 @@ impl FeatureConfig for MultiAgentV2ConfigToml {
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct ContextManagementConfigToml {
/// Enables experimental context management.
#[serde(skip_serializing_if = "Option::is_none")]
pub experimental_mode: Option<bool>,
}
impl FeatureConfig for ContextManagementConfigToml {
fn enabled(&self) -> Option<bool> {
self.experimental_mode
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct TokenBudgetConfigToml {
+18
View File
@@ -18,6 +18,7 @@ mod feature_configs;
mod legacy;
pub use feature_configs::CodeModeConfigToml;
pub use feature_configs::CodeModeHostConfigToml;
pub use feature_configs::ContextManagementConfigToml;
pub use feature_configs::CurrentTimeReminderConfigToml;
pub use feature_configs::CurrentTimeReminderDeliveryMode;
pub use feature_configs::CurrentTimeSource;
@@ -312,6 +313,8 @@ pub enum Feature {
Goals,
/// Add current context-window metadata to model-visible context.
TokenBudget,
/// Enables experimental context management.
ContextManagement,
/// Track and report a shared token budget across a session's agent threads.
RolloutBudget,
/// Add current-time reminders to model-visible context.
@@ -761,6 +764,8 @@ pub struct FeaturesToml {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub token_budget: Option<FeatureToml<TokenBudgetConfigToml>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub context_management: Option<FeatureToml<ContextManagementConfigToml>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rollout_budget: Option<FeatureToml<RolloutBudgetConfigToml>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub current_time_reminder: Option<FeatureToml<CurrentTimeReminderConfigToml>>,
@@ -807,6 +812,13 @@ impl FeaturesToml {
if let Some(enabled) = self.token_budget.as_ref().and_then(FeatureToml::enabled) {
entries.insert(Feature::TokenBudget.key().to_string(), enabled);
}
if let Some(enabled) = self
.context_management
.as_ref()
.and_then(FeatureToml::enabled)
{
entries.insert(Feature::ContextManagement.key().to_string(), enabled);
}
if let Some(enabled) = self.rollout_budget.as_ref().and_then(FeatureToml::enabled) {
entries.insert(Feature::RolloutBudget.key().to_string(), enabled);
}
@@ -1541,6 +1553,12 @@ pub const FEATURES: &[FeatureSpec] = &[
stage: Stage::UnderDevelopment,
default_enabled: false,
},
FeatureSpec {
id: Feature::ContextManagement,
key: "context_management",
stage: Stage::UnderDevelopment,
default_enabled: false,
},
FeatureSpec {
id: Feature::RolloutBudget,
key: "rollout_budget",