mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Keep extracting memories out of core and moving the write trigger in the app-server This is temporary and it should move at the client level as a follow-up This makes core fully independant from `codex-memories-write` --------- Co-authored-by: Codex <noreply@openai.com>
56 lines
1.5 KiB
Rust
56 lines
1.5 KiB
Rust
use crate::phase1;
|
|
use crate::phase2;
|
|
use crate::runtime::MemoryStartupContext;
|
|
use codex_core::CodexThread;
|
|
use codex_core::ThreadManager;
|
|
use codex_core::config::Config;
|
|
use codex_features::Feature;
|
|
use codex_login::AuthManager;
|
|
use codex_protocol::ThreadId;
|
|
use codex_protocol::protocol::SessionSource;
|
|
use std::sync::Arc;
|
|
use tracing::warn;
|
|
|
|
/// Starts the asynchronous startup memory pipeline for an eligible root session.
|
|
///
|
|
/// The pipeline is skipped for ephemeral sessions, disabled feature flags, and
|
|
/// subagent sessions.
|
|
pub fn start_memories_startup_task(
|
|
thread_manager: Arc<ThreadManager>,
|
|
auth_manager: Arc<AuthManager>,
|
|
thread_id: ThreadId,
|
|
thread: Arc<CodexThread>,
|
|
config: Arc<Config>,
|
|
source: &SessionSource,
|
|
) {
|
|
if config.ephemeral
|
|
|| !config.features.enabled(Feature::MemoryTool)
|
|
|| source.is_non_root_agent()
|
|
{
|
|
return;
|
|
}
|
|
|
|
let context = Arc::new(MemoryStartupContext::new(
|
|
thread_manager,
|
|
auth_manager,
|
|
thread_id,
|
|
thread,
|
|
config.as_ref(),
|
|
source.clone(),
|
|
));
|
|
|
|
if context.state_db().is_none() {
|
|
warn!("state db unavailable for memories startup pipeline; skipping");
|
|
return;
|
|
}
|
|
|
|
tokio::spawn(async move {
|
|
// Clean memories to make preserve DB size
|
|
phase1::prune(context.as_ref(), &config).await;
|
|
// Run phase 1.
|
|
phase1::run(Arc::clone(&context), Arc::clone(&config)).await;
|
|
// Run phase 2.
|
|
phase2::run(context, config).await;
|
|
});
|
|
}
|