mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Separate thread startup metadata from replay history (#46294)
## Why `CodexThread` retained the full `SessionConfiguredEvent`, including initial replay messages, and cloned it even for callers that only needed thread or session IDs. ## What changed Store `ThreadStartupMetadata` without replay history and expose it by reference through `startup_metadata()`. Update callers to read IDs from this metadata. When rejoining a running thread, rebuild the startup response using the supplied resume history for `initial_messages`. ## Testing Extend the resume test to verify that rejoining reuses the loaded thread, preserves startup metadata, and still returns the original replay messages as a prefix. GitOrigin-RevId: 9d656063088c28f091d29e5862e4b9d894b7642c
This commit is contained in:
1 parent
47fc8d661e
commit
17baabd01b
11 files changed
+171
-25
No files matched your search
@@ -8,6 +8,7 @@ use crate::session::SessionSettingsUpdate;
|
||||
use crate::session::new_submission_id;
|
||||
use crate::session::session::Session;
|
||||
use crate::session::step_settings::StepSettingsUpdate;
|
||||
use crate::thread_startup_metadata::ThreadStartupMetadata;
|
||||
use codex_diagnostics::Gauge;
|
||||
use codex_diagnostics::GaugeGuard;
|
||||
use codex_exec_server::SelectedCapabilityRootsStatus;
|
||||
@@ -39,7 +40,6 @@ use codex_protocol::protocol::Event;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol::protocol::SessionConfiguredEvent;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::Submission;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
@@ -184,7 +184,7 @@ pub struct CodexThread {
|
||||
// Registration source controls live access and lifecycle hooks. Managed Guardian
|
||||
// reviewers keep their existing subagent identity inside the session.
|
||||
pub(crate) session_source: SessionSource,
|
||||
session_configured: SessionConfiguredEvent,
|
||||
startup_metadata: ThreadStartupMetadata,
|
||||
rollout_path: Option<PathBuf>,
|
||||
out_of_band_elicitations: Mutex<OutOfBandElicitations>,
|
||||
_diagnostics_guard: GaugeGuard,
|
||||
@@ -210,7 +210,7 @@ impl CodexThread {
|
||||
pub(crate) fn new(
|
||||
session: Arc<Session>,
|
||||
io: SessionIo,
|
||||
session_configured: SessionConfiguredEvent,
|
||||
startup_metadata: ThreadStartupMetadata,
|
||||
rollout_path: Option<PathBuf>,
|
||||
session_source: SessionSource,
|
||||
) -> Self {
|
||||
@@ -218,7 +218,7 @@ impl CodexThread {
|
||||
session,
|
||||
io,
|
||||
session_source,
|
||||
session_configured,
|
||||
startup_metadata,
|
||||
rollout_path,
|
||||
out_of_band_elicitations: Mutex::new(OutOfBandElicitations::default()),
|
||||
_diagnostics_guard: LIVE_THREADS.track(),
|
||||
@@ -707,8 +707,9 @@ impl CodexThread {
|
||||
self.rollout_path.clone()
|
||||
}
|
||||
|
||||
pub fn session_configured(&self) -> SessionConfiguredEvent {
|
||||
self.session_configured.clone()
|
||||
/// Returns startup metadata without the one-time initial message replay.
|
||||
pub fn startup_metadata(&self) -> &ThreadStartupMetadata {
|
||||
&self.startup_metadata
|
||||
}
|
||||
|
||||
pub(crate) fn is_running(&self) -> bool {
|
||||
|
||||
@@ -34,6 +34,7 @@ mod compact_model_fallback;
|
||||
mod compact_remote_history;
|
||||
mod compact_remote_v2;
|
||||
mod compact_token_budget;
|
||||
mod thread_startup_metadata;
|
||||
pub use codex_network_proxy::EnvironmentNetworkPolicy;
|
||||
pub use codex_network_proxy::NetworkDomainPermission;
|
||||
pub use codex_network_proxy::NetworkDomainPermissionEntry;
|
||||
@@ -50,6 +51,7 @@ pub use codex_thread::GuardianRootMessage;
|
||||
pub use codex_thread::GuardianRootSnapshot;
|
||||
pub use codex_thread::ThreadConfigSnapshot;
|
||||
pub use session::turn_context::TurnContext;
|
||||
pub use thread_startup_metadata::ThreadStartupMetadata;
|
||||
mod agent;
|
||||
mod agent_communication;
|
||||
mod attestation;
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::session::resolve_multi_agent_version;
|
||||
use crate::session::session::Session;
|
||||
use crate::tasks::InterruptedTurnHistoryMarker;
|
||||
use crate::tasks::interrupted_turn_history_marker;
|
||||
use crate::thread_startup_metadata::ThreadStartupMetadata;
|
||||
use codex_agent_graph_store::AgentGraphStore;
|
||||
use codex_agent_graph_store::LocalAgentGraphStore;
|
||||
use codex_analytics::AnalyticsEventsClient;
|
||||
@@ -2061,9 +2062,13 @@ impl ThreadManagerState {
|
||||
resumed.conversation_id
|
||||
)));
|
||||
}
|
||||
drop(threads);
|
||||
let session_configured = thread
|
||||
.startup_metadata()
|
||||
.to_session_configured_event(initial_history.get_event_msgs());
|
||||
return Ok(NewThread {
|
||||
thread_id: resumed.conversation_id,
|
||||
session_configured: thread.session_configured(),
|
||||
session_configured,
|
||||
thread,
|
||||
});
|
||||
}
|
||||
@@ -2278,7 +2283,7 @@ impl ThreadManagerState {
|
||||
let thread = Arc::new(CodexThread::new(
|
||||
session,
|
||||
io,
|
||||
session_configured.clone(),
|
||||
ThreadStartupMetadata::from(&session_configured),
|
||||
session_configured.rollout_path.clone(),
|
||||
session_source,
|
||||
));
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
//! Retained startup metadata, separate from the replay sent in startup responses.
|
||||
|
||||
use codex_protocol::SessionId;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::models::ActivePermissionProfile;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::SessionConfiguredEvent;
|
||||
use codex_protocol::protocol::SessionNetworkProxyRuntime;
|
||||
use codex_protocol::protocol::ThreadSource;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// The configuration reported when a thread started, without its replay history.
|
||||
/// Current settings are available through [`crate::CodexThread::config_snapshot`].
|
||||
#[derive(Debug)]
|
||||
pub struct ThreadStartupMetadata {
|
||||
pub session_id: SessionId,
|
||||
pub thread_id: ThreadId,
|
||||
forked_from_id: Option<ThreadId>,
|
||||
parent_thread_id: Option<ThreadId>,
|
||||
thread_source: Option<ThreadSource>,
|
||||
thread_name: Option<String>,
|
||||
model: String,
|
||||
model_provider_id: String,
|
||||
service_tier: Option<String>,
|
||||
approval_policy: AskForApproval,
|
||||
approvals_reviewer: ApprovalsReviewer,
|
||||
permission_profile: PermissionProfile,
|
||||
active_permission_profile: Option<ActivePermissionProfile>,
|
||||
cwd: AbsolutePathBuf,
|
||||
reasoning_effort: Option<ReasoningEffort>,
|
||||
network_proxy: Option<SessionNetworkProxyRuntime>,
|
||||
rollout_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl From<&SessionConfiguredEvent> for ThreadStartupMetadata {
|
||||
fn from(event: &SessionConfiguredEvent) -> Self {
|
||||
let SessionConfiguredEvent {
|
||||
session_id,
|
||||
thread_id,
|
||||
forked_from_id,
|
||||
parent_thread_id,
|
||||
thread_source,
|
||||
thread_name,
|
||||
model,
|
||||
model_provider_id,
|
||||
service_tier,
|
||||
approval_policy,
|
||||
approvals_reviewer,
|
||||
permission_profile,
|
||||
active_permission_profile,
|
||||
cwd,
|
||||
reasoning_effort,
|
||||
initial_messages: _,
|
||||
network_proxy,
|
||||
rollout_path,
|
||||
} = event;
|
||||
Self {
|
||||
session_id: *session_id,
|
||||
thread_id: *thread_id,
|
||||
forked_from_id: *forked_from_id,
|
||||
parent_thread_id: *parent_thread_id,
|
||||
thread_source: thread_source.clone(),
|
||||
thread_name: thread_name.clone(),
|
||||
model: model.clone(),
|
||||
model_provider_id: model_provider_id.clone(),
|
||||
service_tier: service_tier.clone(),
|
||||
approval_policy: *approval_policy,
|
||||
approvals_reviewer: *approvals_reviewer,
|
||||
permission_profile: permission_profile.clone(),
|
||||
active_permission_profile: active_permission_profile.clone(),
|
||||
cwd: cwd.clone(),
|
||||
reasoning_effort: reasoning_effort.clone(),
|
||||
network_proxy: network_proxy.clone(),
|
||||
rollout_path: rollout_path.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ThreadStartupMetadata {
|
||||
pub(crate) fn to_session_configured_event(
|
||||
&self,
|
||||
initial_messages: Option<Vec<EventMsg>>,
|
||||
) -> SessionConfiguredEvent {
|
||||
SessionConfiguredEvent {
|
||||
session_id: self.session_id,
|
||||
thread_id: self.thread_id,
|
||||
forked_from_id: self.forked_from_id,
|
||||
parent_thread_id: self.parent_thread_id,
|
||||
thread_source: self.thread_source.clone(),
|
||||
thread_name: self.thread_name.clone(),
|
||||
model: self.model.clone(),
|
||||
model_provider_id: self.model_provider_id.clone(),
|
||||
service_tier: self.service_tier.clone(),
|
||||
approval_policy: self.approval_policy,
|
||||
approvals_reviewer: self.approvals_reviewer,
|
||||
permission_profile: self.permission_profile.clone(),
|
||||
active_permission_profile: self.active_permission_profile.clone(),
|
||||
cwd: self.cwd.clone(),
|
||||
reasoning_effort: self.reasoning_effort.clone(),
|
||||
initial_messages,
|
||||
network_proxy: self.network_proxy.clone(),
|
||||
rollout_path: self.rollout_path.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user