Files
codex/codex-rs/ext/extension-api/src/message_lifecycle.rs
T
Ruslan Nigmatullin 5e5bdee745 Decouple message lifecycle state from model-visible item IDs (#59785)
## Why

A message's model-visible item ID may be unknown until the recipient records it. Message lifecycle observers need to capture publication state before that point.

## What changed

Remove `message_id` from `MessageLifecycleInput` and give each publication's `ExtensionData` a fresh UUID key. Stop assigning an item ID when publishing messages for lifecycle observers.

## Testing

Update the agent mailbox test to store a contributor-specific token in `ExtensionData` at publication and retrieve it at consumption, verifying that publication state survives queued delivery and recipient eviction.

GitOrigin-RevId: e254f94994d0976e61cb46ee23297f3248b9a389
2026-11-06 01:50:20 +00:00

23 lines
1.1 KiB
Rust

//! Capture publication state once; consume it independently for each delivery.
use crate::ExtensionData;
use codex_protocol::ThreadId;
/// State shared by all deliveries of a publication, including recipients resolved later.
/// The model-visible item ID may still be unknown until the recipient records the message.
pub struct MessageLifecycleInput {
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) {}
}