Files
codex/codex-rs/ext/extension-api/src/message_lifecycle.rs
T
rhan-oai 37f199dab1 Add host-reserved V2 child creation APIs (#57586)
## What changed

- Add `CodexThread::create_child` to create an idle child from a live tool invocation using a host-reserved thread ID and controller.
- Add `prepare_child` and `ThreadManager::create_prepared_child` to capture inherited settings and fresh or forked history, then start the child on another manager even after the parent shuts down. Reject detached preparation when live bindings cannot be transferred.
- Add opt-in `HostToolInvocationLookup` to track live calls and reject duplicate active call IDs within a turn. Revoke invocation access when dispatch ends and clean up provisional children when startup fails or is cancelled.

## Testing

Add tests for invocation lifetime and call ID reservation, inherited policy and live bindings, detached startup with fresh and full history, and cancellation cleanup.

GitOrigin-RevId: 71f17ecb4cd7636517e675df59289a8e8c7105b8
2026-10-27 23:02:27 +00:00

24 lines
1.0 KiB
Rust

//! Capture publication state once; consume it independently for each delivery.
use crate::ExtensionData;
use codex_protocol::ResponseItemId;
use codex_protocol::ThreadId;
/// State shared by all deliveries of a publication, including recipients resolved later.
pub struct MessageLifecycleInput {
pub message_id: ResponseItemId,
pub sender: ThreadId,
/// Capture contributor-specific state at publication; read it at consumption.
pub data: ExtensionData,
}
/// Observes messages from local agent control and the initial task of a host-spawned child.
/// Callbacks are synchronous and must not block. Replaying history or submitting raw
/// protocol input does not create a publication.
pub trait MessageLifecycleContributor: Send + Sync {
/// Called once before the message is exposed to any recipient.
fn on_publish(&self, _input: &MessageLifecycleInput) {}
/// Called at most once per logical delivery, at history commitment before sampling.
fn on_consumed(&self, _input: &MessageLifecycleInput, _recipient: ThreadId) {}
}