mirror of
https://github.com/openai/codex.git
synced 2026-11-28 23:34:06 +00:00
Record realtime conversation history in Core (#41924)
## Why Realtime history should be recorded consistently for every Core host, including when no app-server event listener is attached. ## What changed - Move transcript segmentation, session boundaries, and backing-agent artifact promotion into Core for paginated threads. - Persist canonical realtime items through the thread store in event order and emit dedicated history lifecycle events for hosts to present. - Translate those Core events into the existing app-server realtime item notifications without app-server persisting the items a second time. ## Testing - Cover Core-only persistence across repeated sessions, ephemeral sessions, accepted and rejected steering, typed input ordering, and artifact promotion. - Verify app-server notifications correspond to the persisted timeline. GitOrigin-RevId: 7cbef14129d77f6d6d7099b733be91f5279c55f5
This commit is contained in:
1 parent
34c4f7e72d
commit
64c9cde458
22 files changed
+971
-472
No files matched your search
@@ -1,12 +1,8 @@
|
||||
use super::*;
|
||||
use crate::extensions::send_thread_warning;
|
||||
use crate::realtime_event_handling::apply_realtime_event_effects;
|
||||
use crate::realtime_event_handling::persist_realtime_items;
|
||||
use crate::realtime_history::RealtimeEventEffects;
|
||||
use codex_app_server_protocol::ThreadQueueChangedNotification;
|
||||
use codex_extension_api::ThreadIdleCause;
|
||||
use codex_protocol::config_types::MultiAgentMode;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
|
||||
pub(super) const THREAD_UNLOADING_DELAY: Duration = Duration::from_secs(30 * 60);
|
||||
|
||||
@@ -247,8 +243,6 @@ pub(super) async fn ensure_listener_task_running(
|
||||
)
|
||||
.await;
|
||||
let config_snapshot = conversation.config_snapshot().await;
|
||||
let realtime_history_enabled =
|
||||
matches!(config_snapshot.history_mode, ThreadHistoryMode::Paginated);
|
||||
let thread_settings_baseline = thread_settings_from_config_snapshot(&config_snapshot);
|
||||
let (mut listener_command_rx, listener_generation) = {
|
||||
let mut thread_state = thread_state.lock().await;
|
||||
@@ -331,20 +325,10 @@ pub(super) async fn ensure_listener_task_running(
|
||||
// Track the event before emitting any typed translations
|
||||
// so thread-local state such as raw event opt-in stays
|
||||
// synchronized with the conversation.
|
||||
let (raw_events_enabled, realtime_effects) = {
|
||||
let raw_events_enabled = {
|
||||
let mut thread_state = thread_state.lock().await;
|
||||
thread_state.track_current_turn_event(&event.id, &event.msg);
|
||||
let realtime_effects = if realtime_history_enabled
|
||||
&& thread_state.realtime_history.should_observe(&event.msg)
|
||||
{
|
||||
let active_turn_id = thread_state.active_turn_snapshot().map(|turn| turn.id);
|
||||
thread_state
|
||||
.realtime_history
|
||||
.observe(&event.msg, active_turn_id.as_deref())
|
||||
} else {
|
||||
RealtimeEventEffects::default()
|
||||
};
|
||||
(thread_state.experimental_raw_events, realtime_effects)
|
||||
thread_state.experimental_raw_events
|
||||
};
|
||||
if matches!(
|
||||
&event.msg,
|
||||
@@ -362,14 +346,6 @@ pub(super) async fn ensure_listener_task_running(
|
||||
conversation_id,
|
||||
);
|
||||
|
||||
apply_realtime_event_effects(
|
||||
conversation.as_ref(),
|
||||
&thread_outgoing,
|
||||
conversation_id,
|
||||
realtime_effects,
|
||||
)
|
||||
.await;
|
||||
|
||||
apply_bespoke_event_handling(
|
||||
event.clone(),
|
||||
conversation_id,
|
||||
@@ -582,32 +558,6 @@ pub(super) async fn handle_thread_listener_command(
|
||||
.await;
|
||||
let _ = completion_tx.send(());
|
||||
}
|
||||
ThreadListenerCommand::SealRealtimeUserInput {
|
||||
input,
|
||||
completion_tx,
|
||||
} => {
|
||||
let items = thread_state
|
||||
.lock()
|
||||
.await
|
||||
.realtime_history
|
||||
.seal_user_input(&input);
|
||||
let subscribed_connection_ids = thread_state_manager
|
||||
.subscribed_connection_ids(conversation_id)
|
||||
.await;
|
||||
let thread_outgoing = ThreadScopedOutgoingMessageSender::new(
|
||||
outgoing.clone(),
|
||||
subscribed_connection_ids,
|
||||
conversation_id,
|
||||
);
|
||||
let result = persist_realtime_items(
|
||||
conversation.as_ref(),
|
||||
&thread_outgoing,
|
||||
&conversation_id.to_string(),
|
||||
items,
|
||||
)
|
||||
.await;
|
||||
let _ = completion_tx.send(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -619,10 +619,6 @@ impl TurnRequestProcessor {
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
if let TurnInput::UserInput { content, .. } = &input {
|
||||
self.seal_realtime_transcript_before_user_input(thread_id, content)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let submission = thread
|
||||
.start_or_steer_turn(
|
||||
@@ -997,12 +993,12 @@ impl TurnRequestProcessor {
|
||||
request_id: &ConnectionRequestId,
|
||||
params: TurnSteerParams,
|
||||
) -> Result<TurnSteerResponse, JSONRPCErrorError> {
|
||||
let (thread_id, thread) =
|
||||
self.load_thread(¶ms.thread_id)
|
||||
.await
|
||||
.inspect_err(|error| {
|
||||
self.track_error_response(request_id, error, /*error_type*/ None);
|
||||
})?;
|
||||
let (_, thread) = self
|
||||
.load_thread(¶ms.thread_id)
|
||||
.await
|
||||
.inspect_err(|error| {
|
||||
self.track_error_response(request_id, error, /*error_type*/ None);
|
||||
})?;
|
||||
self.ensure_direct_input_allowed(request_id, thread.as_ref())
|
||||
.await?;
|
||||
|
||||
@@ -1028,9 +1024,6 @@ impl TurnRequestProcessor {
|
||||
.collect();
|
||||
let additional_context = map_additional_context(params.additional_context);
|
||||
|
||||
self.seal_realtime_transcript_before_user_input(thread_id, &mapped_items)
|
||||
.await?;
|
||||
|
||||
let submission = thread
|
||||
.steer_turn(
|
||||
TurnInputRequest::new(TurnInput::UserInput {
|
||||
@@ -1127,37 +1120,6 @@ impl TurnRequestProcessor {
|
||||
Ok(TurnSteerResponse { turn_id })
|
||||
}
|
||||
|
||||
async fn seal_realtime_transcript_before_user_input(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
input: &[CoreInputItem],
|
||||
) -> Result<(), JSONRPCErrorError> {
|
||||
let thread_state = self.thread_state_manager.thread_state(thread_id).await;
|
||||
if !thread_state
|
||||
.lock()
|
||||
.await
|
||||
.realtime_history
|
||||
.should_seal_user_input(input)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
let listener = self
|
||||
.thread_state_manager
|
||||
.current_listener_command_tx(thread_id)
|
||||
.ok_or_else(|| internal_error("thread listener is not running"))?;
|
||||
let (completion_tx, completion_rx) = tokio::sync::oneshot::channel();
|
||||
listener
|
||||
.send(ThreadListenerCommand::SealRealtimeUserInput {
|
||||
input: input.to_vec(),
|
||||
completion_tx,
|
||||
})
|
||||
.map_err(|_| internal_error("thread listener is not running"))?;
|
||||
completion_rx
|
||||
.await
|
||||
.map_err(|_| internal_error("thread listener stopped before sealing realtime input"))?
|
||||
.map_err(internal_error)
|
||||
}
|
||||
|
||||
async fn prepare_realtime_conversation_thread(
|
||||
&self,
|
||||
request_id: &ConnectionRequestId,
|
||||
|
||||
Reference in new issue
Block a user