Skip to content

Commit 07aefff

Browse files
authored
core: bundle settings diff updates into one dev/user envelope (#12417)
## Summary - bundle contextual prompt injection into at most one developer message plus one contextual user message in both: - per-turn settings updates - initial context insertion - preserve `<model_switch>` across compaction by rebuilding it through canonical initial-context injection, instead of relying on strip/reattach hacks - centralize contextual user fragment detection in one shared definition table and reuse it for parsing/compaction logic - keep `AGENTS.md` in its natural serialized format: - `# AGENTS.md instructions for {dirname}` - `<INSTRUCTIONS>...</INSTRUCTIONS>` - simplify related tests/helpers and accept the expected snapshot/layout updates from bundled multi-part messages ## Why The goal is to converge toward a simpler, more intentional prompt shape where contextual updates are consistently represented as one developer envelope plus one contextual user envelope, while keeping parsing and compaction behavior aligned with that representation. ## Notable details - the temporary `SettingsUpdateEnvelope` wrapper was removed; these paths now return `Vec<ResponseItem>` directly - local/remote compaction no longer rely on model-switch strip/restore helpers - contextual user detection is now driven by shared fragment definitions instead of ad hoc matcher assembly - AGENTS/user instructions are still the same logical context; only the synthetic `<user_instructions>` wrapper was replaced by the natural AGENTS text format ## Testing - `just fmt` - `cargo test -p codex-app-server codex_message_processor::tests::extract_conversation_summary_prefers_plain_user_messages -- --exact` - `cargo test -p codex-core compact::tests::collect_user_messages_filters_session_prefix_entries --lib -- --exact` - `cargo test -p codex-core --test all 'suite::compact::snapshot_request_shape_pre_turn_compaction_strips_incoming_model_switch' -- --exact` - `cargo test -p codex-core --test all 'suite::compact_remote::snapshot_request_shape_remote_pre_turn_compaction_strips_incoming_model_switch' -- --exact` - `cargo test -p codex-core --test all 'suite::client::includes_apps_guidance_as_developer_message_when_enabled' -- --exact` - `cargo test -p codex-core --test all 'suite::client::includes_developer_instructions_message_in_request' -- --exact` - `cargo test -p codex-core --test all 'suite::client::includes_user_instructions_message_in_request' -- --exact` - `cargo test -p codex-core --test all 'suite::client::resume_includes_initial_messages_and_sends_prior_items' -- --exact` - `cargo test -p codex-core --test all 'suite::review::review_input_isolated_from_parent_history' -- --exact` - `cargo test -p codex-exec --test all 'suite::resume::exec_resume_last_respects_cwd_filter_and_all_flag' -- --exact` - `cargo test -p core_test_support context_snapshot::tests::full_text_mode_preserves_unredacted_text -- --exact` ## Notes - I also ran several targeted `compact`, `compact_remote`, `prompt_caching`, `model_visible_layout`, and `event_mapping` tests while iterating on prompt-shape changes. - I have not claimed a clean full-workspace `cargo test` from this environment because local sandbox/resource conditions have previously produced unrelated failures in large workspace runs.
1 parent 28bfbb8 commit 07aefff

File tree

47 files changed

+966
-813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+966
-813
lines changed

codex-rs/app-server/src/codex_message_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7627,7 +7627,7 @@ mod tests {
76277627
"role": "user",
76287628
"content": [{
76297629
"type": "input_text",
7630-
"text": "<user_instructions>\n<AGENTS.md contents>\n</user_instructions>".to_string(),
7630+
"text": "# AGENTS.md instructions for project\n\n<INSTRUCTIONS>\n<AGENTS.md contents>\n</INSTRUCTIONS>".to_string(),
76317631
}],
76327632
}),
76337633
json!({

codex-rs/app-server/tests/suite/send_message.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,13 @@ async fn test_send_message_raw_notifications_opt_in() -> Result<()> {
214214
})
215215
.await?;
216216

217-
let permissions = read_raw_response_item(&mut mcp, conversation_id).await;
218-
assert_permissions_message(&permissions);
219-
220217
let developer = read_raw_response_item(&mut mcp, conversation_id).await;
218+
assert_permissions_message(&developer);
221219
assert_developer_message(&developer, "Use the test harness tools.");
222220

223-
let instructions = read_raw_response_item(&mut mcp, conversation_id).await;
224-
assert_instructions_message(&instructions);
225-
226-
let environment = read_raw_response_item(&mut mcp, conversation_id).await;
227-
assert_environment_message(&environment);
221+
let contextual_user = read_raw_response_item(&mut mcp, conversation_id).await;
222+
assert_instructions_message(&contextual_user);
223+
assert_environment_message(&contextual_user);
228224

229225
let response: JSONRPCResponse = timeout(
230226
DEFAULT_READ_TIMEOUT,
@@ -545,9 +541,8 @@ fn assert_permissions_message(item: &ResponseItem) {
545541
false,
546542
)
547543
.into_text();
548-
assert_eq!(
549-
texts,
550-
vec![expected.as_str()],
544+
assert!(
545+
texts.iter().any(|text| *text == expected),
551546
"expected permissions developer message, got {texts:?}"
552547
);
553548
}
@@ -560,9 +555,8 @@ fn assert_developer_message(item: &ResponseItem, expected_text: &str) {
560555
ResponseItem::Message { role, content, .. } => {
561556
assert_eq!(role, "developer");
562557
let texts = content_texts(content);
563-
assert_eq!(
564-
texts,
565-
vec![expected_text],
558+
assert!(
559+
texts.contains(&expected_text),
566560
"expected developer instructions message, got {texts:?}"
567561
);
568562
}

codex-rs/core/src/agent/control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ mod tests {
319319
use crate::config::Config;
320320
use crate::config::ConfigBuilder;
321321
use crate::config_loader::LoaderOverrides;
322+
use crate::contextual_user_message::SUBAGENT_NOTIFICATION_OPEN_TAG;
322323
use crate::features::Feature;
323-
use crate::session_prefix::SUBAGENT_NOTIFICATION_OPEN_TAG;
324324
use assert_matches::assert_matches;
325325
use codex_protocol::config_types::ModeKind;
326326
use codex_protocol::models::ContentItem;

0 commit comments

Comments
 (0)