mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
Allow new threads to opt out of Daybreak propagation (#62879)
## Why App-server clients that prepare threads for later use need to be able to skip Daybreak propagation for an individual thread when the server configuration enables it. ## What changed With `experimentalApi`, pass `daybreakProgramPropagationEnrolled: false` to `thread/start` to opt a new root thread out. Managed requirements take precedence. Omitting the field or passing `null` or `true` uses the configured enrollment rule. The same field on `Thread` reports actual enrollment for the live session, including in the start response and `thread/started` notification. Reusing a live session preserves its enrollment. A thread returned from stored metadata alone reports `null`, and resuming it from storage in a new session reports `false`. ## Testing App-server tests cover enrollment under enabled, required, and disabled configuration, as well as reporting across live reads and resumes, unload, and resume from storage. A core test checks that opting out prevents native helpers from inheriting the root's saved Daybreak choice. GitOrigin-RevId: f9aae9ff76702b1e5a38d45120cd889a26f8ece5
This commit is contained in:
@@ -682,6 +682,7 @@ fn sample_thread(thread_id: &str) -> Thread {
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "openai".to_string(),
|
||||
model: None,
|
||||
|
||||
@@ -120,6 +120,7 @@ pub(super) fn sample_thread_with_metadata(
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "openai".to_string(),
|
||||
model: None,
|
||||
|
||||
BIN
Binary file not shown.
@@ -3394,6 +3394,7 @@ mod tests {
|
||||
git_info: None,
|
||||
name: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
turns: Vec::new(),
|
||||
},
|
||||
model: "gpt-5".to_string(),
|
||||
@@ -3457,6 +3458,7 @@ mod tests {
|
||||
"gitInfo": null,
|
||||
"name": null,
|
||||
"daybreakEnabled": null,
|
||||
"daybreakProgramPropagationEnrolled": null,
|
||||
"turns": []
|
||||
},
|
||||
"model": "gpt-5",
|
||||
|
||||
@@ -334,6 +334,7 @@ fn thread_resume_response_round_trips_initial_turns_page() {
|
||||
git_info: None,
|
||||
name: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
turns: Vec::new(),
|
||||
},
|
||||
model: "gpt-5".to_string(),
|
||||
|
||||
@@ -137,6 +137,11 @@ pub struct ThreadStartParams {
|
||||
#[experimental("thread/start.daybreakEnabled")]
|
||||
#[ts(optional = nullable)]
|
||||
pub daybreak_enabled: Option<bool>,
|
||||
/// False opts this new root out of Daybreak propagation unless managed policy
|
||||
/// requires it. Omitted, null, or true uses the configured enrollment rule.
|
||||
#[experimental("thread/start.daybreakProgramPropagationEnrolled")]
|
||||
#[ts(optional = nullable)]
|
||||
pub daybreak_program_propagation_enrolled: Option<bool>,
|
||||
/// Optional sticky environments for this thread.
|
||||
///
|
||||
/// Omitted selects the default environment when environment access is
|
||||
|
||||
@@ -293,6 +293,10 @@ pub struct Thread {
|
||||
/// Saved Daybreak choice, independent of turn execution. Null if unset.
|
||||
#[experimental("thread.daybreakEnabled")]
|
||||
pub daybreak_enabled: Option<bool>,
|
||||
/// Whether the live thread joined the Daybreak propagation experiment at startup.
|
||||
/// Null when only stored metadata is available. Older servers can omit this field.
|
||||
#[experimental("thread.daybreakProgramPropagationEnrolled")]
|
||||
pub daybreak_program_propagation_enrolled: Option<bool>,
|
||||
/// Only populated on `thread/resume`, `thread/fork`, and `thread/read`
|
||||
/// (when `includeTurns` is true) responses.
|
||||
/// For all other responses and notifications returning a Thread,
|
||||
@@ -342,6 +346,7 @@ struct ThreadCompatibility {
|
||||
git_info: Option<GitInfo>,
|
||||
name: Option<String>,
|
||||
daybreak_enabled: Option<bool>,
|
||||
daybreak_program_propagation_enrolled: Option<bool>,
|
||||
turns: Vec<Turn>,
|
||||
}
|
||||
|
||||
@@ -384,6 +389,7 @@ impl<'de> Deserialize<'de> for Thread {
|
||||
git_info: thread.git_info,
|
||||
name: thread.name,
|
||||
daybreak_enabled: thread.daybreak_enabled,
|
||||
daybreak_program_propagation_enrolled: thread.daybreak_program_propagation_enrolled,
|
||||
turns: thread.turns,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -193,6 +193,15 @@ the choice unset. Ephemeral threads cannot save it.
|
||||
Use `thread/metadata/update` for later changes. This preference does not select
|
||||
`turn/start.cyberAccessProgram` or grant access to an access program.
|
||||
|
||||
With `experimentalApi`, a client preparing a thread for later use can pass
|
||||
`daybreakProgramPropagationEnrolled: false` to `thread/start` to opt that root
|
||||
out of Daybreak propagation. A managed requirement to enable propagation takes
|
||||
precedence. Omitted, null, or true uses the configured enrollment rule.
|
||||
`thread.daybreakProgramPropagationEnrolled` reports actual enrollment for the
|
||||
live thread, including in the start response and `thread/started` notification.
|
||||
Stored metadata alone yields null. Reusing the same live session preserves its
|
||||
enrollment. Starting a new session from storage yields false.
|
||||
|
||||
# Application network policy
|
||||
|
||||
App-server loads application network policy at startup and existing explicit
|
||||
|
||||
@@ -623,8 +623,11 @@ use token_usage_replay::send_thread_token_usage_update_to_connection;
|
||||
|
||||
pub(crate) fn apply_live_thread_settings(
|
||||
thread: &mut Thread,
|
||||
loaded_thread: &CodexThread,
|
||||
config_snapshot: &ThreadConfigSnapshot,
|
||||
) {
|
||||
thread.daybreak_program_propagation_enrolled =
|
||||
Some(loaded_thread.daybreak_program_propagation_enrolled());
|
||||
thread.model = Some(config_snapshot.model.clone());
|
||||
thread.reasoning_effort = config_snapshot.reasoning_effort.clone();
|
||||
thread.environments = Some(
|
||||
|
||||
@@ -56,7 +56,7 @@ async fn enrich_loaded_thread(
|
||||
return;
|
||||
};
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
apply_live_thread_settings(thread, &config_snapshot);
|
||||
apply_live_thread_settings(thread, &loaded_thread, &config_snapshot);
|
||||
if !matches!(
|
||||
&thread.source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. })
|
||||
|
||||
@@ -1347,6 +1347,7 @@ impl ThreadRequestProcessor {
|
||||
thread_source,
|
||||
project_id,
|
||||
daybreak_enabled,
|
||||
daybreak_program_propagation_enrolled,
|
||||
environments,
|
||||
} = params;
|
||||
if matches!(
|
||||
@@ -1426,6 +1427,7 @@ impl ThreadRequestProcessor {
|
||||
thread_source.map(Into::into),
|
||||
project_id,
|
||||
daybreak_enabled,
|
||||
daybreak_program_propagation_enrolled,
|
||||
environment_requests,
|
||||
service_name,
|
||||
allow_provider_model_fallback,
|
||||
@@ -1508,6 +1510,7 @@ impl ThreadRequestProcessor {
|
||||
thread_source: Option<codex_protocol::protocol::ThreadSource>,
|
||||
project_id: Option<String>,
|
||||
daybreak_enabled: Option<bool>,
|
||||
daybreak_program_propagation_enrolled: Option<bool>,
|
||||
environment_requests: Option<Vec<TurnEnvironmentRequest>>,
|
||||
service_name: Option<String>,
|
||||
allow_provider_model_fallback: bool,
|
||||
@@ -1689,6 +1692,8 @@ impl ThreadRequestProcessor {
|
||||
parent_trace: request_trace,
|
||||
environments: Some(environment_requests),
|
||||
thread_extension_init,
|
||||
prevent_daybreak_program_propagation_enrollment:
|
||||
daybreak_program_propagation_enrolled == Some(false),
|
||||
client_mcp_extensions,
|
||||
..start_options
|
||||
})
|
||||
@@ -1699,10 +1704,7 @@ impl ThreadRequestProcessor {
|
||||
))
|
||||
.await;
|
||||
let NewThread {
|
||||
thread_id,
|
||||
thread,
|
||||
session_configured,
|
||||
..
|
||||
thread_id, thread, ..
|
||||
} = match new_thread {
|
||||
Ok(new_thread) => new_thread,
|
||||
Err(err) => {
|
||||
@@ -1742,13 +1744,7 @@ impl ThreadRequestProcessor {
|
||||
otel.name = "app_server.thread_start.config_snapshot",
|
||||
))
|
||||
.await;
|
||||
let mut thread = build_thread_from_snapshot(
|
||||
thread_id,
|
||||
session_configured.session_id.to_string(),
|
||||
thread.multi_agent_version(),
|
||||
&config_snapshot,
|
||||
session_configured.rollout_path.clone(),
|
||||
)?;
|
||||
let mut thread = build_thread_from_loaded_snapshot(&thread, &config_snapshot)?;
|
||||
thread.project_id = project_id.clone();
|
||||
thread.daybreak_enabled = daybreak_enabled;
|
||||
|
||||
@@ -2235,7 +2231,7 @@ impl ThreadRequestProcessor {
|
||||
if let Ok(loaded_thread) = self.thread_manager.get_thread(thread_uuid).await {
|
||||
thread.session_id = loaded_thread.startup_metadata().session_id.to_string();
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, &loaded_thread, &config_snapshot);
|
||||
}
|
||||
self.attach_thread_name(thread_uuid, &mut thread).await;
|
||||
thread.status = resolve_thread_status(
|
||||
@@ -2293,7 +2289,7 @@ impl ThreadRequestProcessor {
|
||||
|
||||
if let Ok(loaded_thread) = self.thread_manager.get_thread(thread_id).await {
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, &loaded_thread, &config_snapshot);
|
||||
}
|
||||
thread.status = resolve_thread_status(
|
||||
self.thread_watch_manager
|
||||
@@ -3410,7 +3406,7 @@ impl ThreadRequestProcessor {
|
||||
loaded_thread.multi_agent_version(),
|
||||
&config_snapshot.session_source,
|
||||
));
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, loaded_thread, &config_snapshot);
|
||||
if !include_turns {
|
||||
if let Some(title) = display_thread_title(
|
||||
thread.history_mode,
|
||||
@@ -3423,7 +3419,7 @@ impl ThreadRequestProcessor {
|
||||
}
|
||||
thread
|
||||
} else {
|
||||
build_thread_from_loaded_snapshot(thread_id, &config_snapshot, loaded_thread)
|
||||
build_thread_from_loaded_snapshot(loaded_thread, &config_snapshot)
|
||||
.map_err(ThreadReadViewError::JsonRpc)?
|
||||
};
|
||||
self.attach_thread_name(thread_id, &mut thread).await;
|
||||
@@ -5028,7 +5024,7 @@ impl ThreadRequestProcessor {
|
||||
)?;
|
||||
thread_summary.session_id = existing_thread.startup_metadata().session_id.to_string();
|
||||
thread_summary.thread_source = config_snapshot.thread_source.clone().map(Into::into);
|
||||
apply_live_thread_settings(&mut thread_summary, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread_summary, &existing_thread, &config_snapshot);
|
||||
thread_summary.can_accept_direct_input = Some(can_accept_direct_input(
|
||||
existing_thread.multi_agent_version(),
|
||||
&config_snapshot.session_source,
|
||||
@@ -5324,16 +5320,16 @@ impl ThreadRequestProcessor {
|
||||
async fn load_thread_from_resume_source_or_send_internal(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
thread: &CodexThread,
|
||||
loaded_thread: &CodexThread,
|
||||
thread_history: &InitialHistory,
|
||||
rollout_path: &Path,
|
||||
resume_source_thread: Option<StoredThread>,
|
||||
include_turns: bool,
|
||||
) -> std::result::Result<Thread, String> {
|
||||
let config_snapshot = thread.config_snapshot().await;
|
||||
let session_id = thread.startup_metadata().session_id.to_string();
|
||||
let config_snapshot = loaded_thread.config_snapshot().await;
|
||||
let session_id = loaded_thread.startup_metadata().session_id.to_string();
|
||||
let can_accept_direct_input = can_accept_direct_input(
|
||||
thread.multi_agent_version(),
|
||||
loaded_thread.multi_agent_version(),
|
||||
&config_snapshot.session_source,
|
||||
);
|
||||
let thread = match thread_history {
|
||||
@@ -5393,14 +5389,8 @@ impl ThreadRequestProcessor {
|
||||
}
|
||||
}
|
||||
InitialHistory::Forked(items) => {
|
||||
let mut thread = build_thread_from_snapshot(
|
||||
thread_id,
|
||||
session_id.clone(),
|
||||
thread.multi_agent_version(),
|
||||
&config_snapshot,
|
||||
Some(rollout_path.into()),
|
||||
)
|
||||
.map_err(|error| error.message)?;
|
||||
let mut thread = build_thread_from_loaded_snapshot(loaded_thread, &config_snapshot)
|
||||
.map_err(|error| error.message)?;
|
||||
thread.preview = preview_from_rollout_items(items);
|
||||
Ok(thread)
|
||||
}
|
||||
@@ -5409,7 +5399,7 @@ impl ThreadRequestProcessor {
|
||||
)),
|
||||
};
|
||||
let mut thread = thread?;
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, loaded_thread, &config_snapshot);
|
||||
thread.can_accept_direct_input = Some(can_accept_direct_input);
|
||||
thread.id = thread_id.to_string();
|
||||
thread.session_id = session_id;
|
||||
@@ -6049,13 +6039,7 @@ impl ThreadRequestProcessor {
|
||||
});
|
||||
(thread, token_usage_turn_id)
|
||||
} else {
|
||||
let mut thread = build_thread_from_snapshot(
|
||||
thread_id,
|
||||
session_configured.session_id.to_string(),
|
||||
forked_thread.multi_agent_version(),
|
||||
&config_snapshot,
|
||||
/*path*/ None,
|
||||
)?;
|
||||
let mut thread = build_thread_from_loaded_snapshot(&forked_thread, &config_snapshot)?;
|
||||
thread.preview = inherited_preview;
|
||||
thread.forked_from_id = Some(source_thread_id.to_string());
|
||||
thread.turns = ephemeral_turns;
|
||||
@@ -6081,7 +6065,7 @@ impl ThreadRequestProcessor {
|
||||
));
|
||||
thread.session_id = session_configured.session_id.to_string();
|
||||
thread.thread_source = config_snapshot.thread_source.clone().map(Into::into);
|
||||
apply_live_thread_settings(&mut thread, &config_snapshot);
|
||||
apply_live_thread_settings(&mut thread, &forked_thread, &config_snapshot);
|
||||
if thread.path.is_none() {
|
||||
thread.project_id = inherited_project_id.clone();
|
||||
}
|
||||
@@ -6982,6 +6966,7 @@ fn thread_from_stored_thread(
|
||||
git_info,
|
||||
name: thread.name,
|
||||
daybreak_enabled: thread.daybreak_enabled,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
turns: Vec::new(),
|
||||
};
|
||||
Ok((thread, history))
|
||||
@@ -7121,16 +7106,14 @@ fn preview_from_rollout_items(items: &[RolloutItem]) -> String {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn build_thread_from_snapshot(
|
||||
thread_id: ThreadId,
|
||||
session_id: String,
|
||||
multi_agent_version: Option<codex_protocol::protocol::MultiAgentVersion>,
|
||||
fn build_thread_from_loaded_snapshot(
|
||||
loaded_thread: &CodexThread,
|
||||
config_snapshot: &ThreadConfigSnapshot,
|
||||
path: Option<PathBuf>,
|
||||
) -> Result<Thread, JSONRPCErrorError> {
|
||||
let now = time::OffsetDateTime::now_utc().unix_timestamp();
|
||||
let metadata = loaded_thread.startup_metadata();
|
||||
Ok(Thread {
|
||||
id: thread_id.to_string(),
|
||||
id: metadata.thread_id.to_string(),
|
||||
environments: Some(
|
||||
config_snapshot
|
||||
.environment_selections()
|
||||
@@ -7139,7 +7122,7 @@ fn build_thread_from_snapshot(
|
||||
.collect(),
|
||||
),
|
||||
extra: None,
|
||||
session_id,
|
||||
session_id: metadata.session_id.to_string(),
|
||||
forked_from_id: None,
|
||||
attached_to_thread_id: None,
|
||||
parent_thread_id: config_snapshot.parent_thread_id.map(|id| id.to_string()),
|
||||
@@ -7156,7 +7139,7 @@ fn build_thread_from_snapshot(
|
||||
updated_at: now,
|
||||
recency_at: Some(now),
|
||||
status: ThreadStatus::NotLoaded,
|
||||
path,
|
||||
path: loaded_thread.rollout_path(),
|
||||
cwd: thread_cwd_for_api(config_snapshot.cwd())?,
|
||||
cli_version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
originator: (!config_snapshot.originator.is_empty())
|
||||
@@ -7165,13 +7148,16 @@ fn build_thread_from_snapshot(
|
||||
agent_role: config_snapshot.session_source.get_agent_role(),
|
||||
source: config_snapshot.session_source.clone().into(),
|
||||
can_accept_direct_input: Some(can_accept_direct_input(
|
||||
multi_agent_version,
|
||||
loaded_thread.multi_agent_version(),
|
||||
&config_snapshot.session_source,
|
||||
)),
|
||||
thread_source: config_snapshot.thread_source.clone().map(Into::into),
|
||||
git_info: None,
|
||||
name: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: Some(
|
||||
loaded_thread.daybreak_program_propagation_enrolled(),
|
||||
),
|
||||
turns: Vec::new(),
|
||||
})
|
||||
}
|
||||
@@ -7204,20 +7190,6 @@ fn paginate_background_terminals(
|
||||
Ok((terminals[start..end].to_vec(), next_cursor))
|
||||
}
|
||||
|
||||
fn build_thread_from_loaded_snapshot(
|
||||
thread_id: ThreadId,
|
||||
config_snapshot: &ThreadConfigSnapshot,
|
||||
loaded_thread: &CodexThread,
|
||||
) -> Result<Thread, JSONRPCErrorError> {
|
||||
build_thread_from_snapshot(
|
||||
thread_id,
|
||||
loaded_thread.startup_metadata().session_id.to_string(),
|
||||
loaded_thread.multi_agent_version(),
|
||||
config_snapshot,
|
||||
loaded_thread.rollout_path(),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "thread_processor_tests.rs"]
|
||||
mod thread_processor_tests;
|
||||
|
||||
@@ -233,6 +233,7 @@ mod tests {
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "mock_provider".to_string(),
|
||||
model: None,
|
||||
|
||||
@@ -308,6 +308,7 @@ pub(crate) fn summary_to_thread(
|
||||
git_info,
|
||||
name: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,36 @@ pub use test_app_server::DEFAULT_CLIENT_NAME;
|
||||
pub use test_app_server::TestAppServer;
|
||||
pub use test_app_server::TestAppServerBuilder;
|
||||
|
||||
pub const CLEARED_OPENAI_AUTH_ENV: &[(&str, Option<&str>)] = &[
|
||||
(codex_login::OPENAI_API_KEY_ENV_VAR, None),
|
||||
(codex_login::CODEX_API_KEY_ENV_VAR, None),
|
||||
(codex_login::CODEX_ACCESS_TOKEN_ENV_VAR, None),
|
||||
(
|
||||
codex_protocol::shell_environment::OPENAI_FEDERATION_RULE_ID_ENV_VAR,
|
||||
None,
|
||||
),
|
||||
(
|
||||
codex_protocol::shell_environment::OPENAI_IDENTITY_TOKEN_FILE_ENV_VAR,
|
||||
None,
|
||||
),
|
||||
(
|
||||
codex_protocol::shell_environment::OPENAI_IDENTITY_TOKEN_SOURCE_ENV_VAR,
|
||||
None,
|
||||
),
|
||||
(
|
||||
codex_protocol::shell_environment::OPENAI_SPIFFE_AUDIENCE_ENV_VAR,
|
||||
None,
|
||||
),
|
||||
(
|
||||
codex_protocol::shell_environment::OPENAI_SPIFFE_ID_ENV_VAR,
|
||||
None,
|
||||
),
|
||||
(
|
||||
codex_protocol::shell_environment::OPENAI_WORKLOAD_IDENTITY_CONTEXT_ENV_VAR,
|
||||
None,
|
||||
),
|
||||
];
|
||||
|
||||
pub fn to_response<T: DeserializeOwned>(response: JSONRPCResponse) -> anyhow::Result<T> {
|
||||
let value = serde_json::to_value(response.result)?;
|
||||
let codex_response = serde_json::from_value(value)?;
|
||||
|
||||
@@ -1397,6 +1397,7 @@ async fn skills_changed_notification_is_emitted_after_skill_change() -> Result<(
|
||||
thread_source: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
dynamic_tools: None,
|
||||
environments: None,
|
||||
selected_capability_roots: None,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use app_test_support::CLEARED_OPENAI_AUTH_ENV;
|
||||
use app_test_support::ChatGptAuthFixture;
|
||||
use app_test_support::PathBufExt;
|
||||
use app_test_support::TestAppServer;
|
||||
@@ -25,13 +26,23 @@ use codex_app_server_protocol::SandboxPolicy;
|
||||
use codex_app_server_protocol::ServerNotification;
|
||||
use codex_app_server_protocol::TextPosition;
|
||||
use codex_app_server_protocol::TextRange;
|
||||
use codex_app_server_protocol::ThreadClosedNotification;
|
||||
use codex_app_server_protocol::ThreadHistoryMode;
|
||||
use codex_app_server_protocol::ThreadListResponse;
|
||||
use codex_app_server_protocol::ThreadMetadataUpdateParams;
|
||||
use codex_app_server_protocol::ThreadMetadataUpdateResponse;
|
||||
use codex_app_server_protocol::ThreadReadParams;
|
||||
use codex_app_server_protocol::ThreadReadResponse;
|
||||
use codex_app_server_protocol::ThreadResumeParams;
|
||||
use codex_app_server_protocol::ThreadResumeResponse;
|
||||
use codex_app_server_protocol::ThreadSource;
|
||||
use codex_app_server_protocol::ThreadStartParams;
|
||||
use codex_app_server_protocol::ThreadStartResponse;
|
||||
use codex_app_server_protocol::ThreadStartedNotification;
|
||||
use codex_app_server_protocol::ThreadStatus;
|
||||
use codex_app_server_protocol::ThreadStatusChangedNotification;
|
||||
use codex_app_server_protocol::ThreadUnsubscribeParams;
|
||||
use codex_app_server_protocol::ThreadUnsubscribeResponse;
|
||||
use codex_app_server_protocol::TurnEnvironmentParams;
|
||||
use codex_app_server_protocol::TurnStartParams;
|
||||
use codex_app_server_protocol::UserInput as V2UserInput;
|
||||
@@ -94,6 +105,148 @@ async fn start_thread_with_model(
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_start_reports_actual_daybreak_enrollment() -> Result<()> {
|
||||
#[derive(Debug)]
|
||||
enum Policy {
|
||||
Enabled,
|
||||
Required,
|
||||
Disabled,
|
||||
}
|
||||
|
||||
let responses = create_mock_responses_server_repeating_assistant("Done").await;
|
||||
for policy in [Policy::Enabled, Policy::Required, Policy::Disabled] {
|
||||
let codex_home = TempDir::new()?;
|
||||
let enabled = !matches!(policy, Policy::Disabled);
|
||||
create_config_toml(
|
||||
codex_home.path(),
|
||||
&responses.uri(),
|
||||
"thread_unload_delay_secs = 0",
|
||||
&format!("[features]\ndaybreak_program_propagation = {enabled}"),
|
||||
)?;
|
||||
if matches!(policy, Policy::Required) {
|
||||
std::fs::write(
|
||||
codex_home.path().join("requirements.toml"),
|
||||
"[features]\ndaybreak_program_propagation = true\n",
|
||||
)?;
|
||||
}
|
||||
let mut server = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
.with_env_overrides(CLEARED_OPENAI_AUTH_ENV)
|
||||
.with_env_overrides(&[("CODEX_SQLITE_HOME", None)])
|
||||
.build_initialized()
|
||||
.await?;
|
||||
let cases: &[(Option<bool>, bool)] = match policy {
|
||||
Policy::Enabled => &[(None, true), (Some(false), false), (Some(true), true)],
|
||||
Policy::Required => &[(Some(false), true)],
|
||||
Policy::Disabled => &[(Some(true), false)],
|
||||
};
|
||||
for &(requested, expected) in cases {
|
||||
let started = server
|
||||
.start_thread(ThreadStartParams {
|
||||
thread_source: Some(ThreadSource::User),
|
||||
daybreak_program_propagation_enrolled: requested,
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(
|
||||
started.thread.daybreak_program_propagation_enrolled,
|
||||
Some(expected),
|
||||
"policy {policy:?}, requested {requested:?}"
|
||||
);
|
||||
if !matches!(policy, Policy::Enabled) || requested.is_none() {
|
||||
continue;
|
||||
}
|
||||
let thread_id = started.thread.id;
|
||||
timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
server.start_turn_and_wait_for_completion(TurnStartParams {
|
||||
thread_id: thread_id.clone(),
|
||||
input: vec![V2UserInput::Text {
|
||||
text: "hello".into(),
|
||||
text_elements: vec![],
|
||||
}],
|
||||
..Default::default()
|
||||
}),
|
||||
)
|
||||
.await??;
|
||||
|
||||
let read = |request_id| ClientRequest::ThreadRead {
|
||||
request_id,
|
||||
params: ThreadReadParams {
|
||||
thread_id: thread_id.clone(),
|
||||
include_turns: false,
|
||||
},
|
||||
};
|
||||
let resume = |request_id| ClientRequest::ThreadResume {
|
||||
request_id,
|
||||
params: ThreadResumeParams {
|
||||
thread_id: thread_id.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
let live: ThreadReadResponse = server.request(read).await?;
|
||||
assert_eq!(
|
||||
live.thread.daybreak_program_propagation_enrolled,
|
||||
Some(expected)
|
||||
);
|
||||
let updated: ThreadMetadataUpdateResponse = server
|
||||
.request(|request_id| ClientRequest::ThreadMetadataUpdate {
|
||||
request_id,
|
||||
params: ThreadMetadataUpdateParams {
|
||||
thread_id: thread_id.clone(),
|
||||
project_id: None,
|
||||
git_info: None,
|
||||
daybreak_enabled: Some(true),
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(
|
||||
updated.thread.daybreak_program_propagation_enrolled,
|
||||
Some(expected)
|
||||
);
|
||||
let resumed: ThreadResumeResponse = server.request(resume).await?;
|
||||
assert_eq!(
|
||||
resumed.thread.daybreak_program_propagation_enrolled,
|
||||
Some(expected)
|
||||
);
|
||||
let list_id = server
|
||||
.send_raw_request("thread/list", Some(json!({})))
|
||||
.await?;
|
||||
let list: ThreadListResponse =
|
||||
timeout(DEFAULT_READ_TIMEOUT, server.read_response(list_id)).await??;
|
||||
let listed = list
|
||||
.data
|
||||
.iter()
|
||||
.find(|thread| thread.id == thread_id)
|
||||
.context("started thread absent from list")?;
|
||||
assert_eq!(listed.daybreak_program_propagation_enrolled, Some(expected));
|
||||
|
||||
let _: ThreadUnsubscribeResponse = server
|
||||
.request(|request_id| ClientRequest::ThreadUnsubscribe {
|
||||
request_id,
|
||||
params: ThreadUnsubscribeParams {
|
||||
thread_id: thread_id.clone(),
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadClosedNotification = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
server.read_notification("thread/closed"),
|
||||
)
|
||||
.await??;
|
||||
let stored: ThreadReadResponse = server.request(read).await?;
|
||||
assert_eq!(stored.thread.daybreak_program_propagation_enrolled, None);
|
||||
let cold: ThreadResumeResponse = server.request(resume).await?;
|
||||
assert_eq!(
|
||||
cold.thread.daybreak_program_propagation_enrolled,
|
||||
Some(false)
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_start_provider_model_fallback_applies_to_configured_model() -> Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
|
||||
@@ -16,6 +16,9 @@ pub(crate) enum Enrollment {
|
||||
NativeHelper,
|
||||
}
|
||||
|
||||
/// Request that a speculative root opt out of the propagation experiment.
|
||||
pub(crate) struct PreventRootEnrollment;
|
||||
|
||||
/// The saved choice and the account under which the choice was observed.
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct SavedIntent {
|
||||
|
||||
@@ -1336,6 +1336,13 @@ impl CodexThread {
|
||||
&self.startup_metadata
|
||||
}
|
||||
|
||||
/// Whether this live thread joined the Daybreak propagation experiment at startup.
|
||||
pub fn daybreak_program_propagation_enrolled(&self) -> bool {
|
||||
self.thread_extension_data()
|
||||
.get::<crate::agent::helper_daybreak::Enrollment>()
|
||||
.is_some()
|
||||
}
|
||||
|
||||
pub(crate) fn is_running(&self) -> bool {
|
||||
!self.io.tx_sub.is_closed()
|
||||
}
|
||||
|
||||
@@ -121,6 +121,10 @@ impl ManagedFeatures {
|
||||
self.value.get()
|
||||
}
|
||||
|
||||
pub(crate) fn required_value(&self, feature: Feature) -> Option<bool> {
|
||||
self.pinned_features.get(&feature).copied()
|
||||
}
|
||||
|
||||
fn normalize_and_validate(&self, candidate: Features) -> ConstraintResult<Features> {
|
||||
let normalized = normalize_candidate(candidate, &self.pinned_features);
|
||||
self.value.can_set(&normalized)?;
|
||||
@@ -160,8 +164,8 @@ impl ManagedFeatures {
|
||||
Feature::McpOAuthRefreshCoordination,
|
||||
] {
|
||||
values.set_enabled(feature, next.enabled(feature));
|
||||
if let Some(enabled) = next.pinned_features.get(&feature) {
|
||||
refreshed.pinned_features.insert(feature, *enabled);
|
||||
if let Some(enabled) = next.required_value(feature) {
|
||||
refreshed.pinned_features.insert(feature, enabled);
|
||||
} else {
|
||||
refreshed.pinned_features.remove(&feature);
|
||||
}
|
||||
|
||||
@@ -1075,6 +1075,9 @@ impl Session {
|
||||
Arc::default()
|
||||
}
|
||||
});
|
||||
let prevent_root_enrollment = thread_extension_init
|
||||
.remove::<crate::agent::helper_daybreak::PreventRootEnrollment>()
|
||||
.is_some();
|
||||
let mcp_thread_init = thread_extension_init.clone();
|
||||
let thread_extension_data = codex_extension_api::ExtensionData::new_with_init(
|
||||
thread_id.to_string(),
|
||||
@@ -1099,6 +1102,11 @@ impl Session {
|
||||
InitialHistory::New | InitialHistory::Cleared
|
||||
) && !session_source.is_non_root_agent()
|
||||
&& config.features.enabled(Feature::DaybreakProgramPropagation)
|
||||
&& (!prevent_root_enrollment
|
||||
|| config
|
||||
.features
|
||||
.required_value(Feature::DaybreakProgramPropagation)
|
||||
== Some(true))
|
||||
{
|
||||
thread_extension_data.insert(crate::agent::helper_daybreak::Enrollment::Root);
|
||||
}
|
||||
|
||||
@@ -360,6 +360,8 @@ pub enum PromptCacheKey {
|
||||
|
||||
pub struct StartThreadOptions {
|
||||
pub config: Config,
|
||||
/// Opt out of root enrollment unless managed policy requires propagation.
|
||||
pub prevent_daybreak_program_propagation_enrollment: bool,
|
||||
/// Trusted host country for the initial thread settings.
|
||||
pub request_country: codex_protocol::RequestCountry,
|
||||
/// Request-body cache key policy for this thread and its children. Hosts must reapply it on cold resume.
|
||||
@@ -459,6 +461,7 @@ impl StartThreadOptions {
|
||||
pub fn new(config: Config) -> Self {
|
||||
Self {
|
||||
config,
|
||||
prevent_daybreak_program_propagation_enrollment: false,
|
||||
request_country: codex_protocol::RequestCountry::default(),
|
||||
prompt_cache_key: PromptCacheKey::default(),
|
||||
thread_instructions_provider: None,
|
||||
@@ -2659,6 +2662,7 @@ impl ThreadManagerState {
|
||||
};
|
||||
let StartThreadOptions {
|
||||
mut config,
|
||||
prevent_daybreak_program_propagation_enrollment,
|
||||
request_country,
|
||||
prompt_cache_key,
|
||||
thread_instructions_provider,
|
||||
@@ -2682,6 +2686,9 @@ impl ThreadManagerState {
|
||||
mut reserved_thread_id,
|
||||
disabled_plugin_ids,
|
||||
} = options;
|
||||
if prevent_daybreak_program_propagation_enrollment {
|
||||
thread_extension_init.insert(crate::agent::helper_daybreak::PreventRootEnrollment);
|
||||
}
|
||||
if resume_preparation.is_some()
|
||||
&& (config.ephemeral || !matches!(&initial_history, InitialHistory::Resumed(_)))
|
||||
{
|
||||
|
||||
@@ -144,6 +144,7 @@ async fn paused_helpers(
|
||||
let mut config = test_config().await;
|
||||
config.codex_home = home.abs();
|
||||
config.cwd = home.abs();
|
||||
config.sqlite = codex_state::SqliteConfig::new_for_testing(home.abs());
|
||||
config.agent_max_depth = 2;
|
||||
config.model_provider.supports_websockets = false;
|
||||
config.model_provider.base_url = Some("http://127.0.0.1:9/v1".to_owned());
|
||||
@@ -180,6 +181,46 @@ async fn paused_helpers(
|
||||
(config, manager, turns)
|
||||
}
|
||||
|
||||
#[test_case::test_case(false; "enrolled root")]
|
||||
#[test_case::test_case(true; "opted out root")]
|
||||
#[tokio::test]
|
||||
async fn root_opt_out_controls_native_helper_inheritance(prevent: bool) -> anyhow::Result<()> {
|
||||
let home = tempdir()?;
|
||||
let (config, manager, mut turns) = paused_helpers(home.path(), /*programs*/ None).await;
|
||||
let root = manager
|
||||
.start_thread(StartThreadOptions {
|
||||
prevent_daybreak_program_propagation_enrollment: prevent,
|
||||
..StartThreadOptions::new(config.clone())
|
||||
})
|
||||
.await?;
|
||||
assert!(root.thread.enabled(Feature::DaybreakProgramPropagation));
|
||||
assert_eq!(
|
||||
root.thread.daybreak_program_propagation_enrolled(),
|
||||
!prevent
|
||||
);
|
||||
save_choice(&root.thread, /*enabled*/ true).await;
|
||||
root.thread
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(text()))
|
||||
.await?;
|
||||
let root_turn = admitted_turn(&mut turns, &root.thread).await;
|
||||
let child = spawn_child(
|
||||
&manager,
|
||||
&config,
|
||||
&root.thread,
|
||||
&root_turn,
|
||||
SpawnProgramSource::ParentTurn,
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(child.daybreak_program_propagation_enrolled(), !prevent);
|
||||
let child_turn = admitted_turn(&mut turns, &child).await;
|
||||
let expected = (!prevent).then_some(SavedDaybreakChoice::On);
|
||||
assert_eq!(saved(child.thread_extension_data()), expected);
|
||||
assert_eq!(saved(&child_turn.extension_data), expected);
|
||||
child.shutdown_and_wait().await?;
|
||||
root.thread.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case(Some(false), None, None; "saved off")]
|
||||
#[test_case::test_case(None, Some(false), None; "pending off before materialization")]
|
||||
#[test_case::test_case(None, None, None; "unset")]
|
||||
|
||||
@@ -366,6 +366,7 @@ fn turn_items_for_thread_returns_matching_turn_items() {
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "openai".to_string(),
|
||||
model: None,
|
||||
@@ -887,6 +888,7 @@ fn sample_thread_start_response() -> ThreadStartResponse {
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "openai".to_string(),
|
||||
model: None,
|
||||
|
||||
@@ -772,6 +772,7 @@ pub(in crate::app) fn overview_thread(
|
||||
extra: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
session_id: parent_thread_id.unwrap_or(thread_id).to_string(),
|
||||
forked_from_id: None,
|
||||
attached_to_thread_id: None,
|
||||
|
||||
@@ -149,6 +149,7 @@ mod tests {
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "openai".to_string(),
|
||||
model: None,
|
||||
|
||||
@@ -7630,6 +7630,7 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> Re
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: Some(true),
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "openai".to_string(),
|
||||
model: Some("gpt-agent".to_string()),
|
||||
@@ -7750,6 +7751,7 @@ async fn inactive_thread_started_notification_preserves_primary_model_when_path_
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "agent-provider".to_string(),
|
||||
model: None,
|
||||
@@ -7825,6 +7827,7 @@ async fn thread_read_session_state_does_not_reuse_primary_permission_profile() {
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "read-provider".to_string(),
|
||||
model: Some("server-reported-model".to_string()),
|
||||
|
||||
@@ -1314,6 +1314,7 @@ async fn known_thread_started_preserves_session_without_reading_unmaterialized_r
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "notification-provider".to_string(),
|
||||
model: None,
|
||||
|
||||
@@ -453,6 +453,7 @@ mod tests {
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "read-provider".to_string(),
|
||||
model: None,
|
||||
|
||||
@@ -5251,6 +5251,7 @@ mod tests {
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: "openai".to_string(),
|
||||
model: None,
|
||||
|
||||
@@ -7735,6 +7735,7 @@ session_picker_view = "dense"
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: String::from("openai"),
|
||||
model: None,
|
||||
@@ -7783,6 +7784,7 @@ session_picker_view = "dense"
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: String::from("openai"),
|
||||
model: None,
|
||||
@@ -7886,6 +7888,7 @@ session_picker_view = "dense"
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: String::from("openai"),
|
||||
model: None,
|
||||
@@ -7966,6 +7969,7 @@ session_picker_view = "dense"
|
||||
section_entered_at: None,
|
||||
project_id: None,
|
||||
daybreak_enabled: None,
|
||||
daybreak_program_propagation_enrolled: None,
|
||||
history_mode: Default::default(),
|
||||
model_provider: String::from("openai"),
|
||||
model: None,
|
||||
|
||||
Reference in New Issue
Block a user