feat: simplify DB further (#13771)

This commit is contained in:
jif-oai
2026-03-07 12:48:36 +01:00
committed by GitHub
parent 5ceff6588e
commit cf143bf71e
28 changed files with 147 additions and 297 deletions

View File

@@ -447,7 +447,6 @@ ON CONFLICT(thread_id, position) DO NOTHING
&self,
builder: &ThreadMetadataBuilder,
items: &[RolloutItem],
otel: Option<&SessionTelemetry>,
new_thread_memory_mode: Option<&str>,
updated_at_override: Option<DateTime<Utc>>,
) -> anyhow::Result<()> {
@@ -480,20 +479,12 @@ ON CONFLICT(thread_id, position) DO NOTHING
} else {
self.upsert_thread(&metadata).await
};
if let Err(err) = upsert_result {
if let Some(otel) = otel {
otel.counter(DB_ERROR_METRIC, 1, &[("stage", "apply_rollout_items")]);
}
return Err(err);
}
upsert_result?;
if let Some(memory_mode) = extract_memory_mode(items)
&& let Err(err) = self
.set_thread_memory_mode(builder.id, memory_mode.as_str())
.await
{
if let Some(otel) = otel {
otel.counter(DB_ERROR_METRIC, 1, &[("stage", "set_thread_memory_mode")]);
}
return Err(err);
}
let dynamic_tools = extract_dynamic_tools(items);
@@ -502,9 +493,6 @@ ON CONFLICT(thread_id, position) DO NOTHING
.persist_dynamic_tools(builder.id, dynamic_tools.as_deref())
.await
{
if let Some(otel) = otel {
otel.counter(DB_ERROR_METRIC, 1, &[("stage", "persist_dynamic_tools")]);
}
return Err(err);
}
Ok(())
@@ -678,7 +666,7 @@ mod tests {
#[tokio::test]
async fn upsert_thread_keeps_creation_memory_mode_for_existing_rows() {
let codex_home = unique_temp_dir();
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None)
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("state db should initialize");
let thread_id =
@@ -716,7 +704,7 @@ mod tests {
#[tokio::test]
async fn apply_rollout_items_restores_memory_mode_from_session_meta() {
let codex_home = unique_temp_dir();
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None)
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("state db should initialize");
let thread_id =
@@ -754,7 +742,7 @@ mod tests {
})];
runtime
.apply_rollout_items(&builder, &items, None, None, None)
.apply_rollout_items(&builder, &items, None, None)
.await
.expect("apply_rollout_items should succeed");
@@ -768,7 +756,7 @@ mod tests {
#[tokio::test]
async fn apply_rollout_items_preserves_existing_git_branch_and_fills_missing_git_fields() {
let codex_home = unique_temp_dir();
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None)
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("state db should initialize");
let thread_id =
@@ -812,7 +800,7 @@ mod tests {
})];
runtime
.apply_rollout_items(&builder, &items, None, None, None)
.apply_rollout_items(&builder, &items, None, None)
.await
.expect("apply_rollout_items should succeed");
@@ -832,7 +820,7 @@ mod tests {
#[tokio::test]
async fn update_thread_git_info_preserves_newer_non_git_metadata() {
let codex_home = unique_temp_dir();
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None)
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("state db should initialize");
let thread_id =
@@ -891,7 +879,7 @@ mod tests {
#[tokio::test]
async fn insert_thread_if_absent_preserves_existing_metadata() {
let codex_home = unique_temp_dir();
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None)
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("state db should initialize");
let thread_id =
@@ -936,7 +924,7 @@ mod tests {
#[tokio::test]
async fn update_thread_git_info_can_clear_fields() {
let codex_home = unique_temp_dir();
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None)
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("state db should initialize");
let thread_id =
@@ -970,7 +958,7 @@ mod tests {
#[tokio::test]
async fn touch_thread_updated_at_updates_only_updated_at() {
let codex_home = unique_temp_dir();
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None)
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("state db should initialize");
let thread_id =
@@ -1007,7 +995,7 @@ mod tests {
#[tokio::test]
async fn apply_rollout_items_uses_override_updated_at_when_provided() {
let codex_home = unique_temp_dir();
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string(), None)
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("state db should initialize");
let thread_id =
@@ -1045,7 +1033,7 @@ mod tests {
DateTime::<Utc>::from_timestamp(1_700_001_234, 0).expect("timestamp");
runtime
.apply_rollout_items(&builder, &items, None, None, Some(override_updated_at))
.apply_rollout_items(&builder, &items, None, Some(override_updated_at))
.await
.expect("apply_rollout_items should succeed");