mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Add persisted sections for organizing threads (#35722)
## What changed - Replace the `isPinned` thread metadata and filters with an optional persisted `section` and `sectionId`. - Add the paginated `threadSection/list` app-server method so clients can discover sections even when they contain no threads. - Seed a stable `Pinned` section, validate section assignments, and support filtering for a specific section or for unsectioned threads. ## Testing - Cover section protocol serialization, listing and pagination, metadata updates, filtering, persistence, migration compatibility, and operation without SQLite state. GitOrigin-RevId: 7972b5471d29317b9387bfd90aa9f573f691ad4c
This commit is contained in:
1 parent
9291a123fb
commit
85c6da1c79
85 files changed
+1826
-419
No files matched your search
@@ -241,7 +241,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: true,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
|
||||
@@ -144,7 +144,7 @@ pub(super) fn stored_thread_from_rollout_item(
|
||||
updated_at,
|
||||
recency_at,
|
||||
archived_at,
|
||||
is_pinned: item.is_pinned,
|
||||
section: item.section,
|
||||
cwd: item.cwd.unwrap_or_default(),
|
||||
cli_version: item.cli_version.unwrap_or_default(),
|
||||
source,
|
||||
|
||||
@@ -97,7 +97,7 @@ pub(super) async fn list_rollout_threads(
|
||||
sort_key: codex_rollout::ThreadSortKey,
|
||||
sort_direction: codex_rollout::SortDirection,
|
||||
) -> ThreadStoreResult<codex_rollout::ThreadsPage> {
|
||||
if params.relation_filter.is_some() || params.is_pinned.is_some() {
|
||||
if params.relation_filter.is_some() || params.section.is_some() {
|
||||
let relation_filter = params
|
||||
.relation_filter
|
||||
.map(|relation_filter| match relation_filter {
|
||||
@@ -120,7 +120,7 @@ pub(super) async fn list_rollout_threads(
|
||||
params.cwd_filters.as_deref(),
|
||||
relation_filter,
|
||||
params.archived,
|
||||
params.is_pinned,
|
||||
params.section.as_ref().map(Option::as_deref),
|
||||
params.search_term.as_deref(),
|
||||
)
|
||||
.await
|
||||
@@ -240,7 +240,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: false,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
@@ -301,7 +301,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: false,
|
||||
search_term: Some("needle".to_string()),
|
||||
relation_filter: None,
|
||||
@@ -374,7 +374,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: false,
|
||||
search_term: Some("canonical".to_string()),
|
||||
relation_filter: None,
|
||||
@@ -411,7 +411,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: false,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
@@ -428,7 +428,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: true,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
@@ -481,7 +481,7 @@ mod tests {
|
||||
allowed_sources: vec![SessionSource::Cli],
|
||||
model_providers: Some(vec!["test-provider".to_string()]),
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: false,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
@@ -519,7 +519,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: false,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
|
||||
@@ -62,7 +62,7 @@ pub(super) async fn read_thread(
|
||||
&& !rollout_thread.preview.is_empty()
|
||||
{
|
||||
rollout_thread.recency_at = thread.recency_at;
|
||||
rollout_thread.is_pinned = thread.is_pinned;
|
||||
rollout_thread.section = thread.section;
|
||||
if thread.name.is_some() {
|
||||
rollout_thread.name = thread.name;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ pub(super) async fn read_thread_by_rollout_path(
|
||||
thread = stored_thread_from_sqlite_metadata(store, metadata).await?;
|
||||
} else {
|
||||
thread.recency_at = metadata.recency_at;
|
||||
thread.is_pinned = metadata.is_pinned;
|
||||
thread.section = metadata.section;
|
||||
let (fallback_sha, fallback_branch, fallback_origin_url) = match thread.git_info.take()
|
||||
{
|
||||
Some(info) => (
|
||||
@@ -383,7 +383,7 @@ async fn stored_thread_from_sqlite_metadata(
|
||||
updated_at: metadata.updated_at,
|
||||
recency_at: metadata.recency_at,
|
||||
archived_at: metadata.archived_at,
|
||||
is_pinned: metadata.is_pinned,
|
||||
section: metadata.section,
|
||||
cwd: metadata.cwd,
|
||||
cli_version: metadata.cli_version,
|
||||
source: parse_session_source(&metadata.source),
|
||||
@@ -479,7 +479,7 @@ fn stored_thread_from_meta_line(
|
||||
updated_at,
|
||||
recency_at: updated_at,
|
||||
archived_at: archived.then_some(updated_at),
|
||||
is_pinned: false,
|
||||
section: None,
|
||||
cwd: meta_line.meta.cwd,
|
||||
cli_version: meta_line.meta.cli_version,
|
||||
source: meta_line.meta.source,
|
||||
|
||||
@@ -93,7 +93,7 @@ pub(super) async fn search_threads(
|
||||
allowed_sources: params.allowed_sources.clone(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: params.archived,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
|
||||
@@ -125,7 +125,7 @@ async fn split_homes_support_backfill_listing_and_paginated_history() {
|
||||
archived: false,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
use_state_db_only: true,
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -165,7 +165,10 @@ mod tests {
|
||||
builder.cli_version = Some("test_version".to_string());
|
||||
let mut metadata = builder.build(config.default_model_provider_id.as_str());
|
||||
metadata.archived_at = Some(metadata.updated_at);
|
||||
metadata.is_pinned = true;
|
||||
metadata.section = Some(codex_state::ThreadSection {
|
||||
id: codex_state::PINNED_THREAD_SECTION_ID.to_string(),
|
||||
name: codex_state::PINNED_THREAD_SECTION_NAME.to_string(),
|
||||
});
|
||||
runtime
|
||||
.upsert_thread(&metadata)
|
||||
.await
|
||||
@@ -175,7 +178,7 @@ mod tests {
|
||||
.unarchive_thread(ArchiveThreadParams { thread_id })
|
||||
.await
|
||||
.expect("unarchive thread");
|
||||
assert!(unarchived.is_pinned);
|
||||
assert_eq!(unarchived.section, metadata.section);
|
||||
|
||||
let restored_path = home
|
||||
.path()
|
||||
@@ -189,6 +192,6 @@ mod tests {
|
||||
assert_eq!(updated.rollout_path, restored_path);
|
||||
assert_eq!(updated.archived_at, None);
|
||||
assert_eq!(updated.recency_at, metadata.recency_at);
|
||||
assert!(updated.is_pinned);
|
||||
assert_eq!(updated.section, metadata.section);
|
||||
}
|
||||
}
|
||||
@@ -278,7 +278,7 @@ async fn apply_metadata_update(
|
||||
rollout_path = Some(resolved.path);
|
||||
}
|
||||
if existing.is_none()
|
||||
&& patch.is_pinned.is_some()
|
||||
&& patch.section.is_some()
|
||||
&& let Some(path) = rollout_path.as_deref()
|
||||
&& let Some(existing_rollout_path) =
|
||||
codex_rollout::existing_rollout_path(path).await
|
||||
@@ -389,8 +389,23 @@ async fn apply_metadata_update(
|
||||
if let Some(first_user_message) = patch.first_user_message {
|
||||
metadata.first_user_message = Some(first_user_message);
|
||||
}
|
||||
if let Some(is_pinned) = patch.is_pinned {
|
||||
metadata.is_pinned = is_pinned;
|
||||
if let Some(section) = patch.section.clone() {
|
||||
metadata.section = match section {
|
||||
Some(section_id) => Some(
|
||||
state_db
|
||||
.get_thread_section(§ion_id)
|
||||
.await
|
||||
.map_err(|err| ThreadStoreError::Internal {
|
||||
message: format!(
|
||||
"failed to read section {section_id} for thread {thread_id}: {err}"
|
||||
),
|
||||
})?
|
||||
.ok_or_else(|| ThreadStoreError::InvalidRequest {
|
||||
message: format!("thread section not found: {section_id}"),
|
||||
})?,
|
||||
),
|
||||
None => None,
|
||||
};
|
||||
}
|
||||
if let Some(git_info) = patch.git_info {
|
||||
let existing_git_info = git_info_from_parts(
|
||||
@@ -409,19 +424,17 @@ async fn apply_metadata_update(
|
||||
.map_err(|err| ThreadStoreError::Internal {
|
||||
message: format!("failed to update thread metadata for {thread_id}: {err}"),
|
||||
})?;
|
||||
if let Some(is_pinned) = patch.is_pinned {
|
||||
if let Some(section) = patch.section {
|
||||
let updated = state_db
|
||||
.update_thread_pin(thread_id, is_pinned)
|
||||
.update_thread_section(thread_id, section.as_deref())
|
||||
.await
|
||||
.map_err(|err| ThreadStoreError::Internal {
|
||||
message: format!(
|
||||
"failed to update pin state for thread {thread_id}: {err}"
|
||||
),
|
||||
message: format!("failed to update section for thread {thread_id}: {err}"),
|
||||
})?;
|
||||
if !updated {
|
||||
return Err(ThreadStoreError::Internal {
|
||||
message: format!(
|
||||
"thread metadata unavailable before pin update: {thread_id}"
|
||||
"thread metadata unavailable before section update: {thread_id}"
|
||||
),
|
||||
});
|
||||
}
|
||||
@@ -590,9 +603,9 @@ fn sqlite_write_failure_should_block(patch: &ThreadMetadataPatch) -> bool {
|
||||
// transcript-derived metadata, thread names, and memory-mode indexing were log-only. Keep that
|
||||
// failure isolation so a corrupted optional state DB does not make JSONL transcript durability
|
||||
// look broken. Explicit git-only updates still require SQLite because partial git patches need
|
||||
// the existing SQLite value to preserve unspecified fields. User-selected pin state is
|
||||
// the existing SQLite value to preserve unspecified fields. User-selected section state is
|
||||
// SQLite-only, so losing its write must also fail the explicit metadata update.
|
||||
patch.is_pinned.is_some() || (patch.git_info.is_some() && !has_observed_metadata_facts(patch))
|
||||
patch.section.is_some() || (patch.git_info.is_some() && !has_observed_metadata_facts(patch))
|
||||
}
|
||||
|
||||
fn sqlite_write_error_is_best_effort(err: &ThreadStoreError) -> bool {
|
||||
@@ -892,7 +905,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn pin_only_metadata_updates_persist_in_sqlite_without_changing_the_rollout() {
|
||||
async fn section_only_metadata_updates_persist_in_sqlite_without_changing_the_rollout() {
|
||||
let home = TempDir::new().expect("temp dir");
|
||||
let config = test_config(home.path());
|
||||
let uuid = Uuid::from_u128(320);
|
||||
@@ -912,7 +925,7 @@ mod tests {
|
||||
.update_thread_metadata(UpdateThreadMetadataParams {
|
||||
thread_id,
|
||||
patch: ThreadMetadataPatch {
|
||||
is_pinned: Some(true),
|
||||
section: Some(Some(codex_state::PINNED_THREAD_SECTION_ID.to_string())),
|
||||
..Default::default()
|
||||
},
|
||||
include_archived: false,
|
||||
@@ -920,13 +933,25 @@ mod tests {
|
||||
.await
|
||||
.expect("pin thread");
|
||||
|
||||
assert!(pinned.is_pinned);
|
||||
assert_eq!(
|
||||
pinned.section,
|
||||
Some(codex_state::ThreadSection {
|
||||
id: codex_state::PINNED_THREAD_SECTION_ID.to_string(),
|
||||
name: codex_state::PINNED_THREAD_SECTION_NAME.to_string(),
|
||||
})
|
||||
);
|
||||
let pinned_metadata = runtime
|
||||
.get_thread(thread_id)
|
||||
.await
|
||||
.expect("read pinned metadata")
|
||||
.expect("pinned metadata");
|
||||
assert!(pinned_metadata.is_pinned);
|
||||
assert_eq!(
|
||||
pinned_metadata.section,
|
||||
Some(codex_state::ThreadSection {
|
||||
id: codex_state::PINNED_THREAD_SECTION_ID.to_string(),
|
||||
name: codex_state::PINNED_THREAD_SECTION_NAME.to_string(),
|
||||
})
|
||||
);
|
||||
assert_eq!(pinned_metadata.preview.as_deref(), Some("Hello from user"));
|
||||
assert_eq!(pinned_metadata.source, "cli");
|
||||
let pinned_page = store
|
||||
@@ -938,7 +963,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
is_pinned: Some(true),
|
||||
section: Some(Some(codex_state::PINNED_THREAD_SECTION_ID.to_string())),
|
||||
archived: false,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
@@ -962,7 +987,13 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("read pinned thread by rollout path");
|
||||
assert!(read_by_path.is_pinned);
|
||||
assert_eq!(
|
||||
read_by_path.section,
|
||||
Some(codex_state::ThreadSection {
|
||||
id: codex_state::PINNED_THREAD_SECTION_ID.to_string(),
|
||||
name: codex_state::PINNED_THREAD_SECTION_NAME.to_string(),
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(&rollout_path).expect("read rollout"),
|
||||
original_rollout
|
||||
@@ -972,22 +1003,23 @@ mod tests {
|
||||
.update_thread_metadata(UpdateThreadMetadataParams {
|
||||
thread_id,
|
||||
patch: ThreadMetadataPatch {
|
||||
is_pinned: Some(false),
|
||||
section: Some(None),
|
||||
..Default::default()
|
||||
},
|
||||
include_archived: false,
|
||||
})
|
||||
.await
|
||||
.expect("unpin thread");
|
||||
.expect("clear thread section");
|
||||
|
||||
assert!(!unpinned.is_pinned);
|
||||
assert!(
|
||||
!runtime
|
||||
assert_eq!(unpinned.section, None);
|
||||
assert_eq!(
|
||||
runtime
|
||||
.get_thread(thread_id)
|
||||
.await
|
||||
.expect("read unpinned metadata")
|
||||
.expect("unpinned metadata")
|
||||
.is_pinned
|
||||
.expect("read cleared metadata")
|
||||
.expect("cleared metadata")
|
||||
.section,
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(&rollout_path).expect("read rollout"),
|
||||
@@ -1798,9 +1830,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sqlite_failures_block_for_explicit_pin_updates() {
|
||||
fn sqlite_failures_block_for_explicit_section_updates() {
|
||||
assert!(sqlite_write_failure_should_block(&ThreadMetadataPatch {
|
||||
is_pinned: Some(false),
|
||||
section: Some(None),
|
||||
..Default::default()
|
||||
}));
|
||||
}
|
||||
@@ -2078,7 +2110,7 @@ mod tests {
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: Some(Vec::new()),
|
||||
cwd_filters: Some(vec![workspace]),
|
||||
is_pinned: None,
|
||||
section: None,
|
||||
archived: false,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
|
||||
Reference in new issue
Block a user