mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] Surface runtime warnings in codex exec (#27415)
## Why `codex exec` drops thread-scoped warning notifications. Warnings discovered while a thread starts, including unreadable or invalid UTF-8 project `AGENTS.md` files, therefore become silent. ## What changed - Process global and primary-thread warning notifications while continuing to ignore warnings from unrelated threads. - Render runtime warnings in human output and expose them through the existing non-fatal error item in JSONL output. - Add focused routing, rendering, and malformed project-instruction coverage.
This commit is contained in:
committed by
GitHub
Unverified
parent
cc97839068
commit
7fbbc9f033
@@ -239,6 +239,7 @@ impl EventProcessor for EventProcessorWithHumanOutput {
|
||||
);
|
||||
CodexStatus::Running
|
||||
}
|
||||
ServerNotification::Warning(notification) => self.process_warning(notification.message),
|
||||
ServerNotification::Error(notification) => {
|
||||
eprintln!(
|
||||
"{} {}",
|
||||
|
||||
@@ -430,6 +430,11 @@ impl EventProcessorWithJsonOutput {
|
||||
}));
|
||||
CodexStatus::Running
|
||||
}
|
||||
ServerNotification::Warning(notification) => {
|
||||
let warning = self.collect_warning(notification.message);
|
||||
events.extend(warning.events);
|
||||
warning.status
|
||||
}
|
||||
ServerNotification::Error(notification) => {
|
||||
let message = match notification.error.additional_details {
|
||||
Some(details) if !details.is_empty() => {
|
||||
|
||||
@@ -59,6 +59,33 @@ fn failed_turn_does_not_overwrite_output_last_message_file() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_warning_emits_a_non_fatal_error_item() {
|
||||
let mut processor = EventProcessorWithJsonOutput::new(/*last_message_path*/ None);
|
||||
|
||||
let collected = processor.collect_thread_events(ServerNotification::Warning(
|
||||
codex_app_server_protocol::WarningNotification {
|
||||
thread_id: Some("thread-1".to_string()),
|
||||
message: "invalid global instructions".to_string(),
|
||||
},
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
collected,
|
||||
CollectedThreadEvents {
|
||||
events: vec![ThreadEvent::ItemCompleted(ItemCompletedEvent {
|
||||
item: ExecThreadItem {
|
||||
id: "item_0".to_string(),
|
||||
details: ThreadItemDetails::Error(ErrorItem {
|
||||
message: "invalid global instructions".to_string(),
|
||||
}),
|
||||
},
|
||||
})],
|
||||
status: CodexStatus::Running,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mcp_tool_call_result_preserves_meta_in_jsonl_event() {
|
||||
let mut processor = EventProcessorWithJsonOutput::new(/*last_message_path*/ None);
|
||||
|
||||
@@ -1256,6 +1256,11 @@ fn should_process_notification(
|
||||
) -> bool {
|
||||
match notification {
|
||||
ServerNotification::ConfigWarning(_) | ServerNotification::DeprecationNotice(_) => true,
|
||||
// TODO(anp) resolve duplicate startup warnings
|
||||
ServerNotification::Warning(notification) => notification
|
||||
.thread_id
|
||||
.as_deref()
|
||||
.is_none_or(|candidate| candidate == thread_id),
|
||||
ServerNotification::Error(notification) => {
|
||||
notification.thread_id == thread_id && notification.turn_id == turn_id
|
||||
}
|
||||
|
||||
@@ -267,6 +267,35 @@ fn lagged_event_warning_message_is_explicit() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_warnings_are_filtered_to_the_primary_thread() {
|
||||
let primary_thread_id = "thread-1";
|
||||
let turn_id = "turn-1";
|
||||
let outcomes = [
|
||||
codex_app_server_protocol::WarningNotification {
|
||||
thread_id: None,
|
||||
message: "global warning".to_string(),
|
||||
},
|
||||
codex_app_server_protocol::WarningNotification {
|
||||
thread_id: Some(primary_thread_id.to_string()),
|
||||
message: "primary warning".to_string(),
|
||||
},
|
||||
codex_app_server_protocol::WarningNotification {
|
||||
thread_id: Some("thread-2".to_string()),
|
||||
message: "other warning".to_string(),
|
||||
},
|
||||
]
|
||||
.map(|warning| {
|
||||
should_process_notification(
|
||||
&ServerNotification::Warning(warning),
|
||||
primary_thread_id,
|
||||
turn_id,
|
||||
)
|
||||
});
|
||||
|
||||
assert_eq!(outcomes, [true, true, false]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn resume_lookup_model_providers_filters_only_last_lookup() {
|
||||
let codex_home = tempdir().expect("create temp codex home");
|
||||
|
||||
Reference in New Issue
Block a user