Allow setting daybreakEnabled when starting a thread (#45513)

## What changed

Add experimental `thread/start.daybreakEnabled` so clients can set the initial preference for persistent threads. Omitted or null values leave it unset; explicit values are rejected for ephemeral threads.

Return the choice in the start response, `thread/started`, and reads before persistence. Stage it with the initial thread metadata and save it when the thread is persisted. Later changes still use `thread/metadata/update`. The preference does not select `turn/start.cyberAccessProgram` or grant access.

## Testing

Add coverage for true, false, and unset values in responses, notifications, reads, and reads after persistence and restart, plus rejection for ephemeral threads. Update existing metadata and access-program tests to exercise threads with an initial preference.

GitOrigin-RevId: 3bff3dc55a18436067bc2a3f156f5abf52d7321b
This commit is contained in:
faizan-oai authored and copyberry committed 2026-09-14 20:57:48 +00:00
1 parent ea3c4848d8
commit ef8b356c22
8 files changed
+181 -4

No files matched your search

@@ -4,6 +4,8 @@ use app_test_support::TestAppServer;
use app_test_support::write_chatgpt_auth;
use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::CyberAccessProgram;
use codex_app_server_protocol::JSONRPCErrorError;
use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::ThreadForkParams;
use codex_app_server_protocol::ThreadForkResponse;
use codex_app_server_protocol::ThreadMetadataUpdateParams;
@@ -13,6 +15,7 @@ use codex_app_server_protocol::ThreadReadResponse;
use codex_app_server_protocol::ThreadResumeParams;
use codex_app_server_protocol::ThreadResumeResponse;
use codex_app_server_protocol::ThreadStartParams;
use codex_app_server_protocol::ThreadStartedNotification;
use codex_app_server_protocol::TurnStartParams;
use codex_app_server_protocol::TurnStatus;
use codex_app_server_protocol::UserInput;
@@ -29,6 +32,102 @@ use wiremock::matchers::header;
use wiremock::matchers::method;
use wiremock::matchers::path;
#[tokio::test]
async fn thread_start_stages_daybreak_until_persistence() -> Result<()> {
core_test_support::skip_if_no_network!(Ok(()));
let server = responses::start_mock_server().await;
responses::mount_sse_sequence(
&server,
(0..3)
.map(|index| responses::sse(vec![responses::ev_completed(&format!("resp-{index}"))]))
.collect(),
)
.await;
let home = TempDir::new()?;
let mut app = start_chatgpt_app(home.path(), &server).await?;
let mut threads = Vec::new();
for daybreak_enabled in [Some(true), Some(false), None] {
let started = app
.start_thread(ThreadStartParams {
daybreak_enabled,
..Default::default()
})
.await?;
assert_eq!(started.thread.daybreak_enabled, daybreak_enabled);
let notification: ThreadStartedNotification =
app.read_notification("thread/started").await?;
assert_eq!(notification.thread, started.thread);
let read: ThreadReadResponse = app
.request(|request_id| ClientRequest::ThreadRead {
request_id,
params: ThreadReadParams {
thread_id: started.thread.id.clone(),
include_turns: false,
},
})
.await?;
assert_eq!(read.thread.daybreak_enabled, daybreak_enabled);
let completed = app
.start_turn_and_wait_for_completion(TurnStartParams {
thread_id: started.thread.id.clone(),
input: vec![UserInput::Text {
text: "start this task".to_owned(),
text_elements: Vec::new(),
}],
..Default::default()
})
.await?;
assert_eq!(completed.turn.status, TurnStatus::Completed);
threads.push((started.thread.id, daybreak_enabled));
}
app.shutdown_gracefully().await?;
let mut restarted = start_chatgpt_app(home.path(), &server).await?;
for (thread_id, daybreak_enabled) in threads {
let read: ThreadReadResponse = restarted
.request(|request_id| ClientRequest::ThreadRead {
request_id,
params: ThreadReadParams {
thread_id: thread_id.clone(),
include_turns: false,
},
})
.await?;
assert_eq!(
(read.thread.id, read.thread.daybreak_enabled),
(thread_id, daybreak_enabled)
);
}
Ok(())
}
#[tokio::test]
async fn thread_start_rejects_daybreak_for_ephemeral_threads() -> Result<()> {
core_test_support::skip_if_no_network!(Ok(()));
let server = responses::start_mock_server().await;
let home = TempDir::new()?;
let mut app = start_chatgpt_app(home.path(), &server).await?;
let request_id = app
.send_thread_start_request_with_auto_env(ThreadStartParams {
daybreak_enabled: Some(true),
ephemeral: Some(true),
..Default::default()
})
.await?;
let error = app
.read_stream_until_error_message(RequestId::Integer(request_id))
.await?;
assert_eq!(
error.error,
JSONRPCErrorError {
code: -32600,
message: "daybreakEnabled is not supported for ephemeral threads".to_owned(),
data: None,
}
);
Ok(())
}
#[tokio::test]
async fn turn_start_forwards_explicit_cyber_access_program() -> Result<()> {
core_test_support::skip_if_no_network!(Ok(()));
@@ -54,7 +153,13 @@ async fn turn_start_forwards_explicit_cyber_access_program() -> Result<()> {
.await;
let home = TempDir::new()?;
let mut app = start_chatgpt_app(home.path(), &server).await?;
let thread = app.start_thread(ThreadStartParams::default()).await?.thread;
let thread = app
.start_thread(ThreadStartParams {
daybreak_enabled: Some(true),
..Default::default()
})
.await?
.thread;
for program in programs {
let completed = app
.start_turn_and_wait_for_completion(TurnStartParams {
@@ -100,14 +205,24 @@ async fn daybreak_thread_metadata_persists_independently_across_restart_and_fork
.await;
let home = TempDir::new()?;
let mut app = start_chatgpt_app(home.path(), &server).await?;
let first = app.start_thread(ThreadStartParams::default()).await?;
let second = app.start_thread(ThreadStartParams::default()).await?;
let first = app
.start_thread(ThreadStartParams {
daybreak_enabled: Some(false),
..Default::default()
})
.await?;
let second = app
.start_thread(ThreadStartParams {
daybreak_enabled: Some(true),
..Default::default()
})
.await?;
assert_eq!(
(
first.thread.daybreak_enabled,
second.thread.daybreak_enabled
),
(None, None)
(Some(false), Some(true))
);
for (thread_id, enabled) in [(&first.thread.id, true), (&second.thread.id, false)] {