fix(app-server): report dynamic tool schema errors

This commit is contained in:
Alex Kotliarskyi
2026-05-21 11:21:09 -07:00
parent de80fa6e31
commit 8677b878cc
30 changed files with 547 additions and 14 deletions
@@ -910,11 +910,8 @@ pub(crate) async fn apply_bespoke_event_handling(
return;
}
let turn_error = TurnError {
message: ev.message,
codex_error_info: ev.codex_error_info.map(V2CodexErrorInfo::from),
additional_details: None,
};
let dynamic_tools = conversation.dynamic_tools().await;
let turn_error = TurnError::from_core_error_event(&ev, Some(dynamic_tools.as_slice()));
handle_error(conversation_id, turn_error.clone(), &thread_state).await;
outgoing
.send_server_notification(ServerNotification::Error(ErrorNotification {
@@ -932,6 +929,7 @@ pub(crate) async fn apply_bespoke_event_handling(
message: ev.message,
codex_error_info: ev.codex_error_info.map(V2CodexErrorInfo::from),
additional_details: ev.additional_details,
data: None,
};
outgoing
.send_server_notification(ServerNotification::Error(ErrorNotification {
@@ -3178,6 +3176,7 @@ mod tests {
message: "boom".to_string(),
codex_error_info: Some(V2CodexErrorInfo::InternalServerError),
additional_details: None,
data: None,
},
&thread_state,
)
@@ -3190,6 +3189,7 @@ mod tests {
message: "boom".to_string(),
codex_error_info: Some(V2CodexErrorInfo::InternalServerError),
additional_details: None,
data: None,
})
);
Ok(())
@@ -3350,6 +3350,7 @@ mod tests {
message: "oops".to_string(),
codex_error_info: None,
additional_details: None,
data: None,
},
&thread_state,
)
@@ -3400,6 +3401,7 @@ mod tests {
message: "bad".to_string(),
codex_error_info: Some(V2CodexErrorInfo::Other),
additional_details: None,
data: None,
},
&thread_state,
)
@@ -3435,6 +3437,7 @@ mod tests {
message: "bad".to_string(),
codex_error_info: Some(V2CodexErrorInfo::Other),
additional_details: None,
data: None,
})
);
assert_eq!(n.turn.completed_at, Some(TEST_TURN_COMPLETED_AT));
@@ -3645,6 +3648,7 @@ mod tests {
message: "a1".to_string(),
codex_error_info: Some(V2CodexErrorInfo::BadRequest),
additional_details: None,
data: None,
},
&thread_state,
)
@@ -3666,6 +3670,7 @@ mod tests {
message: "b1".to_string(),
codex_error_info: None,
additional_details: None,
data: None,
},
&thread_state,
)
@@ -3702,6 +3707,7 @@ mod tests {
message: "a1".to_string(),
codex_error_info: Some(V2CodexErrorInfo::BadRequest),
additional_details: None,
data: None,
})
);
}
@@ -3720,6 +3726,7 @@ mod tests {
message: "b1".to_string(),
codex_error_info: None,
additional_details: None,
data: None,
})
);
}
@@ -2086,7 +2086,14 @@ impl ThreadRequestProcessor {
.load_history(/*include_archived*/ true)
.await
.map_err(|err| thread_read_history_load_error(thread_id, err))?;
thread.turns = build_api_turns_from_rollout_items(&history.items);
let live_turn = {
let thread_state = self.thread_state_manager.thread_state(thread_id).await;
let state = thread_state.lock().await;
state
.active_turn_snapshot()
.or_else(|| state.last_terminal_turn_snapshot())
};
populate_thread_turns_from_history(thread, &history.items, live_turn.as_ref());
}
Ok(())
@@ -133,6 +133,39 @@ mod thread_processor_behavior_tests {
validate_dynamic_tools(&tools).expect("valid schema");
}
#[test]
fn validate_dynamic_tools_accepts_root_any_of_input_schema() {
let tools = vec![ApiDynamicToolSpec {
namespace: Some("repro".to_string()),
name: "create".to_string(),
description: "test".to_string(),
input_schema: json!({
"anyOf": [
{
"type": "object",
"properties": {
"kind": { "type": "string", "enum": ["wikiEdit"] },
"slug": { "type": "string" }
},
"required": ["kind", "slug"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"kind": { "type": "string", "enum": ["chatMessage"] },
"channel": { "type": "string" }
},
"required": ["kind", "channel"],
"additionalProperties": false
}
]
}),
defer_loading: false,
}];
validate_dynamic_tools(&tools).expect("valid schema");
}
#[test]
fn validate_dynamic_tools_accepts_same_name_in_different_namespaces() {
let tools = vec![
@@ -787,6 +787,7 @@ impl TurnRequestProcessor {
turn_kind: turn_kind.into(),
}),
additional_details: None,
data: None,
};
let data = match serde_json::to_value(error) {
Ok(data) => Some(data),
+19
View File
@@ -6,6 +6,7 @@ use codex_app_server_protocol::ThreadHistoryBuilder;
use codex_app_server_protocol::ThreadSettings;
use codex_app_server_protocol::Turn;
use codex_app_server_protocol::TurnError;
use codex_app_server_protocol::TurnStatus;
use codex_core::CodexThread;
use codex_core::ThreadConfigSnapshot;
use codex_file_watcher::WatchRegistration;
@@ -74,6 +75,7 @@ pub(crate) struct ThreadState {
pub(crate) pending_rollbacks: Option<ConnectionRequestId>,
pub(crate) turn_summary: TurnSummary,
pub(crate) last_terminal_turn_id: Option<String>,
pub(crate) last_terminal_turn: Option<Turn>,
pub(crate) cancel_tx: Option<oneshot::Sender<()>>,
pub(crate) experimental_raw_events: bool,
pub(crate) listener_generation: u64,
@@ -117,6 +119,8 @@ impl ThreadState {
}
self.listener_command_tx = None;
self.current_turn_history.reset();
self.last_terminal_turn_id = None;
self.last_terminal_turn = None;
self.listener_thread = None;
self.watch_registration = WatchRegistration::default();
}
@@ -135,15 +139,30 @@ impl ThreadState {
self.current_turn_history.active_turn_snapshot()
}
pub(crate) fn last_terminal_turn_snapshot(&self) -> Option<Turn> {
self.last_terminal_turn.clone()
}
pub(crate) fn track_current_turn_event(&mut self, event_turn_id: &str, event: &EventMsg) {
if let EventMsg::TurnStarted(payload) = event {
self.turn_summary.started_at = payload.started_at;
self.last_terminal_turn_id = None;
self.last_terminal_turn = None;
}
self.current_turn_history.handle_event(event);
if matches!(event, EventMsg::TurnAborted(_) | EventMsg::TurnComplete(_))
&& !self.current_turn_history.has_active_turn()
{
self.last_terminal_turn_id = Some(event_turn_id.to_string());
let mut terminal_turn = self.current_turn_history.active_turn_snapshot();
if let Some(turn) = terminal_turn.as_mut()
&& let Some(error) = self.turn_summary.last_error.clone()
{
turn.status = TurnStatus::Failed;
turn.error = Some(error);
}
self.last_terminal_turn = terminal_turn
.filter(|turn| turn.error.is_some() || matches!(turn.status, TurnStatus::Failed));
self.current_turn_history.reset();
}
}