Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Bump thread updated_at on unarchive to refresh sidebar ordering (#10280)

Charley Cunninghamd3514bbdd221
diff --git a/codex-rs/app-server/src/codex_message_processor.rs b/codex-rs/app-server/src/codex_message_processor.rs
index 76b2393e8a..d044786bdf 100644
--- a/codex-rs/app-server/src/codex_message_processor.rs
+++ b/codex-rs/app-server/src/codex_message_processor.rs
@@ -202,6 +202,8 @@ use codex_utils_json_to_toml::json_to_toml;
use std::collections::HashMap;
use std::collections::HashSet;
use std::ffi::OsStr;
+use std::fs::FileTimes;
+use std::fs::OpenOptions;
use std::io::Error as IoError;
use std::path::Path;
use std::path::PathBuf;
@@ -209,6 +211,7 @@ use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::time::Duration;
+use std::time::SystemTime;
use tokio::sync::Mutex;
use tokio::sync::broadcast;
use tokio::sync::oneshot;
@@ -1978,6 +1981,28 @@ impl CodexMessageProcessor {
message: format!("failed to unarchive thread: {err}"),
data: None,
})?;
+ tokio::task::spawn_blocking({
+ let restored_path = restored_path.clone();
+ move || -> std::io::Result<()> {
+ let times = FileTimes::new().set_modified(SystemTime::now());
+ OpenOptions::new()
+ .append(true)
+ .open(&restored_path)?
+ .set_times(times)?;
+ Ok(())
+ }
+ })
+ .await
+ .map_err(|err| JSONRPCErrorError {
+ code: INTERNAL_ERROR_CODE,
+ message: format!("failed to update unarchived thread timestamp: {err}"),
+ data: None,
+ })?
+ .map_err(|err| JSONRPCErrorError {
+ code: INTERNAL_ERROR_CODE,
+ message: format!("failed to update unarchived thread timestamp: {err}"),
+ data: None,
+ })?;
if let Some(ctx) = state_db_ctx {
let _ = ctx
.mark_unarchived(thread_id, restored_path.as_path())
diff --git a/codex-rs/app-server/tests/suite/v2/thread_unarchive.rs b/codex-rs/app-server/tests/suite/v2/thread_unarchive.rs
index c56b39e33b..dada1cbf20 100644
--- a/codex-rs/app-server/tests/suite/v2/thread_unarchive.rs
+++ b/codex-rs/app-server/tests/suite/v2/thread_unarchive.rs
@@ -11,7 +11,11 @@ use codex_app_server_protocol::ThreadUnarchiveParams;
use codex_app_server_protocol::ThreadUnarchiveResponse;
use codex_core::find_archived_thread_path_by_id_str;
use codex_core::find_thread_path_by_id_str;
+use std::fs::FileTimes;
+use std::fs::OpenOptions;
use std::path::Path;
+use std::time::Duration;
+use std::time::SystemTime;
use tempfile::TempDir;
use tokio::time::timeout;
@@ -62,6 +66,16 @@ async fn thread_unarchive_moves_rollout_back_into_sessions_directory() -> Result
archived_path.exists(),
"expected {archived_path_display} to exist"
);
+ let old_time = SystemTime::UNIX_EPOCH + Duration::from_secs(1);
+ let old_timestamp = old_time
+ .duration_since(SystemTime::UNIX_EPOCH)
+ .expect("old timestamp")
+ .as_secs() as i64;
+ let times = FileTimes::new().set_modified(old_time);
+ OpenOptions::new()
+ .append(true)
+ .open(&archived_path)?
+ .set_times(times)?;
let unarchive_id = mcp
.send_thread_unarchive_request(ThreadUnarchiveParams {
@@ -73,7 +87,13 @@ async fn thread_unarchive_moves_rollout_back_into_sessions_directory() -> Result
mcp.read_stream_until_response_message(RequestId::Integer(unarchive_id)),
)
.await??;
- let _: ThreadUnarchiveResponse = to_response::<ThreadUnarchiveResponse>(unarchive_resp)?;
+ let ThreadUnarchiveResponse {
+ thread: unarchived_thread,
+ } = to_response::<ThreadUnarchiveResponse>(unarchive_resp)?;
+ assert!(
+ unarchived_thread.updated_at > old_timestamp,
+ "expected updated_at to be bumped on unarchive"
+ );
let rollout_path_display = rollout_path.display();
assert!(