Add persisted manual ordering for thread sections (#36007)

## What changed

- Add `thread/section/move` to atomically move a thread into, within, or out of a section. Threads can be inserted before an existing member or appended, and moves within a section preserve `sectionEnteredAt`.
- Add `section_position` sorting to `thread/list`, with ascending order as its default, and expose `sectionEnteredAt` in thread responses.
- Persist section positions and entry times in SQLite, including migration of existing section members into recency order. Section membership is no longer updated through `thread/metadata/update`.

## Testing

- Cover section moves, reordering, pagination, persistence across restarts and rollout reconciliation, concurrent updates, and rank renumbering.

GitOrigin-RevId: aec6d7ddedca5277029b5caf5c074975397e956c
This commit is contained in:
joeytrasatti-openai authored and copyberry committed 2026-07-29 18:37:22 +00:00
1 parent c41a38dd10
commit ad6fc66b6d
75 files changed
+2879 -543

No files matched your search

@@ -546,6 +546,11 @@ client_request_definitions! {
serialization: thread_id(params.thread_id),
response: v2::ThreadMetadataUpdateResponse,
},
ThreadSectionMove => "thread/section/move" {
params: v2::ThreadSectionMoveParams,
serialization: thread_id(params.thread_id),
response: v2::ThreadSectionMoveResponse,
},
#[experimental("thread/settings/update")]
ThreadSettingsUpdate => "thread/settings/update" {
params: v2::ThreadSettingsUpdateParams,
@@ -1873,6 +1878,92 @@ mod tests {
}
}
#[test]
fn thread_section_move_round_trips_and_serializes_by_thread() -> Result<()> {
assert_eq!(
serde_json::to_value(v2::ThreadSortKey::SectionPosition)?,
json!("section_position")
);
let request = ClientRequest::ThreadSectionMove {
request_id: request_id(),
params: v2::ThreadSectionMoveParams {
thread_id: "thread-1".to_string(),
section_id: Some("01984de2-8f74-7c91-a3b2-5c5e937cf318".to_string()),
before_thread_id: Some("thread-2".to_string()),
},
};
assert_eq!(
serde_json::to_value(&request)?,
json!({
"method": "thread/section/move",
"id": 1,
"params": {
"threadId": "thread-1",
"sectionId": "01984de2-8f74-7c91-a3b2-5c5e937cf318",
"beforeThreadId": "thread-2"
}
})
);
assert_eq!(
request.serialization_scope(),
Some(ClientRequestSerializationScope::Thread {
thread_id: "thread-1".to_string()
})
);
let append_request = ClientRequest::try_from(JSONRPCRequest {
id: request_id(),
method: "thread/section/move".to_string(),
params: Some(json!({
"threadId": "thread-1",
"sectionId": "01984de2-8f74-7c91-a3b2-5c5e937cf318"
})),
trace: None,
})?;
assert_eq!(
append_request,
ClientRequest::ThreadSectionMove {
request_id: request_id(),
params: v2::ThreadSectionMoveParams {
thread_id: "thread-1".to_string(),
section_id: Some("01984de2-8f74-7c91-a3b2-5c5e937cf318".to_string()),
before_thread_id: None,
},
}
);
let clear_request = ClientRequest::try_from(JSONRPCRequest {
id: request_id(),
method: "thread/section/move".to_string(),
params: Some(json!({
"threadId": "thread-1",
"sectionId": null
})),
trace: None,
})?;
assert_eq!(
clear_request,
ClientRequest::ThreadSectionMove {
request_id: request_id(),
params: v2::ThreadSectionMoveParams {
thread_id: "thread-1".to_string(),
section_id: None,
before_thread_id: None,
},
}
);
assert!(
ClientRequest::try_from(JSONRPCRequest {
id: request_id(),
method: "thread/section/move".to_string(),
params: Some(json!({ "threadId": "thread-1" })),
trace: None,
})
.is_err()
);
Ok(())
}
#[test]
fn client_request_serialization_scope_covers_keyed_families() {
let thread_id = "thread-1".to_string();
@@ -2717,6 +2808,7 @@ mod tests {
preview: "first prompt".to_string(),
ephemeral: true,
section: None,
section_entered_at: None,
history_mode: Default::default(),
model_provider: "openai".to_string(),
created_at: 1,
@@ -2770,6 +2862,7 @@ mod tests {
"preview": "first prompt",
"ephemeral": true,
"section": null,
"sectionEnteredAt": null,
"historyMode": "legacy",
"modelProvider": "openai",
"createdAt": 1,