Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Preserve inherited context in prediction forks (#53678)

Keyan Zhang044e74fef3d1
diff --git a/codex-rs/app-server/src/request_processors/thread_processor.rs b/codex-rs/app-server/src/request_processors/thread_processor.rs
index ba04c2b693..9563a250cc 100644
--- a/codex-rs/app-server/src/request_processors/thread_processor.rs
+++ b/codex-rs/app-server/src/request_processors/thread_processor.rs
@@ -5175,6 +5175,9 @@ impl ThreadRequestProcessor {
_ => internal_error(format!("failed to inherit parent state: {err}")),
})?;
options.config.ephemeral = ephemeral;
+ options
+ .thread_extension_init
+ .insert(codex_core::compact::AutoCompactionDisabled);
options
.config
.features
diff --git a/codex-rs/app-server/tests/suite/v2/compaction.rs b/codex-rs/app-server/tests/suite/v2/compaction.rs
index 2f3f895977..47082d837f 100644
--- a/codex-rs/app-server/tests/suite/v2/compaction.rs
+++ b/codex-rs/app-server/tests/suite/v2/compaction.rs
@@ -10,6 +10,7 @@ use app_test_support::ChatGptAuthFixture;
use app_test_support::MockResponsesConfig;
use app_test_support::TestAppServer;
use app_test_support::write_chatgpt_auth;
+use codex_app_server_protocol::CodexErrorInfo;
use codex_app_server_protocol::ItemCompletedNotification;
use codex_app_server_protocol::ItemStartedNotification;
use codex_app_server_protocol::JSONRPCError;
@@ -18,6 +19,8 @@ use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::ResponseUsageMetadata;
use codex_app_server_protocol::ThreadCompactStartParams;
use codex_app_server_protocol::ThreadCompactStartResponse;
+use codex_app_server_protocol::ThreadForkParams;
+use codex_app_server_protocol::ThreadForkResponse;
use codex_app_server_protocol::ThreadHistoryMode;
use codex_app_server_protocol::ThreadItem;
use codex_app_server_protocol::ThreadResumeParams;
@@ -28,13 +31,16 @@ use codex_app_server_protocol::TokenUsageBreakdown;
use codex_app_server_protocol::TurnCompletedNotification;
use codex_app_server_protocol::TurnStartParams;
use codex_app_server_protocol::TurnStartResponse;
+use codex_app_server_protocol::TurnStatus;
use codex_app_server_protocol::UserInput as V2UserInput;
use codex_config::types::AuthCredentialsStoreMode;
+use codex_features::Feature;
use codex_utils_absolute_path::test_support::PathExt;
use core_test_support::responses;
use core_test_support::skip_if_no_network;
use pretty_assertions::assert_eq;
use serde_json::json;
+use std::collections::BTreeMap;
use tempfile::TempDir;
use test_case::test_case;
use tokio::time::timeout;
@@ -59,6 +65,215 @@ enum CompactionRoute {
Remote,
}
+/// Prediction forks retain their prompt through pre-, mid-, and post-turn thresholds,
+/// while their parent still compacts normally and keeps the same skill and tool inputs.
+#[test_case(ThreadHistoryMode::Legacy, 0; "legacy pre-turn")]
+#[test_case(ThreadHistoryMode::Paginated, 0; "paginated pre-turn")]
+#[test_case(ThreadHistoryMode::Legacy, 95; "legacy post-turn")]
+#[test_case(ThreadHistoryMode::Paginated, 95; "paginated post-turn")]
+#[tokio::test]
+async fn prediction_forks_do_not_auto_compact(
+ history_mode: ThreadHistoryMode,
+ post_turn_percent: u8,
+) -> Result<()> {
+ skip_if_no_network!(Ok(()));
+ let server = responses::start_mock_server().await;
+ let mock = responses::mount_sse_sequence(
+ &server,
+ vec![
+ responses::sse(vec![
+ responses::ev_assistant_message("seed", "Remember the original context."),
+ responses::ev_completed_with_tokens("seed", /*total_tokens*/ 70_000),
+ ]),
+ responses::sse(vec![
+ responses::ev_function_call("call", "unknown_test_tool", "{}"),
+ responses::ev_completed_with_tokens("tool", /*total_tokens*/ 330_000),
+ ]),
+ responses::sse(vec![
+ responses::ev_assistant_message("prediction", "Prediction complete."),
+ responses::ev_completed_with_tokens("prediction", /*total_tokens*/ 330_000),
+ ]),
+ responses::sse(vec![
+ responses::ev_assistant_message("next-prediction", "Still the original context."),
+ responses::ev_completed_with_tokens(
+ "next-prediction",
+ /*total_tokens*/ 330_000,
+ ),
+ ]),
+ responses::sse(vec![
+ responses::ev_assistant_message("parent", "Parent complete."),
+ responses::ev_completed_with_tokens("parent", /*total_tokens*/ 330_000),
+ ]),
+ responses::sse(vec![
+ responses::ev_assistant_message("summary", "Compacted parent context."),
+ responses::ev_completed_with_tokens("summary", /*total_tokens*/ 200),
+ ]),
+ responses::sse(vec![
+ responses::ev_assistant_message("after", "Parent after compaction."),
+ responses::ev_completed_with_tokens("after", /*total_tokens*/ 120),
+ ]),
+ ],
+ )
+ .await;
+ let codex_home = TempDir::new()?;
+ compaction_config(&server.uri(), /*auto_compact_limit*/ 200_000)
+ .with_root_config(&format!(
+ "model_post_turn_compact_threshold_percent = {post_turn_percent}"
+ ))
+ .write(codex_home.path())?;
+ let skill_dir = codex_home.path().join("skills/cache-test");
+ std::fs::create_dir_all(&skill_dir)?;
+ std::fs::write(
+ skill_dir.join("SKILL.md"),
+ "---\nname: cache-test\ndescription: Retain this skill metadata across prediction forks.\n---\nUse the original context.\n",
+ )?;
+ let mut mcp = TestAppServer::builder()
+ .with_codex_home(codex_home.path())
+ .build_initialized()
+ .await?;
+ let parent = mcp
+ .start_thread(ThreadStartParams {
+ history_mode: Some(history_mode),
+ ..Default::default()
+ })
+ .await?;
+ send_turn_and_wait(&mut mcp, &parent.thread.id, "Seed").await?;
+ let fork_id = mcp
+ .send_thread_fork_request(ThreadForkParams {
+ thread_id: parent.thread.id.clone(),
+ experimental_prediction_mode: true,
+ ephemeral: true,
+ exclude_turns: true,
+ ..Default::default()
+ })
+ .await?;
+ let child: ThreadForkResponse =
+ timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(fork_id)).await??;
+ for (thread_id, expected_requests) in [
+ (&child.thread.id, 3),
+ (&child.thread.id, 4),
+ (&parent.thread.id, if post_turn_percent > 0 { 6 } else { 5 }),
+ (&parent.thread.id, 7),
+ ] {
+ let completed = mcp
+ .start_turn_and_wait_for_completion(TurnStartParams {
+ thread_id: thread_id.clone(),
+ input: vec![V2UserInput::Text {
+ text: "Continue".into(),
+ text_elements: vec![],
+ }],
+ ..Default::default()
+ })
+ .await?;
+ assert_eq!(completed.turn.status, TurnStatus::Completed);
+ assert_eq!(mock.requests().len(), expected_requests);
+ }
+ let requests = mock.requests();
+ let comparable = |index: usize| {
+ let body = requests[index].body_json();
+ responses::strip_response_item_ids_from_json(responses::strip_metadata_from_json(json!({
+ "input": body["input"],
+ "instructions": body["instructions"],
+ "tools": body["tools"],
+ })))
+ };
+ assert_eq!(comparable(1), comparable(4));
+ assert!(requests[1].body_contains_text("Retain this skill metadata"));
+ assert!(requests[2].body_contains_text("Remember the original context."));
+ assert!(requests[3].body_contains_text("Remember the original context."));
+ assert!(requests[5].body_contains_text(COMPACT_PROMPT));
+ assert!(requests[6].body_contains_text("Compacted parent context."));
+ Ok(())
+}
+
+/// Predictions preserve history on context-limit failures and reject model-requested resets.
+#[test_case(false; "context limit")]
+#[test_case(true; "context reset")]
+#[tokio::test]
+async fn prediction_context_failure_does_not_compact(reset_context: bool) -> Result<()> {
+ skip_if_no_network!(Ok(()));
+ let server = responses::start_mock_server().await;
+ let mut mock_responses = vec![
+ responses::sse(vec![responses::ev_completed_with_tokens(
+ "seed", /*total_tokens*/ 330_000,
+ )]),
+ if reset_context {
+ responses::sse(vec![
+ responses::ev_function_call("reset", "new_context", "{}"),
+ responses::ev_completed("prediction"),
+ ])
+ } else {
+ responses::sse_failed(
+ "prediction",
+ "context_length_exceeded",
+ "Context limit exceeded",
+ )
+ },
+ ];
+ if reset_context {
+ mock_responses.push(responses::sse(vec![
+ responses::ev_assistant_message("answer", "Prediction without resetting context."),
+ responses::ev_completed("answer"),
+ ]));
+ }
+ let mock = responses::mount_sse_sequence(&server, mock_responses).await;
+ let codex_home = TempDir::new()?;
+ compaction_config(&server.uri(), /*auto_compact_limit*/ 200_000)
+ .with_root_config("model_post_turn_compact_threshold_percent = 0")
+ .with_features(&BTreeMap::from([(Feature::TokenBudget, reset_context)]))
+ .write(codex_home.path())?;
+ let mut mcp = TestAppServer::builder()
+ .with_codex_home(codex_home.path())
+ .build_initialized()
+ .await?;
+ let parent = mcp.start_thread(ThreadStartParams::default()).await?;
+ send_turn_and_wait(&mut mcp, &parent.thread.id, "Seed").await?;
+ let fork_id = mcp
+ .send_thread_fork_request(ThreadForkParams {
+ thread_id: parent.thread.id,
+ experimental_prediction_mode: true,
+ ephemeral: true,
+ exclude_turns: true,
+ ..Default::default()
+ })
+ .await?;
+ let child: ThreadForkResponse =
+ timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(fork_id)).await??;
+ let completed = mcp
+ .start_turn_and_wait_for_completion(TurnStartParams {
+ thread_id: child.thread.id,
+ input: vec![V2UserInput::Text {
+ text: "Predict".into(),
+ text_elements: vec![],
+ }],
+ ..Default::default()
+ })
+ .await?;
+ let requests = mock.requests();
+ if reset_context {
+ assert_eq!(completed.turn.status, TurnStatus::Completed);
+ assert_eq!(requests.len(), 3);
+ assert!(requests[2].body_contains_text("Context resets are disabled for this thread."));
+ assert!(requests[2].body_contains_text("Seed"));
+ } else {
+ assert_eq!(completed.turn.status, TurnStatus::Failed);
+ let error = completed.turn.error.expect("prediction should fail");
+ assert_eq!(
+ error.codex_error_info,
+ Some(CodexErrorInfo::ContextWindowExceeded)
+ );
+ assert_eq!(requests.len(), 2);
+ assert_eq!(
+ requests[1]
+ .message_input_texts("user")
+ .last()
+ .map(String::as_str),
+ Some("Predict")
+ );
+ }
+ Ok(())
+}
+
#[test_case(CompactionRoute::Local, Some(300), 429, "usage_limit_reached"; "local five hour")]
#[test_case(CompactionRoute::Remote, Some(10_080), 429, "usage_limit_reached"; "remote weekly")]
#[test_case(CompactionRoute::Local, None, 429, "usage_limit_reached"; "missing window")]
diff --git a/codex-rs/core/src/compact.rs b/codex-rs/core/src/compact.rs
index 661b058ad1..71761349e4 100644
--- a/codex-rs/core/src/compact.rs
+++ b/codex-rs/core/src/compact.rs
@@ -62,6 +62,10 @@ pub use codex_prompts::SUMMARIZATION_PROMPT;
pub use codex_prompts::SUMMARY_PREFIX;
const COMPACT_USER_MESSAGE_MAX_TOKENS: usize = 20_000;
+/// Thread-local policy that preserves inherited context without changing model or skill budgets.
+/// Insert into `StartThreadOptions::thread_extension_init` to disable automatic compaction.
+pub struct AutoCompactionDisabled;
+
/// Metadata for a new compaction checkpoint, kept separate from its replacement history.
///
/// `Session::replace_compacted_history` assigns missing item IDs before constructing the persisted
diff --git a/codex-rs/core/src/session/turn.rs b/codex-rs/core/src/session/turn.rs
index 70fc892c8d..70a6f0bcaf 100644
--- a/codex-rs/core/src/session/turn.rs
+++ b/codex-rs/core/src/session/turn.rs
@@ -6,6 +6,7 @@ use std::sync::atomic::Ordering;
use crate::client::ModelClientSession;
use crate::client_common::Prompt;
use crate::client_common::ResponseEvent;
+use crate::compact::AutoCompactionDisabled;
use crate::compact::run_inline_auto_compact_task;
use crate::compact_remote_v2::BackgroundCompactionCandidate;
use crate::compact_remote_v2::run_inline_remote_auto_compact_task as run_inline_remote_auto_compact_task_v2;
@@ -170,6 +171,13 @@ pub(crate) async fn run_turn(
prewarmed_client_session: Option<ModelClientSession>,
cancellation_token: CancellationToken,
) -> CodexResult<Option<String>> {
+ let auto_compaction_enabled = sess
+ .services
+ .thread_extension_data
+ .get::<AutoCompactionDisabled>()
+ .is_none();
+ let auto_summarization_enabled =
+ auto_compaction_enabled && !turn_context.config.features.enabled(Feature::TokenBudget);
if crate::guardian::is_basic_session_source(&turn_context.session_source) {
crate::guardian::check_pending_guardian_input(&sess, &turn_context).await?;
}
@@ -182,13 +190,14 @@ pub(crate) async fn run_turn(
// new user message are recorded. Estimate pending incoming items (context
// diffs/full reinjection + user input) and trigger compaction preemptively
// when they would push the thread over the compaction threshold.
- if let Err(err) = run_pre_sampling_compact(
- &sess,
- &turn_context,
- &mut client_session,
- &cancellation_token,
- )
- .await
+ if auto_compaction_enabled
+ && let Err(err) = run_pre_sampling_compact(
+ &sess,
+ &turn_context,
+ &mut client_session,
+ &cancellation_token,
+ )
+ .await
{
// Compaction runs before the new input is recorded, so preserve it on every failure.
run_hooks_and_record_inputs(
@@ -335,8 +344,8 @@ pub(crate) async fn run_turn(
{
// Token-budget compaction resets history, which can discard the evidence
// referenced by a pending delta review. Leave budget failures unreusable.
- if !matches!(error.details(), CodexErrorDetails::ContextWindowExceeded)
- || turn_context.config.features.enabled(Feature::TokenBudget)
+ if !auto_summarization_enabled
+ || !matches!(error.details(), CodexErrorDetails::ContextWindowExceeded)
{
return Err(error);
}
@@ -608,16 +617,19 @@ pub(crate) async fn run_turn(
);
}
- let should_roll_over = needs_follow_up
+ let should_roll_over = auto_compaction_enabled
+ && needs_follow_up
&& (sess.take_new_context_window_request().await || token_limit_reached);
- let allow_auto_compact_fallback = !should_roll_over && !token_limit_reached;
- super::token_budget::maybe_record(
- sess.as_ref(),
- turn_context.as_ref(),
- token_status.base_window_tokens_remaining,
- allow_auto_compact_fallback,
- )
- .await;
+ if auto_compaction_enabled {
+ let allow_auto_compact_fallback = !should_roll_over && !token_limit_reached;
+ super::token_budget::maybe_record(
+ sess.as_ref(),
+ turn_context.as_ref(),
+ token_status.base_window_tokens_remaining,
+ allow_auto_compact_fallback,
+ )
+ .await;
+ }
// as long as compaction works well in getting us way below the token limit, we shouldn't worry about being in an infinite loop.
if should_roll_over {
@@ -720,8 +732,8 @@ pub(crate) async fn run_turn(
// Token-budget resets do not summarize, so preserve their existing rollover
// policy. Keep summarizing compaction in this task to serialize history updates.
let config = &turn_context.config;
- if config.model_post_turn_compact_threshold_percent > 0
- && !config.features.enabled(Feature::TokenBudget)
+ let should_compact_after_turn = auto_summarization_enabled
+ && config.model_post_turn_compact_threshold_percent > 0
&& super::context_window::context_window_token_status(
sess.as_ref(),
turn_context.as_ref(),
@@ -729,7 +741,8 @@ pub(crate) async fn run_turn(
.await
.turn_end_compaction_threshold_reached
&& !sess.input_queue.has_pending_input(&sess.active_turn).await
- && !cancellation_token.is_cancelled()
+ && !cancellation_token.is_cancelled();
+ if should_compact_after_turn
&& let Err(err) = run_auto_compact(
&sess,
Arc::clone(&step_context),
@@ -764,9 +777,9 @@ pub(crate) async fn run_turn(
continue;
}
Err(err)
- if matches!(err.details(), CodexErrorDetails::ContextWindowExceeded)
+ if auto_summarization_enabled
+ && matches!(err.details(), CodexErrorDetails::ContextWindowExceeded)
&& !guardian_budget_compacted
- && !turn_context.config.features.enabled(Feature::TokenBudget)
&& sess
.services
.thread_extension_data
diff --git a/codex-rs/core/src/tools/handlers/new_context_window.rs b/codex-rs/core/src/tools/handlers/new_context_window.rs
index 45b1a191db..4b11300b54 100644
--- a/codex-rs/core/src/tools/handlers/new_context_window.rs
+++ b/codex-rs/core/src/tools/handlers/new_context_window.rs
@@ -1,3 +1,4 @@
+use crate::compact::AutoCompactionDisabled;
use crate::function_tool::FunctionCallError;
use crate::tools::context::FunctionToolOutput;
use crate::tools::context::ToolInvocation;
@@ -35,6 +36,18 @@ impl ToolExecutor<ToolInvocation> for NewContextWindowHandler {
));
}
+ if invocation
+ .session
+ .services
+ .thread_extension_data
+ .get::<AutoCompactionDisabled>()
+ .is_some()
+ {
+ return Err(FunctionCallError::RespondToModel(
+ "Context resets are disabled for this thread.".to_string(),
+ ));
+ }
+
invocation.session.request_new_context_window().await;
Ok(boxed_tool_output(FunctionToolOutput::from_text(
diff --git a/codex-rs/core/tests/suite/scenarios.rs b/codex-rs/core/tests/suite/scenarios.rs
index b2251f83fc..e212859bc3 100644
--- a/codex-rs/core/tests/suite/scenarios.rs
+++ b/codex-rs/core/tests/suite/scenarios.rs
@@ -16,9 +16,12 @@ use codex_config::ConfigLayerStack;
use codex_config::types::McpServerConfig;
use codex_context_fragments::AnsweredQuestion;
use codex_context_fragments::ContextualUserFragment;
+use codex_core::ForkSnapshot;
use codex_core::StartThreadOptions;
use codex_core::TurnInputRequest;
+use codex_core::compact::AutoCompactionDisabled;
use codex_core::config::Config;
+use codex_core::config::TokenBudgetConfig;
use codex_exec_server::CreateDirectoryOptions;
use codex_exec_server::EnvironmentManager;
use codex_exec_server::LOCAL_ENVIRONMENT_ID;
@@ -63,6 +66,7 @@ use core_test_support::context_snapshot::ContextSnapshotOptions;
use core_test_support::context_snapshot::SnapshotEntry;
use core_test_support::responses::ev_assistant_message;
use core_test_support::responses::ev_completed;
+use core_test_support::responses::ev_completed_with_tokens;
use core_test_support::responses::ev_custom_tool_call;
use core_test_support::responses::ev_function_call_with_namespace;
use core_test_support::responses::ev_message_item_added;
@@ -2021,6 +2025,82 @@ async fn prediction_fork_inherits_parent_context() -> Result<()> {
Ok(())
}
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn prediction_fork_preserves_context_above_compaction_threshold() -> Result<()> {
+ skip_if_no_network!(Ok(()));
+
+ let server = start_mock_server().await;
+ let mock = mount_sse_sequence(
+ &server,
+ vec![
+ sse(vec![
+ ev_assistant_message("parent", "The release is ready for validation."),
+ ev_completed_with_tokens("parent", /*total_tokens*/ 70_000),
+ ]),
+ sse(vec![
+ ev_function_call_with_namespace(
+ "remaining",
+ "functions",
+ "get_context_remaining",
+ "{}",
+ ),
+ ev_completed_with_tokens("tool", /*total_tokens*/ 70_000),
+ ]),
+ sse(vec![
+ ev_assistant_message("prediction", "Run the release checks."),
+ ev_completed_with_tokens("prediction", /*total_tokens*/ 70_000),
+ ]),
+ ],
+ )
+ .await;
+ let mut test = test_codex()
+ .with_model("gpt-6-astra")
+ .with_config(|config| {
+ configure_scenario_catalog(config);
+ config.workspace_roots = vec![config.cwd.clone()];
+ config.model_auto_compact_token_limit = Some(50_000);
+ config
+ .features
+ .enable(Feature::TokenBudget)
+ .expect("enable token budget");
+ config.token_budget = Some(TokenBudgetConfig {
+ reminder_threshold_tokens: Some(2_000),
+ ..TokenBudgetConfig::default()
+ });
+ })
+ .build_with_auto_env(&server)
+ .await?;
+
+ test.submit_turn("Prepare the release.").await?;
+ test.codex.flush_rollout().await?;
+ let (mut options, settings) = test
+ .thread_manager
+ .fork_options_from_parent(test.session_configured.thread_id)
+ .await?;
+ options.config.ephemeral = true;
+ options.thread_extension_init.insert(AutoCompactionDisabled);
+ let child = test
+ .thread_manager
+ .fork_legacy_thread(
+ ForkSnapshot::Interrupted,
+ options,
+ test.codex.rollout_path().expect("parent rollout path"),
+ )
+ .await?;
+ child.thread.restore_thread_settings(settings).await?;
+ test.codex = child.thread;
+ test.submit_turn("Suggest my next message.").await?;
+
+ let requests = mock.requests();
+ assert_eq!(requests.len(), 3);
+ insta::assert_snapshot!(context_snapshot::format_request_history_snapshot(
+ "The parent finishes above the compaction threshold. Its prediction fork retains the parent's context and reminder, but neither compacts nor adds another reminder after a tool call.",
+ &requests,
+ &ContextSnapshotOptions::default().include_request_settings(),
+ ));
+ Ok(())
+}
+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn guardian_checkpoint_migration_request_history() -> Result<()> {
skip_if_no_network!(Ok(()));
diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__prediction_fork_preserves_context_above_compaction_threshold.snap b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__prediction_fork_preserves_context_above_compaction_threshold.snap
new file mode 100644
index 0000000000..eef36d9ce3
--- /dev/null
+++ b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__prediction_fork_preserves_context_above_compaction_threshold.snap
@@ -0,0 +1,119 @@
+---
+source: core/tests/suite/scenarios.rs
+expression: "context_snapshot::format_request_history_snapshot(\"The parent finishes above the compaction threshold. Its prediction fork retains the parent's context and reminder, but neither compacts nor adds another reminder after a tool call.\",\n&requests, &ContextSnapshotOptions::default().include_request_settings(),)"
+---
+Scenario: The parent finishes above the compaction threshold. Its prediction fork retains the parent's context and reminder, but neither compacts nor adds another reminder after a tool call.
+
+## Window 1
+Settings:
+ include: ["reasoning.encrypted_content"]
+ model: "gpt-6-astra"
+ parallel_tool_calls: false
+ prompt_cache_key: "<PROMPT_CACHE_KEY 1>"
+ reasoning: {"context":"all_turns","effort":"low"}
+ store: false
+ stream: true
+ text: {"verbosity":"low"}
+ tool_choice: "auto"
+-- request 1 (turn) --
+00:additional_tools/developer (3; hash=696793f2090ba3e3):
+ - namespace/functions; hash=eb439da1f745d8d5
+ - custom/exec
+ - function/wait
+ - function/request_user_input
+ - function/request_user_input_async
+ - function/new_context
+ - namespace/clock: Tools for reading and waiting on time.; hash=f402e8c5e9b5e317
+ - function/sleep
+ - namespace/collaboration: Tools for spawning and managing sub-agents.; hash=2c8d6295978dbe63
+ - function/followup_task
+ - function/interrupt_agent
+ - function/list_agents
+ - function/send_message
+ - function/spawn_agent
+ - function/wait_agent
+01:message/developer:
+ You are Codex, an agent based on GPT-6. You and the user share one workspace, and your job is to collabo...them until their intended goal is completely handled. [hash=efa50f074efa5803]
+
+ # When to ask the user for permission
+
+ Use your best judgement given task context for when you really need user permission, like a competent co...ork without ending the turn to clarify with the user. [hash=ca7367e658b51388]
+
+ User authorization and preferences persist across turns. Do not request permission again when the user h... any guidelines provided in skills or external files. [hash=911f91c92c72882c]
+
+ <OMITTED 155 LINES; ~4935 TOKENS; hash=5573869716192298>
+
+ - Skill naming: If a plugin contributes skills, those skill entries are prefixed with plugin_name: in the Skills list.
+ - MCP naming: Plugin-provided MCP tools keep standard MCP identifiers such as mcp__server__tool; use tool provenance to tell which plugin they come from.
+ - Trigger rules: If the user explicitly names a plugin, prefer capabilities associated with that plugin for that turn.
+ - Relationship to capabilities: Plugins are not invoked directly. Use their underlying skills, MCP tools, and app tools to help solve the task.
+ - Relevance: Determine what a plugin can help with from explicit user mention or from the plugin-associa..., MCP tools, and apps exposed elsewhere in this turn. [hash=620459a4e7b590f0]
+ - Missing/blocked: If the user requests a plugin that does not have relevant callable capabilities for t..., say so briefly and continue with the best fallback. [hash=746b0469a8f6cb3e]
+
+02:message/developer[2]:
+ [01] <permissions instructions>
+ Filesystem sandboxing defines which files can be read or written. `sandbox_mode` is `danger-full-access`...ll commands are permitted. Network access is enabled. [hash=c134061cebb94a1b]
+ Approval policy is currently never. Do not provide the `sandbox_permissions` for any reason, commands will be rejected.
+ </permissions instructions>
+ [02] <collaboration_mode># Collaboration Mode: Default
+
+ You are now in Default mode. Any previous instructions for other modes (e.g. Plan mode) are no longer active.
+
+ Your active mode changes only when new developer instructions with a different `<collaboration_mode>...<...by themselves. Known mode names are Default and Plan. [hash=e75f6b12fc52d812]
+
+ ## request_user_input availability
+
+ Use the `request_user_input` tool only when it is listed in the available tools for this turn.
+
+ Use the `request_user_input` tool only for optional questions where the answer would materially improve the quality of the work.
+
+ If `request_user_input` returns no answers, continue with best judgment instead of asking again or treating the turn as blocked.
+
+ Never use the `request_user_input` tool for permission requests or permission-related escalations.
+ </collaboration_mode>
+03:message/developer:
+ <context_window>
+ Agent name: /root
+ First context window id: <UUID 1>
+ Current context window id: <UUID 1>
+ </context_window>
+04:message/developer:
+ <multi_agent_role>You are `/root`, the primary agent in a team of agents collaborating to fulfill the user's goals.
+
+ At the start of your turn, you are the active agent.
+ You can spawn sub-agents to handle subtasks, and those sub-agents can spawn their own sub-agents.
+ All agents in the team, including the agents that you can assign tasks to, are equally intelligent and capable, and have access to the same set of tools.
+
+ You can use `spawn_agent` to create a new agent, `followup_task` to give an existing agent a new task an...message to a running agent without triggering a turn. [hash=7d40ff8b58977202]
+ `send_message` calls may be read by a human, so ensure they are legible. Always put proper spaces between words and/or numbers.
+ <OMITTED 17 LINES; ~246 TOKENS; hash=780031e2df907944>
+ - All agents use the same current working directory.
+ - As a result, edits made by one agent are immediately visible to all other agents.
+
+ When calling `wait_agent`, prefer longer waits (minutes) to avoid busy polling.
+
+ There are 4 available concurrency slots, meaning that up to 4 agents can be active at once, including you.
+
+ Full-history forks (`fork_turns` omitted or `"all"`) inherit the parent model and reasoning effort and d... so, set `fork_turns` to `"none"`.</multi_agent_role> [hash=d5928243dc643bcc]
+05:message/developer:
+ <multi_agent_mode>Any earlier instruction enabling proactive multi-agent delegation no longer applies. D...elegation, or parallel agent work.</multi_agent_mode> [hash=2b6e037067b4390c]
+06:message/user:
+ <environment_context>
+ <cwd><CWD></cwd>
+ <shell><HOST_SHELL></shell>
+ <current_date><CURRENT_DATE></current_date>
+ <timezone><HOST_TIMEZONE></timezone>
+ <filesystem><workspace_roots><root><CWD></root></workspace_roots><permission_profile type="disabled"><...e="unrestricted" /></permission_profile></filesystem> [hash=d40b2f45cb028888]
+ </environment_context>
+07:message/user:
+ Prepare the release.
+-- request 2 (turn) --
+08:message/assistant:
+ The release is ready for validation.
+09:message/developer:
+ Your context window is nearly exhausted (only 0 tokens remaining) and will be automatically reset for yo... and history items will be persistent across windows. [hash=23016acc05795bc3]
+10:message/user:
+ Suggest my next message.
+-- request 3 (turn) --
+11:function_call/functions.get_context_remaining:{}
+12:function_call_output:You have 0 tokens left in this context window.