mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:19:04 +00:00
Add thread recencyAt for sidebar ordering (#27910)
## Summary Add a server-owned `recencyAt` timestamp and `recency_at` thread-list sort key for product recency ordering while preserving the existing meaning of `updatedAt` as the latest persisted thread mutation. This is the server-side alternative to #27697. Rather than narrowing `updatedAt`, clients can sort the sidebar by `recency_at` and continue treating `updatedAt` as mutation time. Paired Codex Apps PR: [openai/openai#1024599](https://github.com/openai/openai/pull/1024599) ## Contract - `recencyAt` initializes when a thread is created. - A turn start advances `recencyAt` monotonically. - Commentary, agent output, tool results, token/accounting updates, turn completion, archive, unarchive, resume, and generic metadata writes do not advance it. - `updatedAt` retains its existing behavior and continues to advance for persisted thread mutations. - Current servers populate `recencyAt`; the response field is optional in generated TypeScript so clients connected to older servers can fall back to `updatedAt`. - Filesystem-only fallback uses existing updated/mtime ordering when SQLite is unavailable. ## Persistence and compatibility Migration 0038 adds second- and millisecond-precision recency columns, backfills them from the existing updated timestamp, creates list indexes, and includes an insert trigger so older binaries writing to a migrated database seed recency without causing later mutations to advance it. Generic metadata upserts preserve existing recency values. Turn-start updates use a dedicated monotonic touch, and process-local allocation keeps millisecond cursor values unique. State DB list, search, read, filtered-list repair, rollout fallback propagation, and app-server conversions all carry the new field. ## API `Thread` responses include: ```ts recencyAt?: number ``` `thread/list` and `thread/search` accept: ```json { "sortKey": "recency_at" } ``` Generated TypeScript and JSON schemas are included. ## Validation - `just test -p codex-state` — 146 passed - `just test -p codex-rollout` — 69 passed - `just test -p codex-thread-store` — 81 passed - `just test -p codex-app-server-protocol` — 231 passed - Focused app-server list ordering, response mapping, archive/unarchive, and resume lifecycle tests passed - Scoped `just fix` for state, rollout, thread-store, app-server-protocol, and app-server - `just fmt` - `git diff --check` - Independent correctness, simplicity, elegance, security, and test-quality reviews; actionable ordering, lifecycle, query-projection, and timestamp-uniqueness findings were addressed
This commit is contained in:
1 parent
f0cb96bcb1
commit
fac3158c2a
67 files changed
+1153
-99
No files matched your search
@@ -175,6 +175,7 @@ SELECT
|
||||
threads.rollout_path,
|
||||
threads.created_at_ms AS created_at,
|
||||
threads.updated_at_ms AS updated_at,
|
||||
threads.recency_at_ms AS recency_at,
|
||||
threads.source,
|
||||
threads.thread_source,
|
||||
threads.agent_path,
|
||||
@@ -545,6 +546,7 @@ SELECT
|
||||
threads.rollout_path,
|
||||
threads.created_at_ms AS created_at,
|
||||
threads.updated_at_ms AS updated_at,
|
||||
threads.recency_at_ms AS recency_at,
|
||||
threads.source,
|
||||
threads.thread_source,
|
||||
threads.agent_nickname,
|
||||
|
||||
@@ -47,6 +47,7 @@ pub(super) fn test_thread_metadata(
|
||||
rollout_path: codex_home.join(format!("rollout-{thread_id}.jsonl")),
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
recency_at: now,
|
||||
source: "cli".to_string(),
|
||||
thread_source: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::*;
|
||||
use crate::SortDirection;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use std::sync::atomic::AtomicI64;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
impl StateRuntime {
|
||||
@@ -12,6 +13,7 @@ SELECT
|
||||
threads.rollout_path,
|
||||
threads.created_at_ms AS created_at,
|
||||
threads.updated_at_ms AS updated_at,
|
||||
threads.recency_at_ms AS recency_at,
|
||||
threads.source,
|
||||
threads.thread_source,
|
||||
threads.agent_nickname,
|
||||
@@ -498,6 +500,7 @@ ON CONFLICT(child_thread_id) DO NOTHING
|
||||
metadata: &crate::ThreadMetadata,
|
||||
) -> anyhow::Result<bool> {
|
||||
let updated_at = self.allocate_thread_updated_at(metadata.updated_at)?;
|
||||
let recency_at = self.allocate_thread_recency_at(metadata.recency_at)?;
|
||||
let preview = metadata_preview(metadata);
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
@@ -506,8 +509,10 @@ INSERT INTO threads (
|
||||
rollout_path,
|
||||
created_at,
|
||||
updated_at,
|
||||
recency_at,
|
||||
created_at_ms,
|
||||
updated_at_ms,
|
||||
recency_at_ms,
|
||||
source,
|
||||
thread_source,
|
||||
agent_nickname,
|
||||
@@ -530,7 +535,7 @@ INSERT INTO threads (
|
||||
git_branch,
|
||||
git_origin_url,
|
||||
memory_mode
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO NOTHING
|
||||
"#,
|
||||
)
|
||||
@@ -538,8 +543,10 @@ ON CONFLICT(id) DO NOTHING
|
||||
.bind(metadata.rollout_path.display().to_string())
|
||||
.bind(datetime_to_epoch_seconds(metadata.created_at))
|
||||
.bind(datetime_to_epoch_seconds(updated_at))
|
||||
.bind(datetime_to_epoch_seconds(recency_at))
|
||||
.bind(datetime_to_epoch_millis(metadata.created_at))
|
||||
.bind(datetime_to_epoch_millis(updated_at))
|
||||
.bind(datetime_to_epoch_millis(recency_at))
|
||||
.bind(metadata.source.as_str())
|
||||
.bind(
|
||||
metadata
|
||||
@@ -621,6 +628,32 @@ ON CONFLICT(id) DO NOTHING
|
||||
Ok(result.rows_affected() > 0)
|
||||
}
|
||||
|
||||
pub async fn touch_thread_recency_at(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
recency_at: DateTime<Utc>,
|
||||
) -> anyhow::Result<bool> {
|
||||
let recency_at = self.allocate_thread_recency_at(recency_at)?;
|
||||
let recency_at_seconds = datetime_to_epoch_seconds(recency_at);
|
||||
let recency_at_millis = datetime_to_epoch_millis(recency_at);
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
UPDATE threads
|
||||
SET
|
||||
recency_at = MAX(?, MAX(?, recency_at_ms + 1) / 1000),
|
||||
recency_at_ms = MAX(?, recency_at_ms + 1)
|
||||
WHERE id = ?
|
||||
"#,
|
||||
)
|
||||
.bind(recency_at_seconds)
|
||||
.bind(recency_at_millis)
|
||||
.bind(recency_at_millis)
|
||||
.bind(thread_id.to_string())
|
||||
.execute(self.pool.as_ref())
|
||||
.await?;
|
||||
Ok(result.rows_affected() > 0)
|
||||
}
|
||||
|
||||
/// Allocate a persisted `updated_at` value for thread-list cursor ordering.
|
||||
///
|
||||
/// We keep a process-local high-water mark so hot rollout writes can get unique,
|
||||
@@ -631,42 +664,56 @@ ON CONFLICT(id) DO NOTHING
|
||||
&self,
|
||||
updated_at: DateTime<Utc>,
|
||||
) -> anyhow::Result<DateTime<Utc>> {
|
||||
let candidate = datetime_to_epoch_millis(updated_at);
|
||||
let allocated = loop {
|
||||
let current = self.thread_updated_at_millis.load(Ordering::Relaxed);
|
||||
|
||||
// New wall-clock time: advance the process-local high-water mark and use it as-is.
|
||||
if candidate > current {
|
||||
if self
|
||||
.thread_updated_at_millis
|
||||
.compare_exchange(current, candidate, Ordering::Relaxed, Ordering::Relaxed)
|
||||
.is_ok()
|
||||
{
|
||||
break candidate;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Older timestamps come from backfill/repair paths that preserve rollout mtimes.
|
||||
// Do not drag historical rows forward just because this process has seen newer writes.
|
||||
if candidate.saturating_add(1000) <= current {
|
||||
break candidate;
|
||||
}
|
||||
|
||||
// Same hot one-second bucket as the current high-water mark. Allocate the next
|
||||
// millisecond so updated_at remains unique and cursor-orderable inside the process.
|
||||
let bumped = current.saturating_add(1);
|
||||
if self
|
||||
.thread_updated_at_millis
|
||||
.compare_exchange(current, bumped, Ordering::Relaxed, Ordering::Relaxed)
|
||||
.is_ok()
|
||||
{
|
||||
break bumped;
|
||||
}
|
||||
};
|
||||
epoch_millis_to_datetime(allocated)
|
||||
allocate_thread_timestamp(self.thread_updated_at_millis.as_ref(), updated_at)
|
||||
}
|
||||
|
||||
fn allocate_thread_recency_at(
|
||||
&self,
|
||||
recency_at: DateTime<Utc>,
|
||||
) -> anyhow::Result<DateTime<Utc>> {
|
||||
allocate_thread_timestamp(self.thread_recency_at_millis.as_ref(), recency_at)
|
||||
}
|
||||
}
|
||||
|
||||
fn allocate_thread_timestamp(
|
||||
high_water_mark: &AtomicI64,
|
||||
timestamp: DateTime<Utc>,
|
||||
) -> anyhow::Result<DateTime<Utc>> {
|
||||
let candidate = datetime_to_epoch_millis(timestamp);
|
||||
let allocated = loop {
|
||||
let current = high_water_mark.load(Ordering::Relaxed);
|
||||
|
||||
// New wall-clock time: advance the process-local high-water mark and use it as-is.
|
||||
if candidate > current {
|
||||
if high_water_mark
|
||||
.compare_exchange(current, candidate, Ordering::Relaxed, Ordering::Relaxed)
|
||||
.is_ok()
|
||||
{
|
||||
break candidate;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Older timestamps come from backfill/repair paths that preserve rollout mtimes.
|
||||
// Do not drag historical rows forward just because this process has seen newer writes.
|
||||
if candidate.saturating_add(1000) <= current {
|
||||
break candidate;
|
||||
}
|
||||
|
||||
// Same hot one-second bucket as the current high-water mark. Allocate the next
|
||||
// millisecond so the timestamp remains unique and cursor-orderable inside the process.
|
||||
let bumped = current.saturating_add(1);
|
||||
if high_water_mark
|
||||
.compare_exchange(current, bumped, Ordering::Relaxed, Ordering::Relaxed)
|
||||
.is_ok()
|
||||
{
|
||||
break bumped;
|
||||
}
|
||||
};
|
||||
epoch_millis_to_datetime(allocated)
|
||||
}
|
||||
|
||||
impl StateRuntime {
|
||||
pub async fn update_thread_git_info(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
@@ -702,6 +749,7 @@ WHERE id = ?
|
||||
creation_memory_mode: Option<&str>,
|
||||
) -> anyhow::Result<()> {
|
||||
let updated_at = self.allocate_thread_updated_at(metadata.updated_at)?;
|
||||
let insert_recency_at = self.allocate_thread_recency_at(metadata.recency_at)?;
|
||||
let preview = metadata_preview(metadata);
|
||||
// Backfill/reconcile callers merge existing git info before upserting, but that
|
||||
// read/modify/write is not atomic. Preserve non-null SQLite git fields here so
|
||||
@@ -713,8 +761,10 @@ INSERT INTO threads (
|
||||
rollout_path,
|
||||
created_at,
|
||||
updated_at,
|
||||
recency_at,
|
||||
created_at_ms,
|
||||
updated_at_ms,
|
||||
recency_at_ms,
|
||||
source,
|
||||
thread_source,
|
||||
agent_nickname,
|
||||
@@ -737,13 +787,15 @@ INSERT INTO threads (
|
||||
git_branch,
|
||||
git_origin_url,
|
||||
memory_mode
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
rollout_path = excluded.rollout_path,
|
||||
created_at = excluded.created_at,
|
||||
updated_at = excluded.updated_at,
|
||||
recency_at = threads.recency_at,
|
||||
created_at_ms = excluded.created_at_ms,
|
||||
updated_at_ms = excluded.updated_at_ms,
|
||||
recency_at_ms = threads.recency_at_ms,
|
||||
source = excluded.source,
|
||||
thread_source = excluded.thread_source,
|
||||
agent_nickname = excluded.agent_nickname,
|
||||
@@ -771,8 +823,10 @@ ON CONFLICT(id) DO UPDATE SET
|
||||
.bind(metadata.rollout_path.display().to_string())
|
||||
.bind(datetime_to_epoch_seconds(metadata.created_at))
|
||||
.bind(datetime_to_epoch_seconds(updated_at))
|
||||
.bind(datetime_to_epoch_seconds(insert_recency_at))
|
||||
.bind(datetime_to_epoch_millis(metadata.created_at))
|
||||
.bind(datetime_to_epoch_millis(updated_at))
|
||||
.bind(datetime_to_epoch_millis(insert_recency_at))
|
||||
.bind(metadata.source.as_str())
|
||||
.bind(
|
||||
metadata
|
||||
@@ -1079,6 +1133,7 @@ SELECT
|
||||
threads.rollout_path,
|
||||
threads.created_at_ms AS created_at,
|
||||
threads.updated_at_ms AS updated_at,
|
||||
threads.recency_at_ms AS recency_at,
|
||||
threads.source,
|
||||
threads.thread_source,
|
||||
threads.agent_nickname,
|
||||
@@ -1197,6 +1252,7 @@ pub(super) fn push_thread_filters<'a>(
|
||||
let column = match sort_key {
|
||||
SortKey::CreatedAt => "threads.created_at_ms",
|
||||
SortKey::UpdatedAt => "threads.updated_at_ms",
|
||||
SortKey::RecencyAt => "threads.recency_at_ms",
|
||||
};
|
||||
let operator = match sort_direction {
|
||||
SortDirection::Asc => ">",
|
||||
@@ -1208,6 +1264,19 @@ pub(super) fn push_thread_filters<'a>(
|
||||
builder.push(operator);
|
||||
builder.push(" ");
|
||||
builder.push_bind(anchor_ts);
|
||||
if sort_key == SortKey::RecencyAt
|
||||
&& let Some(anchor_id) = anchor.id
|
||||
{
|
||||
builder.push(" OR (");
|
||||
builder.push(column);
|
||||
builder.push(" = ");
|
||||
builder.push_bind(anchor_ts);
|
||||
builder.push(" AND threads.id ");
|
||||
builder.push(operator);
|
||||
builder.push(" ");
|
||||
builder.push_bind(anchor_id.to_string());
|
||||
builder.push(")");
|
||||
}
|
||||
builder.push(")");
|
||||
}
|
||||
}
|
||||
@@ -1232,6 +1301,7 @@ pub(super) fn push_thread_order_and_limit(
|
||||
let order_column = match sort_key {
|
||||
SortKey::CreatedAt => "threads.created_at_ms",
|
||||
SortKey::UpdatedAt => "threads.updated_at_ms",
|
||||
SortKey::RecencyAt => "threads.recency_at_ms",
|
||||
};
|
||||
let order_direction = match sort_direction {
|
||||
SortDirection::Asc => "ASC",
|
||||
@@ -1247,6 +1317,10 @@ pub(super) fn push_thread_order_and_limit(
|
||||
builder.push(order_column);
|
||||
builder.push(" ");
|
||||
builder.push(order_direction);
|
||||
if sort_key == SortKey::RecencyAt {
|
||||
builder.push(", threads.id ");
|
||||
builder.push(order_direction);
|
||||
}
|
||||
builder.push(" LIMIT ");
|
||||
builder.push_bind(limit as i64);
|
||||
}
|
||||
@@ -1521,6 +1595,7 @@ mod tests {
|
||||
|
||||
let anchor = Anchor {
|
||||
ts: older_updated_at,
|
||||
id: None,
|
||||
};
|
||||
let model_providers = ["test-provider".to_string()];
|
||||
let page = runtime
|
||||
@@ -1547,6 +1622,7 @@ mod tests {
|
||||
Some(Anchor {
|
||||
ts: DateTime::<Utc>::from_timestamp_millis(1_700_000_200_000)
|
||||
.expect("valid timestamp"),
|
||||
id: None,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -1631,6 +1707,7 @@ mod tests {
|
||||
Some(Anchor {
|
||||
ts: DateTime::<Utc>::from_timestamp_millis(1_700_000_300_000)
|
||||
.expect("valid timestamp"),
|
||||
id: None,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -1693,6 +1770,7 @@ mod tests {
|
||||
];
|
||||
let anchor = Anchor {
|
||||
ts: DateTime::<Utc>::from_timestamp(1_700_000_000, 0).expect("valid timestamp"),
|
||||
id: None,
|
||||
};
|
||||
for (sort_key, visible_index, cwd_index) in [
|
||||
(
|
||||
@@ -1705,6 +1783,11 @@ mod tests {
|
||||
"idx_threads_visible_updated_at_ms",
|
||||
"idx_threads_archived_cwd_updated_at_ms",
|
||||
),
|
||||
(
|
||||
SortKey::RecencyAt,
|
||||
"idx_threads_visible_recency_at_ms",
|
||||
"idx_threads_archived_cwd_recency_at_ms",
|
||||
),
|
||||
] {
|
||||
for (cwd_filters, anchor, expected_index, expect_temp_sort) in [
|
||||
(None, None, visible_index, false),
|
||||
@@ -2279,6 +2362,186 @@ mod tests {
|
||||
assert_eq!(persisted.preview.as_deref(), Some("first-user-message"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn touch_thread_recency_at_is_monotonic_and_survives_stale_upsert() {
|
||||
let codex_home = unique_temp_dir();
|
||||
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
|
||||
.await
|
||||
.expect("state db should initialize");
|
||||
let thread_id =
|
||||
ThreadId::from_string("00000000-0000-0000-0000-000000000792").expect("valid thread id");
|
||||
let mut metadata = test_thread_metadata(&codex_home, thread_id, codex_home.clone());
|
||||
let original_recency_at = metadata.recency_at;
|
||||
runtime
|
||||
.upsert_thread(&metadata)
|
||||
.await
|
||||
.expect("initial upsert should succeed");
|
||||
|
||||
let touched_at =
|
||||
DateTime::<Utc>::from_timestamp_millis(1_700_001_111_123).expect("timestamp");
|
||||
assert!(
|
||||
runtime
|
||||
.touch_thread_recency_at(thread_id, touched_at)
|
||||
.await
|
||||
.expect("touch should succeed")
|
||||
);
|
||||
|
||||
metadata.updated_at =
|
||||
DateTime::<Utc>::from_timestamp_millis(1_700_001_222_456).expect("timestamp");
|
||||
metadata.title = "updated metadata".to_string();
|
||||
assert_eq!(metadata.recency_at, original_recency_at);
|
||||
runtime
|
||||
.upsert_thread(&metadata)
|
||||
.await
|
||||
.expect("stale metadata upsert should succeed");
|
||||
|
||||
let persisted = runtime
|
||||
.get_thread(thread_id)
|
||||
.await
|
||||
.expect("thread should load")
|
||||
.expect("thread should exist");
|
||||
assert_eq!(persisted.recency_at, touched_at);
|
||||
assert_eq!(persisted.updated_at, metadata.updated_at);
|
||||
assert_eq!(persisted.title, "updated metadata");
|
||||
|
||||
assert!(
|
||||
runtime
|
||||
.touch_thread_recency_at(thread_id, original_recency_at)
|
||||
.await
|
||||
.expect("older touch should succeed")
|
||||
);
|
||||
let persisted = runtime
|
||||
.get_thread(thread_id)
|
||||
.await
|
||||
.expect("thread should load")
|
||||
.expect("thread should exist");
|
||||
assert_eq!(
|
||||
datetime_to_epoch_millis(persisted.recency_at),
|
||||
datetime_to_epoch_millis(touched_at) + 1
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_threads_orders_and_pages_by_recency_at() {
|
||||
let codex_home = unique_temp_dir();
|
||||
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
|
||||
.await
|
||||
.expect("state db should initialize");
|
||||
let first_id =
|
||||
ThreadId::from_string("00000000-0000-0000-0000-000000000793").expect("valid thread id");
|
||||
let second_id =
|
||||
ThreadId::from_string("00000000-0000-0000-0000-000000000794").expect("valid thread id");
|
||||
let third_id =
|
||||
ThreadId::from_string("00000000-0000-0000-0000-000000000795").expect("valid thread id");
|
||||
let recency_at =
|
||||
DateTime::<Utc>::from_timestamp_millis(1_700_002_000_456).expect("timestamp");
|
||||
|
||||
for thread_id in [first_id, second_id, third_id] {
|
||||
let mut metadata = test_thread_metadata(&codex_home, thread_id, codex_home.clone());
|
||||
metadata.recency_at = recency_at;
|
||||
runtime
|
||||
.upsert_thread(&metadata)
|
||||
.await
|
||||
.expect("thread insert should succeed");
|
||||
}
|
||||
sqlx::query("UPDATE threads SET recency_at = ?, recency_at_ms = ?")
|
||||
.bind(datetime_to_epoch_seconds(recency_at))
|
||||
.bind(datetime_to_epoch_millis(recency_at))
|
||||
.execute(runtime.pool.as_ref())
|
||||
.await
|
||||
.expect("recency timestamps should match");
|
||||
|
||||
let first_page = runtime
|
||||
.list_threads(
|
||||
/*page_size*/ 1,
|
||||
ThreadFilterOptions {
|
||||
archived_only: false,
|
||||
allowed_sources: &[],
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
anchor: None,
|
||||
sort_key: SortKey::RecencyAt,
|
||||
sort_direction: SortDirection::Desc,
|
||||
search_term: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("list should succeed");
|
||||
assert_eq!(
|
||||
first_page
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| item.id)
|
||||
.collect::<Vec<_>>(),
|
||||
vec![third_id]
|
||||
);
|
||||
assert_eq!(
|
||||
first_page.next_anchor,
|
||||
Some(Anchor {
|
||||
ts: recency_at,
|
||||
id: Some(third_id),
|
||||
})
|
||||
);
|
||||
|
||||
let second_page = runtime
|
||||
.list_threads(
|
||||
/*page_size*/ 1,
|
||||
ThreadFilterOptions {
|
||||
archived_only: false,
|
||||
allowed_sources: &[],
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
anchor: first_page.next_anchor.as_ref(),
|
||||
sort_key: SortKey::RecencyAt,
|
||||
sort_direction: SortDirection::Desc,
|
||||
search_term: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("second list should succeed");
|
||||
assert_eq!(
|
||||
second_page
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| item.id)
|
||||
.collect::<Vec<_>>(),
|
||||
vec![second_id]
|
||||
);
|
||||
assert_eq!(
|
||||
second_page.next_anchor,
|
||||
Some(Anchor {
|
||||
ts: recency_at,
|
||||
id: Some(second_id),
|
||||
})
|
||||
);
|
||||
|
||||
let third_page = runtime
|
||||
.list_threads(
|
||||
/*page_size*/ 1,
|
||||
ThreadFilterOptions {
|
||||
archived_only: false,
|
||||
allowed_sources: &[],
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
anchor: second_page.next_anchor.as_ref(),
|
||||
sort_key: SortKey::RecencyAt,
|
||||
sort_direction: SortDirection::Desc,
|
||||
search_term: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("third list should succeed");
|
||||
assert_eq!(
|
||||
third_page
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| item.id)
|
||||
.collect::<Vec<_>>(),
|
||||
vec![first_id]
|
||||
);
|
||||
assert_eq!(third_page.next_anchor, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_updated_at_uses_unique_epoch_millis_and_reads_legacy_seconds() {
|
||||
let codex_home = unique_temp_dir();
|
||||
@@ -2295,8 +2558,10 @@ mod tests {
|
||||
DateTime::<Utc>::from_timestamp_millis(1_700_001_111_123).expect("timestamp millis");
|
||||
let mut first = test_thread_metadata(&codex_home, first_id, codex_home.clone());
|
||||
first.updated_at = updated_at;
|
||||
first.recency_at = updated_at;
|
||||
let mut second = test_thread_metadata(&codex_home, second_id, codex_home.clone());
|
||||
second.updated_at = updated_at;
|
||||
second.recency_at = updated_at;
|
||||
|
||||
runtime
|
||||
.upsert_thread(&first)
|
||||
@@ -2325,6 +2590,14 @@ mod tests {
|
||||
datetime_to_epoch_millis(second.updated_at),
|
||||
1_700_001_111_124
|
||||
);
|
||||
assert_eq!(
|
||||
datetime_to_epoch_millis(first.recency_at),
|
||||
1_700_001_111_123
|
||||
);
|
||||
assert_eq!(
|
||||
datetime_to_epoch_millis(second.recency_at),
|
||||
1_700_001_111_124
|
||||
);
|
||||
let second_row: (i64, i64, Option<i64>, Option<i64>) = sqlx::query_as(
|
||||
"SELECT created_at, updated_at, created_at_ms, updated_at_ms FROM threads WHERE id = ?",
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user