Preserve the saved Daybreak choice across live goal continuations (#63809)

## Why

Automatic goal continuations could lose the thread's saved Daybreak
choice, even when the thread was enrolled in Daybreak propagation.

## What changed

Capture the saved choice when an externally created live goal first
becomes active. For goals created by a tool, carry forward the
originating turn's choice and preserve explicit access program
overrides.

Keep the captured choice in memory for the life of the goal and check
it against the current account and model on continuation. Changing
the thread's Daybreak setting takes effect for new goals.

## Testing

Add coverage for enrolled and opted-out threads, including blocking
a goal when the model lacks Daybreak support and starting a new goal
after turning Daybreak off. Also cover account changes and isolation
from foreground turns.

GitOrigin-RevId: 0baf08f06baf267595cb5a2b3b1fe033db52ad06
This commit is contained in:
jamy-OAI
2026-11-25 02:31:14 +00:00
committed by copyberry
parent 19e95b9be8
commit 986a6b3b11
15 changed files with 617 additions and 88 deletions
@@ -365,6 +365,7 @@ pub(crate) struct NewTurnContextOptions {
pub(crate) prompt_cache_ttl: Option<crate::PromptCacheTtl>,
pub(crate) cyber_access_program: Option<CyberAccessProgram>,
pub(crate) helper_admission: Option<crate::agent::helper_daybreak::turn::HelperTurnAdmission>,
pub(crate) goal_daybreak: Option<crate::GoalDaybreakSnapshot>,
}
/// The context needed for a single turn of the thread.
@@ -1530,6 +1531,9 @@ impl Session {
if let Some(admission) = options.helper_admission {
admission.capture_intent(self, &mut turn_context).await;
}
if let Some(snapshot) = options.goal_daybreak {
snapshot.apply(self, &mut turn_context);
}
// Tool observers retain this turn's selection even after a later turn starts.
if let Some(program) = turn_context.cyber_access_program {
turn_context.extension_data.insert(program);
+20 -2
View File
@@ -25,6 +25,7 @@ use super::thread_settings;
use super::turn_context::NewTurnContextOptions;
use super::turn_context::TurnContext;
use crate::WithTurnExtensionData;
use crate::agent::helper_daybreak::goal::GoalDaybreakAdmission;
use crate::agent::helper_daybreak::turn::HelperTurnAdmission;
use crate::context::ContextualUserFragment;
use crate::context::GuardianSenderMessages;
@@ -109,6 +110,7 @@ impl TurnStartKind {
struct PreparedTurnInputSettings {
thread_settings_update: Option<SessionSettingsUpdate>,
start_options: TurnStartOptions,
goal_daybreak: Option<Arc<GoalDaybreakAdmission>>,
}
impl PreparedTurnInputSettings {
@@ -139,6 +141,7 @@ impl PreparedTurnInputSettings {
Ok(Self {
thread_settings_update,
start_options,
goal_daybreak: None,
})
}
@@ -189,6 +192,7 @@ impl PreparedTurnInputSettings {
prompt_cache_ttl,
cyber_access_program,
helper_admission,
goal_daybreak: self.goal_daybreak.map(|admission| admission.0.clone()),
};
let turn_context = match kind {
TurnStartKind::User | TurnStartKind::Recovery => Some(
@@ -300,12 +304,21 @@ pub(super) async fn handle_realtime_handoff(
)]
async fn handle_inner(
session: &Arc<Session>,
request: WithTurnExtensionData<TurnInputRequest>,
mut request: WithTurnExtensionData<TurnInputRequest>,
mode: TurnInputMode,
submission_id: String,
realtime_handoff_id: Option<uuid::Uuid>,
) -> CodexResult<TurnInputSubmission> {
session.conversation.check_history_recovery()?;
let goal_daybreak = request
.turn_extension_init
.as_mut()
.and_then(codex_extension_api::ExtensionDataInit::remove::<GoalDaybreakAdmission>);
if goal_daybreak.is_some() {
// Only Core's goal-specific idle entry point can supply this attachment.
// It supplies no other data, so consuming it must not clear host defaults.
request.turn_extension_init = None;
}
if request.request.start.service_tier.is_some()
&& crate::agent::host::host_child_uses_shared_service_tier(session)
{
@@ -356,6 +369,7 @@ async fn handle_inner(
kind,
/*expected_previous_turn_id*/ None,
realtime_handoff_id,
goal_daybreak.filter(|_| kind == TurnStartKind::Automatic),
)
.await
}
@@ -384,6 +398,7 @@ async fn handle_inner(
TurnStartKind::Recovery,
Some(expected_previous_turn_id),
realtime_handoff_id,
/*goal_daybreak*/ None,
)
.await
}
@@ -438,6 +453,7 @@ pub(super) async fn handle_recovery(
TurnStartKind::Recovery,
/*expected_previous_turn_id*/ None,
/*realtime_handoff_id*/ None,
/*goal_daybreak*/ None,
)
.await;
if let Ok(TurnInputSubmission::Started { turn_id, .. }) = &result {
@@ -614,6 +630,7 @@ async fn start_if_idle(
kind: TurnStartKind,
expected_previous_turn_id: Option<String>,
realtime_handoff_id: Option<uuid::Uuid>,
goal_daybreak: Option<Arc<GoalDaybreakAdmission>>,
) -> CodexResult<TurnInputSubmission> {
let WithTurnExtensionData {
mut request,
@@ -702,7 +719,7 @@ async fn start_if_idle(
});
}
let settings = match PreparedTurnInputSettings::prepare(
let mut settings = match PreparedTurnInputSettings::prepare(
session,
WithTurnExtensionData {
request: thread_settings,
@@ -718,6 +735,7 @@ async fn start_if_idle(
return Err(error);
}
};
settings.goal_daybreak = goal_daybreak;
let turn_context = match settings
.apply_started(session, submission_id.clone(), kind)
.await