Files
codex/codex-rs/ext/extension-api/src/capabilities/events.rs
T
felixxia-oai 5dd992acd3 Route extension warnings to app-server threads (#35168)
## Why

Extension warnings need a stable thread target even when they are emitted outside an active turn.

## What changed

- Add `ExtensionWarning` and a dedicated `ExtensionEventSink::emit_warning` path with an explicit thread ID and optional turn ID.
- Deliver extension warnings as thread-scoped app-server `warning` notifications, preserving listener ordering and waiting briefly for a subscriber when no listener is active.
- Move skills warnings to the new path, limiting provider catalog warnings to four messages of 256 bytes each.

## Testing

- Cover warning routing, ordering, UTF-8-safe truncation, subscriber fallback, and invalid thread IDs.
- Verify skills warning bounds and app-server delivery of executor catalog budget warnings.

GitOrigin-RevId: 4dcb1ba7f17c0edb1a9d548f9568e0c734bffc15
2026-07-24 12:28:29 +00:00

39 lines
1.5 KiB
Rust

use codex_protocol::protocol::Event;
/// Extension warning with an explicit thread target and optional turn correlation.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExtensionWarning {
/// Stable host-owned thread identifier used for delivery.
pub thread_id: String,
/// Stable host-owned turn identifier when the warning arose in a turn callback.
pub turn_id: Option<String>,
/// Concise warning message for the user.
pub message: String,
}
/// Host-provided fire-and-forget sink for extension-generated events.
///
/// Extensions construct protocol events with the correlation id appropriate for
/// the callback they are handling, then leave persistence, ordering, transport
/// fanout, and logging decisions to the host.
pub trait ExtensionEventSink: Send + Sync {
/// Queue one protocol event for host-owned delivery.
fn emit(&self, event: Event);
/// Queue one warning for host-owned delivery.
///
/// Implementations must use [`ExtensionWarning::thread_id`] for routing. The optional
/// [`ExtensionWarning::turn_id`] is correlation metadata and does not identify a thread.
fn emit_warning(&self, warning: ExtensionWarning);
}
/// Event sink used when the host does not expose extension event emission.
#[derive(Debug, Default, Clone, Copy)]
pub struct NoopExtensionEventSink;
impl ExtensionEventSink for NoopExtensionEventSink {
fn emit(&self, _event: Event) {}
fn emit_warning(&self, _warning: ExtensionWarning) {}
}