Preserve context annotations in merged messages (#40184)

## What changed

- Carry each contextual fragment's `ContentItemKind` through initial context assembly and world-state updates.
- Attach the classifications to merged response messages through `content_item_kinds`, preserving their order alongside the message content.
- Convert extension prompt fragments into annotated developer fragments and classify built-in developer and guardian instructions.

## Testing

- Add an integration test covering roles and content annotations in the first request.
- Update world-state and persisted-history tests to account for annotation metadata.

GitOrigin-RevId: 71c48dad5b17bffd47ba03263e3eb6d5e74fbf4b
This commit is contained in:
pakrym-oai
2026-08-23 04:41:11 +00:00
committed by copyberry
parent 422239eb4b
commit c4b434aae2
8 changed files with 199 additions and 76 deletions
@@ -2,6 +2,7 @@ use super::super::test_support::render_section_cases;
use super::*;
use crate::context::MultiAgentRoleInstructions;
use crate::context::world_state::WorldState;
use codex_protocol::models::ContentItem;
use codex_protocol::models::ResponseItem;
use codex_utils_output_truncation::approx_token_count;
@@ -112,10 +113,20 @@ fn catalog_role_updates_remain_separate_from_active_mode() {
let expected_mode = MultiAgentModeInstructions::from_mode(MultiAgentMode::Proactive)
.expect("proactive mode should render");
assert_eq!(
updates,
updates
.into_iter()
.map(|item| match item {
ResponseItem::Message { content, .. } => content,
_ => panic!("expected world-state message"),
})
.collect::<Vec<_>>(),
vec![
ContextualUserFragment::into(current_role),
ContextualUserFragment::into(expected_mode),
vec![ContentItem::InputText {
text: current_role.render(),
}],
vec![ContentItem::InputText {
text: expected_mode.render(),
}],
],
);
}