mirror of
https://github.com/openai/codex.git
synced 2026-11-24 15:21:20 +00:00
Add Guardian internal session support (#39994)
## What changed - Add an extension API for spawning host-owned internal sessions and a `ThreadReadyInput` lifecycle callback that runs after thread registration. - Add Guardian reviewer session scaffolding that records the parent thread and effective model, plus the under-development `guardian_ext` feature flag. - Start internal sessions with fresh history while preserving parent lineage, shared session controls, and internal-thread visibility rules. - Scope internal-session prompt cache keys to their source and parent thread, and expose `guardian` as an internal session source. ## Testing - Cover internal-session spawning, parent metadata, history isolation, prompt cache keys, and extension spawner argument forwarding. GitOrigin-RevId: 682dae80397d62bb36247796b447042e760ca364
This commit is contained in:
1 parent
79b7606803
commit
56012fafb8
22 files changed
+402
-10
No files matched your search
@@ -906,6 +906,28 @@ impl ThreadManager {
|
||||
Box::pin(self.start_thread_inner(options, /*forked_from_thread_id*/ None)).await
|
||||
}
|
||||
|
||||
/// Starts a fresh internal session associated with an existing parent thread.
|
||||
pub async fn spawn_internal_session(
|
||||
&self,
|
||||
parent_thread_id: ThreadId,
|
||||
mut options: StartThreadOptions,
|
||||
) -> CodexResult<NewThread> {
|
||||
if !matches!(options.session_source, Some(SessionSource::Internal(_))) {
|
||||
return Err(CodexErr::InvalidRequest(
|
||||
"internal sessions require an internal session source".to_string(),
|
||||
));
|
||||
}
|
||||
let parent = self.get_thread(parent_thread_id).await?;
|
||||
options.initial_history = InitialHistory::New;
|
||||
let mut request = ThreadSpawnRequest::new(
|
||||
options,
|
||||
Arc::clone(&parent.session.services.auth_manager),
|
||||
parent.session.services.agent_control.clone(),
|
||||
);
|
||||
request.parent_thread_id = Some(parent_thread_id);
|
||||
Box::pin(self.state.spawn_thread(request)).await
|
||||
}
|
||||
|
||||
/// Allocates a thread ID before startup so a caller can associate host-owned state with it.
|
||||
pub fn reserve_thread_id(&self) -> ThreadId {
|
||||
self.state.thread_id_generator.as_ref()()
|
||||
@@ -1912,6 +1934,7 @@ impl ThreadManagerState {
|
||||
let new_thread = self
|
||||
.finalize_thread_spawn(session, io, tracked_session_source)
|
||||
.await?;
|
||||
new_thread.thread.emit_thread_ready_lifecycle().await;
|
||||
if source_changed_during_startup.load(Ordering::Acquire) {
|
||||
new_thread.thread.session.request_mcp_runtime_refresh();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user