fix: reduce usage of open_if_present (#11344)

This commit is contained in:
jif-oai
2026-02-10 19:25:07 +00:00
committed by GitHub
parent 0639c33892
commit 847a6092e6
11 changed files with 448 additions and 534 deletions

View File

@@ -201,7 +201,7 @@ use codex_core::sandboxing::SandboxPermissions;
use codex_core::skills::remote::download_remote_skill;
use codex_core::skills::remote::list_remote_skills;
use codex_core::state_db::StateDbHandle;
use codex_core::state_db::open_if_present;
use codex_core::state_db::get_state_db;
use codex_core::windows_sandbox::WindowsSandboxLevelExt;
use codex_feedback::CodexFeedback;
use codex_login::ServerOptions as LoginServerOptions;
@@ -2026,11 +2026,7 @@ impl CodexMessageProcessor {
let rollout_path_display = archived_path.display().to_string();
let fallback_provider = self.config.model_provider_id.clone();
let state_db_ctx = open_if_present(
&self.config.codex_home,
self.config.model_provider_id.as_str(),
)
.await;
let state_db_ctx = get_state_db(&self.config, None).await;
let archived_folder = self
.config
.codex_home
@@ -3055,17 +3051,13 @@ impl CodexMessageProcessor {
let fallback_provider = self.config.model_provider_id.clone();
let (allowed_sources_vec, source_kind_filter) = compute_source_filters(source_kinds);
let allowed_sources = allowed_sources_vec.as_slice();
let state_db_ctx = open_if_present(
&self.config.codex_home,
self.config.model_provider_id.as_str(),
)
.await;
let state_db_ctx = get_state_db(&self.config, None).await;
while remaining > 0 {
let page_size = remaining.min(THREAD_LIST_MAX_LIMIT);
let page = if archived {
RolloutRecorder::list_archived_threads(
&self.config.codex_home,
&self.config,
page_size,
cursor_obj.as_ref(),
sort_key,
@@ -3081,7 +3073,7 @@ impl CodexMessageProcessor {
})?
} else {
RolloutRecorder::list_threads(
&self.config.codex_home,
&self.config,
page_size,
cursor_obj.as_ref(),
sort_key,
@@ -4138,11 +4130,7 @@ impl CodexMessageProcessor {
}
if state_db_ctx.is_none() {
state_db_ctx = open_if_present(
&self.config.codex_home,
self.config.model_provider_id.as_str(),
)
.await;
state_db_ctx = get_state_db(&self.config, None).await;
}
// Move the rollout file to archived.
@@ -5567,8 +5555,7 @@ async fn read_history_cwd_from_state_db(
thread_id: Option<ThreadId>,
rollout_path: &Path,
) -> Option<PathBuf> {
if let Some(state_db_ctx) =
open_if_present(&config.codex_home, config.model_provider_id.as_str()).await
if let Some(state_db_ctx) = get_state_db(config, None).await
&& let Some(thread_id) = thread_id
&& let Ok(Some(metadata)) = state_db_ctx.get_thread(thread_id).await
{
@@ -5589,7 +5576,7 @@ async fn read_summary_from_state_db_by_thread_id(
config: &Config,
thread_id: ThreadId,
) -> Option<ConversationSummary> {
let state_db_ctx = open_if_present(&config.codex_home, config.model_provider_id.as_str()).await;
let state_db_ctx = get_state_db(config, None).await;
read_summary_from_state_db_context_by_thread_id(state_db_ctx.as_ref(), thread_id).await
}