mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
state: pass state db handles through consumers (#20561)
## Why SQLite state was still being opened from consumer paths, including lazy `OnceCell`-backed thread-store call sites. That let one process construct multiple state DB connections for the same Codex home, which makes SQLite lock contention and `database is locked` failures much easier to hit. State DB lifetime should be chosen by main-like entrypoints and tests, then passed through explicitly. Consumers should use the supplied `Option<StateDbHandle>` or `StateDbHandle` and keep their existing filesystem fallback or error behavior when no handle is available. The startup path also needs to keep the rollout crate in charge of SQLite state initialization. Opening `codex_state::StateRuntime` directly bypasses rollout metadata backfill, so entrypoints should initialize through `codex_rollout::state_db` and receive a handle only after required rollout backfills have completed. ## What Changed - Initialize the state DB in main-like entrypoints for CLI, TUI, app-server, exec, MCP server, and the thread-manager sample. - Pass `Option<StateDbHandle>` through `ThreadManager`, `LocalThreadStore`, app-server processors, TUI app wiring, rollout listing/recording, personality migration, shell snapshot cleanup, session-name lookup, and memory/device-key consumers. - Remove the lazy local state DB wrapper from the thread store so non-test consumers use only the supplied handle or their existing fallback path. - Make `codex_rollout::state_db::init` the local state startup path: it opens/migrates SQLite, runs rollout metadata backfill when needed, waits for concurrent backfill workers up to a bounded timeout, verifies completion, and then returns the initialized handle. - Keep optional/non-owning SQLite helpers, such as remote TUI local reads, as open-only paths that do not run startup backfill. - Switch app-server startup from direct `codex_state::StateRuntime::init` to the rollout state initializer so app-server cannot skip rollout backfill. - Collapse split rollout lookup/list APIs so callers use the normal methods with an optional state handle instead of `_with_state_db` variants. - Restore `getConversationSummary(ThreadId)` to delegate through `ThreadStore::read_thread` instead of a LocalThreadStore-specific rollout path special case. - Keep DB-backed rollout path lookup keyed on the DB row and file existence, without imposing the filesystem filename convention on existing DB rows. - Verify readable DB-backed rollout paths against `session_meta.id` before returning them, so a stale SQLite row that points at another thread's JSONL falls back to filesystem search and read-repairs the DB row. - Keep `debug prompt-input` filesystem-only so a one-off debug command does not initialize or backfill SQLite state just to print prompt input. - Keep goal-session test Codex homes alive only in the goal-specific helper, rather than leaking tempdirs from the shared session test helper. - Update tests and call sites to pass explicit state handles where DB behavior is expected and explicit `None` where filesystem-only behavior is intended. ## Validation - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo check -p codex-rollout -p codex-thread-store -p codex-app-server -p codex-core -p codex-tui -p codex-exec -p codex-cli --tests` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-rollout state_db_` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-rollout find_thread_path` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-rollout find_thread_path -- --nocapture` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-rollout try_init_ -- --nocapture` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-rollout` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo clippy -p codex-rollout --lib -- -D warnings` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-thread-store read_thread_falls_back_when_sqlite_path_points_to_another_thread -- --nocapture` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-thread-store` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core shell_snapshot` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core --test all personality_migration` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core --test all rollout_list_find` - `RUST_MIN_STACK=8388608 CODEX_SKIP_VENDORED_BWRAP=1 CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core --test all rollout_list_find::find_prefers_sqlite_path_by_id -- --nocapture` - `RUST_MIN_STACK=8388608 CODEX_SKIP_VENDORED_BWRAP=1 CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core --test all rollout_list_find -- --nocapture` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-core interrupt_accounts_active_goal_before_pausing` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-app-server get_auth_status -- --test-threads=1` - `CODEX_SKIP_VENDORED_BWRAP=1 CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo test -p codex-app-server --lib` - `CODEX_SKIP_VENDORED_BWRAP=1 CARGO_TARGET_DIR=/tmp/codex-target-state-db cargo check -p codex-rollout -p codex-app-server --tests` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db just fix -p codex-rollout -p codex-thread-store -p codex-core -p codex-app-server -p codex-tui -p codex-exec -p codex-cli` - `CODEX_SKIP_VENDORED_BWRAP=1 CARGO_TARGET_DIR=/tmp/codex-target-state-db just fix -p codex-rollout -p codex-app-server` - `CARGO_TARGET_DIR=/tmp/codex-target-state-db just fix -p codex-rollout` - `CODEX_SKIP_VENDORED_BWRAP=1 CARGO_TARGET_DIR=/tmp/codex-target-state-db just fix -p codex-core` - `just argument-comment-lint -p codex-core` - `just argument-comment-lint -p codex-rollout` Focused coverage added in `codex-rollout`: - `recorder::tests::state_db_init_backfills_before_returning` verifies the rollout metadata row exists before startup init returns. - `state_db::tests::try_init_waits_for_concurrent_startup_backfill` verifies startup waits for another worker to finish backfill instead of disabling the handle for the process. - `state_db::tests::try_init_times_out_waiting_for_stuck_startup_backfill` verifies startup does not hang indefinitely on a stuck backfill lease. - `tests::find_thread_path_accepts_existing_state_db_path_without_canonical_filename` verifies DB-backed lookup accepts valid existing rollout paths even when the filename does not include the thread UUID. - `tests::find_thread_path_falls_back_when_db_path_points_to_another_thread` verifies DB-backed lookup ignores a stale row whose existing path belongs to another thread and read-repairs the row after filesystem fallback. Focused coverage updated in `codex-core`: - `rollout_list_find::find_prefers_sqlite_path_by_id` now uses a DB-preferred rollout file with matching `session_meta.id`, so it still verifies that valid SQLite paths win without depending on stale/empty rollout contents. `cargo test -p codex-app-server thread_list_respects_search_term_filter -- --test-threads=1 --nocapture` was attempted locally but timed out waiting for the app-server test harness `initialize` response before reaching the changed thread-list code path. `bazel test //codex-rs/thread-store:thread-store-unit-tests --test_output=errors` was attempted locally after the thread-store fix, but this container failed before target analysis while fetching `v8+` through BuildBuddy/direct GitHub. The equivalent local crate coverage, including `cargo test -p codex-thread-store`, passes. A plain local `cargo check -p codex-rollout -p codex-app-server --tests` also requires system `libcap.pc` for `codex-linux-sandbox`; the follow-up app-server check above used `CODEX_SKIP_VENDORED_BWRAP=1` in this container.
This commit is contained in:
committed by
GitHub
Unverified
parent
0035d7bd18
commit
4d201e340e
@@ -144,6 +144,7 @@ use codex_protocol::openai_models::ModelUpgrade;
|
||||
use codex_protocol::openai_models::ReasoningEffort as ReasoningEffortConfig;
|
||||
#[cfg(target_os = "windows")]
|
||||
use codex_protocol::permissions::FileSystemSandboxKind;
|
||||
use codex_rollout::StateDbHandle;
|
||||
use codex_terminal_detection::user_agent;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use color_eyre::eyre::Result;
|
||||
@@ -433,6 +434,7 @@ pub(crate) struct App {
|
||||
pub(crate) chat_widget: ChatWidget,
|
||||
/// Config is stored here so we can recreate ChatWidgets as needed.
|
||||
pub(crate) config: Config,
|
||||
pub(crate) state_db: Option<StateDbHandle>,
|
||||
pub(crate) active_profile: Option<String>,
|
||||
cli_kv_overrides: Vec<(String, TomlValue)>,
|
||||
harness_overrides: ConfigOverrides,
|
||||
@@ -609,6 +611,7 @@ impl App {
|
||||
should_prompt_windows_sandbox_nux_at_startup: bool,
|
||||
remote_app_server_url: Option<String>,
|
||||
remote_app_server_auth_token: Option<String>,
|
||||
state_db: Option<StateDbHandle>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
) -> Result<AppExitInfo> {
|
||||
use tokio_stream::StreamExt;
|
||||
@@ -854,6 +857,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
app_event_tx,
|
||||
chat_widget,
|
||||
config,
|
||||
state_db,
|
||||
active_profile,
|
||||
cli_kv_overrides,
|
||||
harness_overrides,
|
||||
|
||||
@@ -61,6 +61,7 @@ impl App {
|
||||
},
|
||||
None => crate::AppServerTarget::Embedded,
|
||||
},
|
||||
self.state_db.clone(),
|
||||
self.environment_manager.clone(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -638,7 +638,7 @@ impl App {
|
||||
} else {
|
||||
match crate::session_resume::resolve_cwd_for_resume_or_fork(
|
||||
tui,
|
||||
&self.config,
|
||||
self.state_db.as_deref(),
|
||||
¤t_cwd,
|
||||
target_session.thread_id,
|
||||
target_session.path.as_deref(),
|
||||
|
||||
@@ -20,6 +20,7 @@ pub(super) async fn make_test_app() -> App {
|
||||
app_event_tx,
|
||||
chat_widget,
|
||||
config,
|
||||
state_db: None,
|
||||
active_profile: None,
|
||||
cli_kv_overrides: Vec::new(),
|
||||
harness_overrides: ConfigOverrides::default(),
|
||||
|
||||
@@ -3771,6 +3771,7 @@ async fn make_test_app() -> App {
|
||||
app_event_tx,
|
||||
chat_widget,
|
||||
config,
|
||||
state_db: None,
|
||||
active_profile: None,
|
||||
cli_kv_overrides: Vec::new(),
|
||||
harness_overrides: ConfigOverrides::default(),
|
||||
@@ -3832,6 +3833,7 @@ async fn make_test_app_with_channels() -> (
|
||||
app_event_tx,
|
||||
chat_widget,
|
||||
config,
|
||||
state_db: None,
|
||||
active_profile: None,
|
||||
cli_kv_overrides: Vec::new(),
|
||||
harness_overrides: ConfigOverrides::default(),
|
||||
|
||||
@@ -916,7 +916,7 @@ impl App {
|
||||
session.cwd = notification.thread.cwd.clone();
|
||||
let rollout_path = notification.thread.path.clone();
|
||||
if let Some(model) =
|
||||
read_session_model(&self.config, thread_id, rollout_path.as_deref()).await
|
||||
read_session_model(self.state_db.as_deref(), thread_id, rollout_path.as_deref()).await
|
||||
{
|
||||
session.model = model;
|
||||
} else if rollout_path.is_some() {
|
||||
|
||||
@@ -87,7 +87,7 @@ impl App {
|
||||
session.instruction_source_paths = Vec::new();
|
||||
session.rollout_path = thread.path.clone();
|
||||
if let Some(model) =
|
||||
read_session_model(&self.config, thread_id, thread.path.as_deref()).await
|
||||
read_session_model(self.state_db.as_deref(), thread_id, thread.path.as_deref()).await
|
||||
{
|
||||
session.model = model;
|
||||
} else if thread.path.is_some() {
|
||||
|
||||
+63
-13
@@ -49,7 +49,8 @@ use codex_protocol::ThreadId;
|
||||
use codex_protocol::config_types::AltScreenMode;
|
||||
use codex_protocol::config_types::SandboxMode;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_rollout::state_db::get_state_db;
|
||||
use codex_rollout::StateDbHandle;
|
||||
use codex_rollout::state_db;
|
||||
use codex_state::log_db;
|
||||
use codex_terminal_detection::terminal_info;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
@@ -271,6 +272,7 @@ async fn start_embedded_app_server(
|
||||
cloud_requirements: CloudRequirementsLoader,
|
||||
feedback: codex_feedback::CodexFeedback,
|
||||
log_db: Option<log_db::LogDbLayer>,
|
||||
state_db: Option<StateDbHandle>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
) -> color_eyre::Result<InProcessAppServerClient> {
|
||||
start_embedded_app_server_with(
|
||||
@@ -281,6 +283,7 @@ async fn start_embedded_app_server(
|
||||
cloud_requirements,
|
||||
feedback,
|
||||
log_db,
|
||||
state_db,
|
||||
environment_manager,
|
||||
InProcessAppServerClient::start,
|
||||
)
|
||||
@@ -398,6 +401,7 @@ async fn start_app_server(
|
||||
cloud_requirements: CloudRequirementsLoader,
|
||||
feedback: codex_feedback::CodexFeedback,
|
||||
log_db: Option<log_db::LogDbLayer>,
|
||||
state_db: Option<StateDbHandle>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
) -> color_eyre::Result<AppServerClient> {
|
||||
match target {
|
||||
@@ -409,6 +413,7 @@ async fn start_app_server(
|
||||
cloud_requirements,
|
||||
feedback,
|
||||
log_db,
|
||||
state_db,
|
||||
environment_manager,
|
||||
)
|
||||
.await
|
||||
@@ -423,6 +428,7 @@ async fn start_app_server(
|
||||
pub(crate) async fn start_app_server_for_picker(
|
||||
config: &Config,
|
||||
target: &AppServerTarget,
|
||||
state_db: Option<StateDbHandle>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
) -> color_eyre::Result<AppServerSession> {
|
||||
let app_server = start_app_server(
|
||||
@@ -434,6 +440,7 @@ pub(crate) async fn start_app_server_for_picker(
|
||||
CloudRequirementsLoader::default(),
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
state_db,
|
||||
environment_manager,
|
||||
)
|
||||
.await?;
|
||||
@@ -444,9 +451,11 @@ pub(crate) async fn start_app_server_for_picker(
|
||||
pub(crate) async fn start_embedded_app_server_for_picker(
|
||||
config: &Config,
|
||||
) -> color_eyre::Result<AppServerSession> {
|
||||
let state_db = state_db::init(config).await;
|
||||
start_app_server_for_picker(
|
||||
config,
|
||||
&AppServerTarget::Embedded,
|
||||
state_db,
|
||||
Arc::new(EnvironmentManager::default_for_tests()),
|
||||
)
|
||||
.await
|
||||
@@ -461,6 +470,7 @@ async fn start_embedded_app_server_with<F, Fut>(
|
||||
cloud_requirements: CloudRequirementsLoader,
|
||||
feedback: codex_feedback::CodexFeedback,
|
||||
log_db: Option<log_db::LogDbLayer>,
|
||||
state_db: Option<StateDbHandle>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
start_client: F,
|
||||
) -> color_eyre::Result<InProcessAppServerClient>
|
||||
@@ -486,6 +496,7 @@ where
|
||||
cloud_requirements,
|
||||
feedback,
|
||||
log_db,
|
||||
state_db,
|
||||
environment_manager,
|
||||
config_warnings,
|
||||
session_source: serde_json::from_value(serde_json::json!("cli"))
|
||||
@@ -787,15 +798,6 @@ pub async fn run_main(
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(err) = crate::legacy_core::personality_migration::maybe_migrate_personality(
|
||||
&codex_home,
|
||||
&config_toml,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::warn!(error = %err, "failed to run personality migration");
|
||||
}
|
||||
|
||||
let chatgpt_base_url = config_toml
|
||||
.chatgpt_base_url
|
||||
.clone()
|
||||
@@ -865,13 +867,53 @@ pub async fn run_main(
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let config = load_config_or_exit(
|
||||
let mut config = load_config_or_exit(
|
||||
cli_kv_overrides.clone(),
|
||||
overrides.clone(),
|
||||
cloud_requirements.clone(),
|
||||
)
|
||||
.await;
|
||||
|
||||
let state_db = match &app_server_target {
|
||||
AppServerTarget::Embedded => state_db::init(&config).await,
|
||||
AppServerTarget::Remote { .. } => state_db::get_state_db(&config).await,
|
||||
};
|
||||
|
||||
let effective_toml = config.config_layer_stack.effective_config();
|
||||
match effective_toml.try_into() {
|
||||
Ok(config_toml) => {
|
||||
match crate::legacy_core::personality_migration::maybe_migrate_personality(
|
||||
&config.codex_home,
|
||||
&config_toml,
|
||||
state_db.clone(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(
|
||||
crate::legacy_core::personality_migration::PersonalityMigrationStatus::Applied,
|
||||
) => {
|
||||
config = load_config_or_exit(
|
||||
cli_kv_overrides.clone(),
|
||||
overrides.clone(),
|
||||
cloud_requirements.clone(),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
Ok(
|
||||
crate::legacy_core::personality_migration::PersonalityMigrationStatus::SkippedMarker
|
||||
| crate::legacy_core::personality_migration::PersonalityMigrationStatus::SkippedExplicitPersonality
|
||||
| crate::legacy_core::personality_migration::PersonalityMigrationStatus::SkippedNoSessions,
|
||||
) => {}
|
||||
Err(err) => {
|
||||
tracing::warn!(error = %err, "failed to run personality migration");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
tracing::warn!(error = %err, "failed to deserialize config for personality migration");
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::print_stderr)]
|
||||
match check_execpolicy_for_warnings(&config.config_layer_stack).await {
|
||||
Ok(None) => {}
|
||||
@@ -1003,7 +1045,7 @@ pub async fn run_main(
|
||||
|
||||
let otel_tracing_layer = otel.as_ref().and_then(|o| o.tracing_layer());
|
||||
|
||||
let log_db = get_state_db(&config).await.map(log_db::start);
|
||||
let log_db = state_db.clone().map(log_db::start);
|
||||
let log_db_layer = log_db
|
||||
.clone()
|
||||
.map(|layer| layer.with_filter(Targets::new().with_default(Level::TRACE)));
|
||||
@@ -1029,6 +1071,7 @@ pub async fn run_main(
|
||||
cloud_requirements,
|
||||
feedback,
|
||||
log_db,
|
||||
state_db,
|
||||
remote_url,
|
||||
remote_auth_token,
|
||||
environment_manager,
|
||||
@@ -1050,6 +1093,7 @@ async fn run_ratatui_app(
|
||||
mut cloud_requirements: CloudRequirementsLoader,
|
||||
feedback: codex_feedback::CodexFeedback,
|
||||
log_db: Option<log_db::LogDbLayer>,
|
||||
state_db: Option<StateDbHandle>,
|
||||
remote_url: Option<String>,
|
||||
remote_auth_token: Option<String>,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
@@ -1109,6 +1153,7 @@ async fn run_ratatui_app(
|
||||
cloud_requirements.clone(),
|
||||
feedback.clone(),
|
||||
log_db.clone(),
|
||||
state_db.clone(),
|
||||
environment_manager.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1360,7 +1405,7 @@ async fn run_ratatui_app(
|
||||
} else {
|
||||
match resolve_cwd_for_resume_or_fork(
|
||||
&mut tui,
|
||||
&config,
|
||||
state_db.as_deref(),
|
||||
¤t_cwd,
|
||||
target_session.thread_id,
|
||||
target_session.path.as_deref(),
|
||||
@@ -1438,6 +1483,7 @@ async fn run_ratatui_app(
|
||||
cloud_requirements.clone(),
|
||||
feedback.clone(),
|
||||
log_db.clone(),
|
||||
state_db.clone(),
|
||||
environment_manager.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1468,6 +1514,7 @@ async fn run_ratatui_app(
|
||||
should_prompt_windows_sandbox_nux_at_startup,
|
||||
remote_url,
|
||||
remote_auth_token,
|
||||
state_db,
|
||||
environment_manager,
|
||||
)
|
||||
.await;
|
||||
@@ -1672,6 +1719,7 @@ mod tests {
|
||||
async fn start_test_embedded_app_server(
|
||||
config: Config,
|
||||
) -> color_eyre::Result<InProcessAppServerClient> {
|
||||
let state_db = state_db::init(&config).await;
|
||||
start_embedded_app_server(
|
||||
Arg0DispatchPaths::default(),
|
||||
config,
|
||||
@@ -1680,6 +1728,7 @@ mod tests {
|
||||
CloudRequirementsLoader::default(),
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
state_db,
|
||||
Arc::new(EnvironmentManager::default_for_tests()),
|
||||
)
|
||||
.await
|
||||
@@ -2026,6 +2075,7 @@ mod tests {
|
||||
CloudRequirementsLoader::default(),
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
/*state_db*/ None,
|
||||
Arc::new(EnvironmentManager::default_for_tests()),
|
||||
|_args| async { Err(std::io::Error::other("boom")) },
|
||||
)
|
||||
|
||||
@@ -1048,6 +1048,7 @@ mod tests {
|
||||
.await,
|
||||
feedback: codex_feedback::CodexFeedback::new(),
|
||||
log_db: None,
|
||||
state_db: None,
|
||||
environment_manager: Arc::new(
|
||||
codex_app_server_client::EnvironmentManager::default_for_tests(),
|
||||
),
|
||||
|
||||
@@ -12,10 +12,9 @@ use crate::cwd_prompt;
|
||||
use crate::cwd_prompt::CwdPromptAction;
|
||||
use crate::cwd_prompt::CwdPromptOutcome;
|
||||
use crate::cwd_prompt::CwdSelection;
|
||||
use crate::legacy_core::config::Config;
|
||||
use crate::tui::Tui;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_rollout::state_db::get_state_db;
|
||||
use codex_state::StateRuntime;
|
||||
use codex_utils_path as path_utils;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
@@ -66,11 +65,11 @@ pub(crate) async fn resolve_session_thread_id(
|
||||
}
|
||||
|
||||
pub(crate) async fn read_session_model(
|
||||
config: &Config,
|
||||
state_db_ctx: Option<&StateRuntime>,
|
||||
thread_id: ThreadId,
|
||||
path: Option<&Path>,
|
||||
) -> Option<String> {
|
||||
if let Some(state_db_ctx) = get_state_db(config).await
|
||||
if let Some(state_db_ctx) = state_db_ctx
|
||||
&& let Ok(Some(metadata)) = state_db_ctx.get_thread(thread_id).await
|
||||
&& let Some(model) = metadata.model
|
||||
{
|
||||
@@ -86,14 +85,14 @@ pub(crate) async fn read_session_model(
|
||||
|
||||
pub(crate) async fn resolve_cwd_for_resume_or_fork(
|
||||
tui: &mut Tui,
|
||||
config: &Config,
|
||||
state_db_ctx: Option<&StateRuntime>,
|
||||
current_cwd: &Path,
|
||||
thread_id: ThreadId,
|
||||
path: Option<&Path>,
|
||||
action: CwdPromptAction,
|
||||
allow_prompt: bool,
|
||||
) -> color_eyre::Result<ResolveCwdOutcome> {
|
||||
let Some(history_cwd) = read_session_cwd(config, thread_id, path).await else {
|
||||
let Some(history_cwd) = read_session_cwd(state_db_ctx, thread_id, path).await else {
|
||||
return Ok(ResolveCwdOutcome::Continue(None));
|
||||
};
|
||||
if allow_prompt && cwds_differ(current_cwd, &history_cwd) {
|
||||
@@ -113,11 +112,11 @@ pub(crate) async fn resolve_cwd_for_resume_or_fork(
|
||||
}
|
||||
|
||||
async fn read_session_cwd(
|
||||
config: &Config,
|
||||
state_db_ctx: Option<&StateRuntime>,
|
||||
thread_id: ThreadId,
|
||||
path: Option<&Path>,
|
||||
) -> Option<PathBuf> {
|
||||
if let Some(state_db_ctx) = get_state_db(config).await
|
||||
if let Some(state_db_ctx) = state_db_ctx
|
||||
&& let Ok(Some(metadata)) = state_db_ctx.get_thread(thread_id).await
|
||||
{
|
||||
return Some(metadata.cwd);
|
||||
|
||||
Reference in New Issue
Block a user