Gate experimental context by model capability at session startup (#43147)

## Why

Experimental context activation previously checked the provider and account eligibility without checking model support. Child sessions also inherited token-budget activation from their parent, even when starting fresh with a different model.

## What changed

- Add `ModelInfo.supports_experimental_context`, defaulting to `false`, and enable it for the bundled `gpt-6-astra` model. Require this capability when activating experimental context.
- Snapshot configured token-budget preferences before startup activation. Restore them for fresh child sessions before applying their starting model's defaults, while history forks retain their parent's activation.
- Pass unresolved token-budget preferences to child sessions so they can use their own model's prompts.

## Testing

Extend coverage for unsupported models, model-switch guidance under explicit and experimental activation, and child configuration from both active and inactive parents. Verify that omitted capability metadata defaults to `false`.

GitOrigin-RevId: 02df9e171682267232fa923d5ea3f7af36527808
This commit is contained in:
pmccrary-oai authored and copyberry committed 2026-09-06 02:28:38 +00:00
1 parent 1c40ffe427
commit 6af345407d
21 files changed
+128 -15

No files matched your search

@@ -195,6 +195,9 @@ pub(crate) fn build_agent_resume_config(turn: &TurnContext) -> Result<Config, Fu
fn build_agent_shared_config(turn: &TurnContext) -> Result<Config, FunctionCallError> {
let base_config = turn.config.clone();
let mut config = (*base_config).clone();
// Preserve activation for history forks without freezing the parent's model-owned prompts.
// Fresh child startup restores configured preferences from the retained snapshot.
config.token_budget = turn.configured_token_budget.clone();
config.model = Some(turn.model_info().slug.clone());
config.model_provider = turn.provider.info().clone();
config.model_reasoning_effort = turn
@@ -4371,8 +4371,10 @@ async fn tool_handlers_cascade_close_and_resume_and_keep_explicitly_closed_subtr
assert_eq!(shutdown_report.timed_out, Vec::<ThreadId>::new());
}
#[test_case::test_case(false; "inactive_parent")]
#[test_case::test_case(true; "active_parent")]
#[tokio::test]
async fn build_agent_spawn_config_uses_turn_context_values() {
async fn build_agent_spawn_config_uses_turn_context_values(parent_enabled: bool) {
fn pick_allowed_sandbox_policy(
permissions: &crate::config::Permissions,
base: SandboxPolicy,
@@ -4443,8 +4445,26 @@ async fn build_agent_spawn_config_uses_turn_context_values() {
.set(AskForApproval::OnRequest)
.expect("approval policy set");
let parent_config = Arc::make_mut(&mut turn.config);
parent_config
.prepare_token_budget_for_startup()
.expect("capture configured token budget");
parent_config
.features
.set_enabled(Feature::TokenBudget, parent_enabled)
.expect("set parent experimental context");
parent_config
.token_budget
.get_or_insert_default()
.use_history_notes_extension = parent_enabled;
let mut expected = parent_config.clone();
turn.configured_token_budget = expected.token_budget.clone();
Arc::make_mut(&mut turn.config)
.token_budget
.get_or_insert_default()
.guidance_message = Some("Parent model's resolved guidance.".to_string());
let config = build_agent_spawn_config(&base_instructions, &turn).expect("spawn config");
let mut expected = (*turn.config).clone();
expected.base_instructions_provenance = base_instructions.provenance.clone();
expected.base_instructions = Some(base_instructions.text);
expected.model = Some(turn.model_info().slug.clone());