Support initial Codex time context overrides

This commit is contained in:
raju
2026-05-13 21:37:21 -07:00
parent b4ecb42966
commit 50e02cbeb3
19 changed files with 289 additions and 14 deletions
@@ -3763,6 +3763,13 @@
"null"
]
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"type": [
"string",
@@ -3816,6 +3823,13 @@
},
"threadId": {
"type": "string"
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -3938,6 +3952,13 @@
"null"
]
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"type": [
"string",
@@ -4020,6 +4041,13 @@
}
],
"description": "Optional client-supplied analytics source classification for this thread."
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"type": "object"
@@ -4132,6 +4160,13 @@
],
"description": "Override where approval requests are routed for review on this turn and subsequent turns."
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this turn and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"description": "Override the working directory for this turn and subsequent turns.",
"type": [
@@ -4208,6 +4243,13 @@
},
"threadId": {
"type": "string"
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this turn and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -16815,6 +16815,13 @@
"null"
]
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"type": [
"string",
@@ -16868,6 +16875,13 @@
},
"threadId": {
"type": "string"
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -17097,6 +17111,13 @@
"null"
]
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"type": [
"string",
@@ -17179,6 +17200,13 @@
}
],
"description": "Optional client-supplied analytics source classification for this thread."
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"title": "ThreadStartParams",
@@ -17846,6 +17874,13 @@
],
"description": "Override where approval requests are routed for review on this turn and subsequent turns."
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this turn and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"description": "Override the working directory for this turn and subsequent turns.",
"type": [
@@ -17922,6 +17957,13 @@
},
"threadId": {
"type": "string"
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this turn and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -14639,6 +14639,13 @@
"null"
]
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"type": [
"string",
@@ -14692,6 +14699,13 @@
},
"threadId": {
"type": "string"
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -14921,6 +14935,13 @@
"null"
]
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"type": [
"string",
@@ -15003,6 +15024,13 @@
}
],
"description": "Optional client-supplied analytics source classification for this thread."
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"title": "ThreadStartParams",
@@ -15670,6 +15698,13 @@
],
"description": "Override where approval requests are routed for review on this turn and subsequent turns."
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this turn and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"description": "Override the working directory for this turn and subsequent turns.",
"type": [
@@ -15746,6 +15781,13 @@
},
"threadId": {
"type": "string"
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this turn and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -1048,6 +1048,13 @@
"null"
]
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"type": [
"string",
@@ -1101,6 +1108,13 @@
},
"threadId": {
"type": "string"
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -231,6 +231,13 @@
"null"
]
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"type": [
"string",
@@ -313,6 +320,13 @@
}
],
"description": "Optional client-supplied analytics source classification for this thread."
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this thread and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"title": "ThreadStartParams",
@@ -522,6 +522,13 @@
],
"description": "Override where approval requests are routed for review on this turn and subsequent turns."
},
"currentDate": {
"description": "Override the current date shown in the model-visible environment context for this turn and subsequent turns.",
"type": [
"string",
"null"
]
},
"cwd": {
"description": "Override the working directory for this turn and subsequent turns.",
"type": [
@@ -598,6 +605,13 @@
},
"threadId": {
"type": "string"
},
"timezone": {
"description": "Override the timezone shown in the model-visible environment context for this turn and subsequent turns.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -25,4 +25,12 @@ model?: string | null, modelProvider?: string | null, serviceTier?: string | nul
* Override where approval requests are routed for review on this thread
* and subsequent turns.
*/
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, baseInstructions?: string | null, developerInstructions?: string | null, personality?: Personality | null};
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, baseInstructions?: string | null, developerInstructions?: string | null, /**
* Override the current date shown in the model-visible environment
* context for this thread and subsequent turns.
*/
currentDate?: string | null, /**
* Override the timezone shown in the model-visible environment context
* for this thread and subsequent turns.
*/
timezone?: string | null, personality?: Personality | null};
@@ -13,7 +13,15 @@ export type ThreadStartParams = {model?: string | null, modelProvider?: string |
* Override where approval requests are routed for review on this thread
* and subsequent turns.
*/
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, serviceName?: string | null, baseInstructions?: string | null, developerInstructions?: string | null, personality?: Personality | null, ephemeral?: boolean | null, sessionStartSource?: ThreadStartSource | null, /**
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, serviceName?: string | null, baseInstructions?: string | null, developerInstructions?: string | null, /**
* Override the current date shown in the model-visible environment
* context for this thread and subsequent turns.
*/
currentDate?: string | null, /**
* Override the timezone shown in the model-visible environment context
* for this thread and subsequent turns.
*/
timezone?: string | null, personality?: Personality | null, ephemeral?: boolean | null, sessionStartSource?: ThreadStartSource | null, /**
* Optional client-supplied analytics source classification for this thread.
*/
threadSource?: ThreadSource | null};
@@ -14,6 +14,14 @@ export type TurnStartParams = {threadId: string, input: Array<UserInput>, /**
* Override the working directory for this turn and subsequent turns.
*/
cwd?: string | null, /**
* Override the current date shown in the model-visible environment context
* for this turn and subsequent turns.
*/
currentDate?: string | null, /**
* Override the timezone shown in the model-visible environment context for
* this turn and subsequent turns.
*/
timezone?: string | null, /**
* Override the approval policy for this turn and subsequent turns.
*/
approvalPolicy?: AskForApproval | null, /**
@@ -130,6 +130,14 @@ pub struct ThreadStartParams {
pub base_instructions: Option<String>,
#[ts(optional = nullable)]
pub developer_instructions: Option<String>,
/// Override the current date shown in the model-visible environment
/// context for this thread and subsequent turns.
#[ts(optional = nullable)]
pub current_date: Option<String>,
/// Override the timezone shown in the model-visible environment context
/// for this thread and subsequent turns.
#[ts(optional = nullable)]
pub timezone: Option<String>,
#[ts(optional = nullable)]
pub personality: Option<Personality>,
#[ts(optional = nullable)]
@@ -285,6 +293,14 @@ pub struct ThreadResumeParams {
pub base_instructions: Option<String>,
#[ts(optional = nullable)]
pub developer_instructions: Option<String>,
/// Override the current date shown in the model-visible environment
/// context for this thread and subsequent turns.
#[ts(optional = nullable)]
pub current_date: Option<String>,
/// Override the timezone shown in the model-visible environment context
/// for this thread and subsequent turns.
#[ts(optional = nullable)]
pub timezone: Option<String>,
#[ts(optional = nullable)]
pub personality: Option<Personality>,
/// When true, return only thread metadata and live-resume state without
@@ -806,6 +806,8 @@ impl ThreadRequestProcessor {
service_name,
base_instructions,
developer_instructions,
current_date,
timezone,
dynamic_tools,
mock_experimental_field: _mock_experimental_field,
experimental_raw_events,
@@ -837,6 +839,8 @@ impl ThreadRequestProcessor {
permissions,
base_instructions,
developer_instructions,
current_date,
timezone,
personality,
);
typesafe_overrides.ephemeral = ephemeral;
@@ -1201,6 +1205,8 @@ impl ThreadRequestProcessor {
permissions: Option<PermissionProfileSelectionParams>,
base_instructions: Option<String>,
developer_instructions: Option<String>,
current_date: Option<String>,
timezone: Option<String>,
personality: Option<Personality>,
) -> ConfigOverrides {
let mut overrides = ConfigOverrides {
@@ -1217,6 +1223,8 @@ impl ThreadRequestProcessor {
main_execve_wrapper_exe: self.arg0_paths.main_execve_wrapper_exe.clone(),
base_instructions,
developer_instructions,
current_date,
timezone,
personality,
..Default::default()
};
@@ -2369,6 +2377,8 @@ impl ThreadRequestProcessor {
config: mut request_overrides,
base_instructions,
developer_instructions,
current_date,
timezone,
personality,
exclude_turns,
persist_extended_history: _persist_extended_history,
@@ -2403,6 +2413,8 @@ impl ThreadRequestProcessor {
permissions,
base_instructions,
developer_instructions,
current_date,
timezone,
personality,
);
self.load_and_apply_persisted_resume_metadata(
@@ -3063,6 +3075,8 @@ impl ThreadRequestProcessor {
permissions,
base_instructions,
developer_instructions,
/*current_date*/ None,
/*timezone*/ None,
/*personality*/ None,
);
typesafe_overrides.ephemeral = ephemeral.then_some(true);
@@ -637,6 +637,8 @@ mod thread_processor_behavior_tests {
config: None,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
personality: None,
exclude_turns: false,
persist_extended_history: false,
@@ -592,6 +592,8 @@ async fn skills_changed_notification_is_emitted_after_skill_change() -> Result<(
service_name: None,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
personality: None,
ephemeral: None,
session_start_source: None,
+8
View File
@@ -7043,6 +7043,8 @@ async fn test_precedence_fixture_with_o3_profile() -> std::io::Result<()> {
experimental_thread_store: ThreadStoreConfig::Local,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
guardian_policy_config: None,
include_permissions_instructions: true,
include_apps_instructions: true,
@@ -7463,6 +7465,8 @@ async fn test_precedence_fixture_with_gpt3_profile() -> std::io::Result<()> {
experimental_thread_store: ThreadStoreConfig::Local,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
guardian_policy_config: None,
include_permissions_instructions: true,
include_apps_instructions: true,
@@ -7621,6 +7625,8 @@ async fn test_precedence_fixture_with_zdr_profile() -> std::io::Result<()> {
experimental_thread_store: ThreadStoreConfig::Local,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
guardian_policy_config: None,
include_permissions_instructions: true,
include_apps_instructions: true,
@@ -7764,6 +7770,8 @@ async fn test_precedence_fixture_with_gpt5_profile() -> std::io::Result<()> {
experimental_thread_store: ThreadStoreConfig::Local,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
guardian_policy_config: None,
include_permissions_instructions: true,
include_apps_instructions: true,
+14
View File
@@ -449,6 +449,14 @@ pub struct Config {
/// Developer instructions override injected as a separate message.
pub developer_instructions: Option<String>,
/// Optional current date override shown in the model-visible environment
/// context for this session.
pub current_date: Option<String>,
/// Optional timezone override shown in the model-visible environment
/// context for this session.
pub timezone: Option<String>,
/// Guardian-specific policy config override from requirements.toml or config.toml.
/// This is inserted into the fixed guardian prompt template under the
/// `# Policy Configuration` section rather than replacing the whole
@@ -1867,6 +1875,8 @@ pub struct ConfigOverrides {
pub zsh_path: Option<PathBuf>,
pub base_instructions: Option<String>,
pub developer_instructions: Option<String>,
pub current_date: Option<String>,
pub timezone: Option<String>,
pub personality: Option<Personality>,
pub compact_prompt: Option<String>,
pub include_apply_patch_tool: Option<bool>,
@@ -2142,6 +2152,8 @@ impl Config {
zsh_path: zsh_path_override,
base_instructions,
developer_instructions,
current_date,
timezone,
personality,
compact_prompt,
include_apply_patch_tool: include_apply_patch_tool_override,
@@ -2999,6 +3011,8 @@ impl Config {
base_instructions,
personality,
developer_instructions,
current_date,
timezone,
compact_prompt,
commit_attribution,
include_permissions_instructions,
+2 -2
View File
@@ -620,8 +620,8 @@ impl Codex {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: environment_selections.to_selections(),
+29 -10
View File
@@ -2581,8 +2581,8 @@ async fn set_rate_limits_retains_previous_credits() {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: Vec::new(),
@@ -2687,8 +2687,8 @@ async fn set_rate_limits_updates_plan_type_when_present() {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: Vec::new(),
@@ -3146,6 +3146,25 @@ async fn session_configuration_apply_updates_environment_context_overrides() {
assert_eq!(updated.timezone.as_deref(), Some("America/Los_Angeles"));
}
#[tokio::test]
async fn turn_context_uses_initial_environment_context_overrides() {
let (_session, turn_context, _rx) = make_session_and_context_with_auth_and_config_and_rx(
CodexAuth::from_api_key("Test API Key"),
Vec::new(),
|config| {
config.current_date = Some("2026-05-13".to_string());
config.timezone = Some("America/Los_Angeles".to_string());
},
)
.await;
assert_eq!(turn_context.current_date.as_deref(), Some("2026-05-13"));
assert_eq!(
turn_context.timezone.as_deref(),
Some("America/Los_Angeles")
);
}
pub(crate) async fn make_session_configuration_for_tests() -> SessionConfiguration {
let codex_home = tempfile::tempdir().expect("create temp dir");
let config = build_test_config(codex_home.path()).await;
@@ -3182,8 +3201,8 @@ pub(crate) async fn make_session_configuration_for_tests() -> SessionConfigurati
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: Vec::new(),
@@ -3710,8 +3729,8 @@ async fn session_new_fails_when_zsh_fork_enabled_without_zsh_path() {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: Vec::new(),
@@ -3821,8 +3840,8 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: default_environments,
+4
View File
@@ -951,6 +951,8 @@ fn thread_start_params_from_config(config: &Config) -> ThreadStartParams {
sandbox: sandbox.flatten(),
permissions,
config: config_request_overrides_from_config(config),
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
ephemeral: Some(config.ephemeral),
..ThreadStartParams::default()
}
@@ -973,6 +975,8 @@ fn thread_resume_params_from_config(config: &Config, thread_id: String) -> Threa
approvals_reviewer: approvals_reviewer_override_from_config(config),
sandbox: sandbox.flatten(),
permissions,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
config: config_request_overrides_from_config(config),
..ThreadResumeParams::default()
}
+4
View File
@@ -1194,6 +1194,8 @@ fn thread_start_params_from_config(
sandbox,
permissions,
config: config_request_overrides_from_config(config),
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
ephemeral: Some(config.ephemeral),
session_start_source,
thread_source: Some(ThreadSource::User),
@@ -1228,6 +1230,8 @@ fn thread_resume_params_from_config(
sandbox,
permissions,
config: config_request_overrides_from_config(&config),
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
persist_extended_history: false,
..ThreadResumeParams::default()
}