Support renaming cloud threads (#61182)

## What changed

Handle `ThreadSetName` requests in the cloud backend through the cloud client's new `set_thread_name` method, without opening an attachment. Trim the requested name and reject empty names or thread IDs.

After the server acknowledges the rename, update the matching loaded thread's name and emit `ThreadNameUpdated`. Leave the cached name unchanged and emit no notification if the request fails.

## Testing

Add tests for the rename request payload, server acknowledgment and error handling, and preservation of the loaded thread's name when a rename fails.

GitOrigin-RevId: eecfe17a9cfba50c9fa9091a38a36c0011ab9246
This commit is contained in:
Benjamin Carlsson
2026-11-12 21:03:47 +00:00
committed by copyberry
parent bbd0d2b2fb
commit c432cf0253
5 changed files with 149 additions and 0 deletions
+27
View File
@@ -132,6 +132,33 @@ async fn archive_addresses_the_requested_thread_and_requires_acknowledgment() {
assert!(fixture.requests.try_recv().is_err());
}
#[tokio::test]
async fn rename_sends_the_thread_and_title_and_requires_acknowledgment() {
let mut fixture = fixture_responses(vec![
response(vec![frame(&[])], tonic::Status::ok("")),
response(
vec![frame(&[])],
tonic::Status::permission_denied("synthetic denial"),
),
])
.await;
fixture.client.set_thread_name("t", "New").await.unwrap();
assert_request(&mut fixture, "SetThreadName", b"\x0a\x01t\x12\x03New").await;
let error = fixture
.client
.set_thread_name("u", "Other")
.await
.unwrap_err();
let MutationError::OutcomeUnknown(Error::Rpc(status)) = error else {
panic!("expected a remote rename failure");
};
assert_eq!(status.code, tonic::Code::PermissionDenied as i32);
assert_request(&mut fixture, "SetThreadName", b"\x0a\x01u\x12\x05Other").await;
assert!(fixture.requests.try_recv().is_err());
}
#[tokio::test]
async fn activation_preserves_native_settings_and_thread_metadata() {
// Native Thread fields encoded independently of the client's wire types.
+19
View File
@@ -298,6 +298,25 @@ impl Client {
Ok(())
}
/// Saves a conversation name without opening an attachment.
pub async fn set_thread_name(&self, thread_id: &str, name: &str) -> Result<(), MutationError> {
if thread_id.trim().is_empty() || name.trim().is_empty() {
return Err(MutationError::InvalidRequest);
}
let payload = self
.mutate(
wire::SetThreadNameRequest {
thread_id: thread_id.to_owned(),
name: name.to_owned(),
},
"/oaiproto.codex_app_server_backend.ThreadService/SetThreadName",
)
.await?;
wire::EmptyResponse::decode(payload)
.map_err(|_| MutationError::OutcomeUnknown(Error::InvalidResponse))?;
Ok(())
}
/// Archives a conversation using the current account, without opening an attachment.
pub async fn archive_thread(&self, thread_id: &str) -> Result<(), MutationError> {
if thread_id.trim().is_empty() {
+8
View File
@@ -16,6 +16,14 @@ pub(crate) struct ThreadIdRequest {
pub thread_id: String,
}
#[derive(Clone, prost::Message)]
pub(crate) struct SetThreadNameRequest {
#[prost(string, tag = "1")]
pub thread_id: String,
#[prost(string, tag = "2")]
pub name: String,
}
#[derive(Clone, prost::Message)]
pub(crate) struct UnarchiveResponse {
#[prost(bytes = "bytes", optional, tag = "1")]