mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Add per-turn Cyber access program selection to exec and the SDK (#49939)
## Why `codex exec` and the TypeScript SDK need a way to request a Cyber access program for an individual turn. Resuming with an API key can also leave compaction using a saved program that the current credentials cannot access. ## What changed - Add `--cyber-access-program` with `standard`, `daybreak_blue`, and `daybreak_red`, and expose the equivalent `cyberAccessProgram` turn option and `CyberAccessProgram` type in the TypeScript SDK. - Apply explicit selections to new, resumed, and prompted fork turns. Override automatic Daybreak selection for that turn without changing the saved choice. Reject the flag for review and forks without a prompt. - Filter Cyber programs by the built-in OpenAI provider when starting turns and restoring previous-turn settings for compaction. - Allow previous-model compaction fallback with API-key authentication, comparing both model and program so a program change can trigger a retry with the current pair even when the model is unchanged. ## Testing Add CLI help, argument parsing, exec, and SDK coverage for per-turn selection and unsupported commands. Extend core tests for API-key compaction retries, denied explicit selections, custom-provider filtering, remote compaction, and WebSocket response reuse. GitOrigin-RevId: 586f25b621924f3bc509c9a39b39fe2020ff9cd2
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
use codex_api::AccessPrograms;
|
||||
use codex_features::Feature;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_model_provider_info::OPENAI_PROVIDER_ID;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::Result;
|
||||
use codex_protocol::turn_input::CyberAccessProgram;
|
||||
@@ -16,7 +17,7 @@ pub(crate) enum ApiKeyCyberAccessPrograms {
|
||||
|
||||
impl ApiKeyCyberAccessPrograms {
|
||||
pub(crate) fn from_config(config: &crate::config::Config) -> Self {
|
||||
if config.model_provider_id != codex_model_provider_info::OPENAI_PROVIDER_ID {
|
||||
if config.model_provider_id != OPENAI_PROVIDER_ID {
|
||||
Self::UnsupportedProvider
|
||||
} else if config.features.enabled(Feature::ApiKeyCyberAccessPrograms) {
|
||||
Self::Enabled
|
||||
@@ -26,6 +27,13 @@ impl ApiKeyCyberAccessPrograms {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn for_provider(
|
||||
provider_id: &str,
|
||||
program: Option<CyberAccessProgram>,
|
||||
) -> Option<CyberAccessProgram> {
|
||||
program.filter(|_| provider_id == OPENAI_PROVIDER_ID)
|
||||
}
|
||||
|
||||
pub(crate) fn for_auth(
|
||||
auth: Option<&CodexAuth>,
|
||||
program: Option<CyberAccessProgram>,
|
||||
|
||||
@@ -12,6 +12,7 @@ use crate::compact_remote_v2::run_inline_remote_auto_compact_task as run_inline_
|
||||
use crate::connectors;
|
||||
use crate::context::ContextualUserFragment;
|
||||
use crate::context::UserVerificationNotice;
|
||||
use crate::cyber_access_program;
|
||||
use crate::environment_selection::TurnEnvironmentSnapshot;
|
||||
use crate::feedback_tags;
|
||||
use crate::hook_runtime::drain_async_hook_results;
|
||||
@@ -1335,21 +1336,23 @@ fn comp_hash_changed(previous: Option<&str>, current: Option<&str>) -> bool {
|
||||
|
||||
/// Captures the current model's request-scoped state for retrying previous-model compaction.
|
||||
///
|
||||
/// Returns `None` when the active authentication does not use the Codex backend, the provider is
|
||||
/// not OpenAI, or the previous and current model are the same.
|
||||
/// Returns `None` when auth uses neither the Codex backend nor an API key, the provider is
|
||||
/// not OpenAI, or the previous and current model/program pairs are the same.
|
||||
async fn capture_current_model_fallback_step_context(
|
||||
sess: &Arc<Session>,
|
||||
turn_context: &Arc<TurnContext>,
|
||||
previous_model: &str,
|
||||
previous_turn_context: &TurnContext,
|
||||
cancellation_token: &CancellationToken,
|
||||
) -> CodexResult<Option<Arc<StepContext>>> {
|
||||
let uses_codex_backend = turn_context
|
||||
let supports_fallback = turn_context
|
||||
.auth_manager
|
||||
.as_deref()
|
||||
.is_some_and(codex_login::AuthManager::current_auth_uses_codex_backend);
|
||||
if !uses_codex_backend
|
||||
.and_then(codex_login::AuthManager::auth_cached)
|
||||
.is_some_and(|auth| auth.uses_codex_backend() || auth.is_api_key_auth());
|
||||
if !supports_fallback
|
||||
|| !turn_context.provider.info().is_openai()
|
||||
|| previous_model == turn_context.model_info().slug
|
||||
|| (previous_turn_context.model_info().slug == turn_context.model_info().slug
|
||||
&& previous_turn_context.cyber_access_program == turn_context.cyber_access_program)
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -1386,7 +1389,10 @@ async fn maybe_run_previous_model_inline_compact(
|
||||
// turn's program so compaction uses the same model/cyber_access_program pair as that turn.
|
||||
// Combining the previous model with the current turn's program can produce a pair
|
||||
// that the server rejects.
|
||||
previous_model_turn_context.cyber_access_program = previous_turn_settings.cyber_access_program;
|
||||
previous_model_turn_context.cyber_access_program = cyber_access_program::for_provider(
|
||||
&previous_model_turn_context.config.model_provider_id,
|
||||
previous_turn_settings.cyber_access_program,
|
||||
);
|
||||
let previous_model_turn_context = Arc::new(previous_model_turn_context);
|
||||
|
||||
if should_compact_for_comp_hash_change {
|
||||
@@ -1396,7 +1402,7 @@ async fn maybe_run_previous_model_inline_compact(
|
||||
let fallback_step_context = capture_current_model_fallback_step_context(
|
||||
sess,
|
||||
turn_context,
|
||||
previous_model.as_str(),
|
||||
&previous_model_turn_context,
|
||||
cancellation_token,
|
||||
)
|
||||
.await?;
|
||||
@@ -1444,7 +1450,7 @@ async fn maybe_run_previous_model_inline_compact(
|
||||
let fallback_step_context = capture_current_model_fallback_step_context(
|
||||
sess,
|
||||
turn_context,
|
||||
previous_model.as_str(),
|
||||
&previous_model_turn_context,
|
||||
cancellation_token,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -3,6 +3,7 @@ use super::token_budget::has_explicit_settings;
|
||||
use super::token_budget::resolve_token_budget;
|
||||
use super::*;
|
||||
use crate::config::TokenBudgetConfig;
|
||||
use crate::cyber_access_program;
|
||||
use crate::environment_selection::EnvironmentConfigOrigin;
|
||||
use crate::environment_selection::TurnEnvironmentSnapshot;
|
||||
use crate::exec_policy::AllowPrefixRules;
|
||||
@@ -1439,9 +1440,10 @@ impl Session {
|
||||
turn_context.realtime_active = self.conversation.running_state().await.is_some();
|
||||
|
||||
turn_context.final_output_json_schema = options.final_output_json_schema;
|
||||
if turn_context.config.model_provider_id == codex_model_provider_info::OPENAI_PROVIDER_ID {
|
||||
turn_context.cyber_access_program = options.cyber_access_program;
|
||||
}
|
||||
turn_context.cyber_access_program = cyber_access_program::for_provider(
|
||||
&turn_context.config.model_provider_id,
|
||||
options.cyber_access_program,
|
||||
);
|
||||
let turn_context = Arc::new(turn_context);
|
||||
if git_enrichment_policy == GitEnrichmentPolicy::Fresh
|
||||
&& turn_context
|
||||
|
||||
Reference in New Issue
Block a user