Handle standalone tool outputs as external context (#39791)

## What changed

- Treat standalone `function_call_output` items without a `call_id` as external context, including items injected into new and forked threads, and mark the thread memory mode polluted when `memories.disable_on_external_context` is enabled.
- Include these outputs in guardian transcripts with their namespaced tool name and a placeholder for non-text content.
- Allow image generation to reuse images from standalone and otherwise unpaired function or custom-tool outputs.

## Testing

- Cover injected thread items, external-context detection, guardian transcript rendering, and recent-image selection.

GitOrigin-RevId: ca4e8c16a4b731e1256a5956908d00f785b4feb1
This commit is contained in:
rka-oai authored and copyberry committed 2026-08-20 19:46:29 +00:00
1 parent 43526b8561
commit aead844f64
10 files changed
+170 -49

No files matched your search

+20
View File
@@ -595,6 +595,26 @@ pub(crate) fn collect_guardian_transcript_entries<'a>(
};
non_empty_entry(kind, text)
}),
ResponseItem::FunctionCallOutput {
call_id: None,
name: Some(name),
namespace,
output,
..
} => {
let text = output
.body
.to_text()
.unwrap_or_else(|| "[non-text output]".into());
let name = match namespace {
Some(namespace) => format!("{namespace}.{name}"),
None => name.to_string(),
};
non_empty_entry(
GuardianTranscriptEntryKind::Tool(format!("tool {name} result")),
text,
)
}
_ => None,
};
+39
View File
@@ -40,6 +40,7 @@ use codex_protocol::ThreadId;
use codex_protocol::approvals::NetworkApprovalProtocol;
use codex_protocol::config_types::ApprovalsReviewer;
use codex_protocol::models::ContentItem;
use codex_protocol::models::FunctionCallOutputContentItem;
use codex_protocol::models::PermissionProfile;
use codex_protocol::models::ResponseItem;
use codex_protocol::openai_models::ModelsResponse;
@@ -1046,6 +1047,44 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
));
}
#[test]
fn collect_guardian_transcript_entries_preserves_named_unpaired_tool_sources() {
let mut items = vec![ResponseItem::FunctionCallOutput {
id: None,
call_id: None,
name: Some("notifications".to_string()),
namespace: Some("slack".to_string()),
output: codex_protocol::models::FunctionCallOutputPayload::from_text(
"new message".to_string(),
),
internal_chat_message_metadata_passthrough: None,
}];
assert_eq!(
collect_guardian_transcript_entries(&items),
vec![GuardianTranscriptEntry {
kind: GuardianTranscriptEntryKind::Tool("tool slack.notifications result".to_string()),
text: "new message".to_string(),
}]
);
if let ResponseItem::FunctionCallOutput { output, .. } = &mut items[0] {
*output = codex_protocol::models::FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
image_url: "data:image/png;base64,image".to_string(),
detail: None,
},
]);
}
assert_eq!(
collect_guardian_transcript_entries(&items),
vec![GuardianTranscriptEntry {
kind: GuardianTranscriptEntryKind::Tool("tool slack.notifications result".to_string()),
text: "[non-text output]".to_string(),
}]
);
}
#[test]
fn guardian_truncate_text_keeps_prefix_suffix_and_xml_marker() {
let content = "prefix ".repeat(200) + &" suffix".repeat(200);