From 9a8ab54db4f9f9af4dc6efb42b304c55c6a62bd3 Mon Sep 17 00:00:00 2001 From: Frederick Morlock Date: Fri, 6 Nov 2026 19:51:13 +0000 Subject: [PATCH] agent: Allow auto title generation to be disabled (#63998) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective The objective of this PR is to add a configuration option to disable automatic title generation for agent threads. This feature is desirable for users (e.g. as discussed in #63701) with token-based or compute constraints as it can prevent unnecessary (for some) overhead from title generation in addition to unnecessary large cache misses. My personal motivation is that automatic title generation pushes my entire context to my compute backend, which is a complete cache miss because (it appears) the prefix to the prompt is different. Whether it is intentional or not, automatic title generation can fire concurrent to actual generation (see Misc Notes [1]), slowing down my machine (and the output) considerably. ## Solution This PR adds a configuration option, which is exposed in the UI as well as through the standard settings.json channels, to disable automatic title generation. It's worth noting that manual title generation, as well as manual thread renaming, is still preserved. The configuration merely disables the _automatic_ title generation when the option is enabled. Ignoring the code for setting up the configuration option, this PR effectively adds a single condition to the `generate_title` call in `thread.rs` (in `run_turn_internal` that constitutes the automatic title generation. To my knowledge, this is what constitutes the "automatic title generation" and in the situation where I've seen it triggered reliably, it is no longer triggered when the disabling option is set. ## Testing - Did you test these changes? If so, how? - _Yes. I tested the functionality manually through disabling the "Auto-Generate Thread Titles" option in the Settings UI and triggering the condition where I knew automatic title generation would fire (described in Misc Notes [1]). I also tested manual title renaming and the "Regenerate thread title" function to ensure those functions were not affected. I also ran `cargo test --workspace`, which succeeded, and did UI regression tests (although it appears that my settings menu changes were not covered by them, since they did not fail when I didn't update the baseline)_ - _I also added automated tests for the feature, as well as tests to ensure that manual title generation is not affected._ - Are there any parts that need more testing? - _I was unable to fully test "Regenerate thread title" because it seems incompatible with my local LLM (it gets updated to a blank string after the compute backend returns). This is the case with the latest stable Zed (v1.19.2) and does not constitute a regression in my eyes. The automated tests I wrote should cover any regressions for users with a fully functional "Regenerate thread title" button._ - How can other people (reviewers) test your changes? Is there anything specific they need to know? - _Try to trigger automatic title generation with "Auto-Generate Thread Titles" enabled and disabled. You can verify that manual title generation ("Regenerate Thread Title") and manual title renaming also works._ - _It's worth noting that hosting my own compute backend (oMLX) was crucial in discovering and diagnosing this problem. If a tester does not have access to this, they will need to find another method of knowing if the `generate_title` method fires (such as a simple `println!`)._ - If relevant, what platforms did you test these changes on, and are there any important ones you can't test? - _**I only tested my changes on macOS 27 beta**, although the change set should be platform agnostic._ ## Self-Review Checklist: - [X] I've reviewed my own diff for quality, security, and reliability - [X] Unsafe blocks (if any) have justifying comments - [X] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [X] Tests cover the new/changed behavior - [X] Performance impact has been considered and is acceptable ## Showcase I have provided a screenshot of the location of the new toggle below
Click to view screenshot of Settings page Screenshot 2026-09-09 at 9 41 27 PM Above is a screenshot of the placement of the new Settings Menu item ("Auto-Generate Thread Titles"). It is disabled, which is not the default.
## Misc Notes [1]: My "sure fire" way of triggering the automatic title generation (at an inconvenient time) is to stop a prefill request after sending a message in an existing thread (which will trigger the automatic title generation) then resend the message. Perhaps a healthier behaviour would be to cancel in-progress title generation if another generation request come in, but I think it is advantageous to give users an option to disable automatic title generation regardless. **LLM-Use Disclosure:** I used an LLM to assist in isolating the part of the code responsible for automatic title generation triggering and generating a portion of the code I am posting here. I have thoroughly understood, checked, and tested the code which I am submitting manually, and take full professional responsibility for its quality. I have added a `Signed-off-by` section to my commit message to indicate my signing off, and a `Co-Authored-By` section to indicate LLM use. **No LLM was used in the writing of this PR text or commit message.** Thank you! Please let me know if you want me to change anything. --- Release Notes: - Feature: Added a configuration option to disable automatic title generation for agent threads --------- Signed-off-by: Frederick Morlock Co-authored-by: Hennadii Chernyshchyk Co-authored-by: Smit Barmase --- assets/settings/default.json | 6 + crates/agent/src/agent.rs | 97 ++++++++++++++- crates/agent/src/tests/mod.rs | 73 ++++++++++++ crates/agent/src/thread.rs | 4 +- crates/agent/src/tool_permissions.rs | 1 + crates/agent_settings/src/agent_settings.rs | 2 + crates/agent_ui/src/agent_panel.rs | 124 +++++++++++++++++++- crates/agent_ui/src/agent_ui.rs | 1 + crates/settings_content/src/agent.rs | 6 + crates/settings_ui/src/page_data.rs | 23 ++++ docs/src/ai/agent-panel.md | 1 + 11 files changed, 330 insertions(+), 8 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index ba46ed80a58..38b266e8f6a 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -1426,6 +1426,12 @@ // // Default: true "show_merge_conflict_indicator": true, + // Whether to automatically generate a title for Zed Agent threads using the + // summary model. When disabled, titles are only created when manually + // requested (e.g. via the thread's "Regenerate Thread Title" action). + // + // Default: true + "auto_generate_thread_titles": true, }, // Whether the screen sharing icon is shown in the os status bar. "show_call_status_icon": true, diff --git a/crates/agent/src/agent.rs b/crates/agent/src/agent.rs index 091f35d080c..f20cd33e099 100644 --- a/crates/agent/src/agent.rs +++ b/crates/agent/src/agent.rs @@ -3319,11 +3319,23 @@ impl acp_thread::AgentConnection for NativeAgentConnection { session_id: acp_v2::SessionId, project: Entity, _work_dirs: PathList, - _title: Option, + title: Option, cx: &mut App, ) -> Task>> { - self.0 - .update(cx, |agent, cx| agent.open_thread(session_id, project, cx)) + let load = self + .0 + .update(cx, |agent, cx| agent.open_thread(session_id, project, cx)); + cx.spawn(async move |cx| { + let thread = load.await?; + if let Some(title) = title { + thread.update(cx, |thread, cx| { + if thread.title().is_none() { + thread.set_provisional_title(title, cx); + } + }); + } + Ok(thread) + }) } fn auth_methods(&self) -> &[acp_v2::AuthMethod] { @@ -6260,6 +6272,85 @@ mod internal_tests { }); } + #[gpui::test] + async fn test_load_session_restores_caller_title_only_without_saved_title( + cx: &mut TestAppContext, + ) { + init_test(cx); + let (connection, agent, project, acp_thread) = setup_native_agent_session(cx).await; + let session_id = acp_thread.read_with(cx, |thread, _| thread.session_id().clone()); + let thread = cx.update(|cx| native_thread_for_session(&agent, &session_id, cx)); + let database = cx + .update(|cx| ThreadsDatabase::connect(cx)) + .await + .expect("thread database should connect"); + + let untitled_session_id = acp_v2::SessionId::new("untitled"); + let mut untitled_thread = thread.read_with(cx, |thread, cx| thread.to_db(cx)).await; + untitled_thread.title = SharedString::default(); + database + .save_thread( + untitled_session_id.clone(), + untitled_thread, + PathList::new(&[Path::new("/a")]), + ) + .await + .expect("untitled thread should save"); + + let titled_session_id = acp_v2::SessionId::new("titled"); + let mut titled_thread = thread.read_with(cx, |thread, cx| thread.to_db(cx)).await; + titled_thread.title = "Saved title".into(); + database + .save_thread( + titled_session_id.clone(), + titled_thread, + PathList::new(&[Path::new("/a")]), + ) + .await + .expect("titled thread should save"); + + let restored_untitled = cx + .update(|cx| { + connection.clone().load_session( + untitled_session_id.clone(), + project.clone(), + PathList::new(&[Path::new("/a")]), + Some("Sidebar title".into()), + cx, + ) + }) + .await + .expect("untitled thread should load"); + cx.run_until_parked(); + restored_untitled.read_with(cx, |thread, _| { + assert_eq!(thread.title(), Some("Sidebar title".into())); + assert!(thread.has_provisional_title()); + }); + // The restored title is display-only, so it must not be written back + // as the native thread's own title. + let native_untitled = + cx.update(|cx| native_thread_for_session(&agent, &untitled_session_id, cx)); + native_untitled.read_with(cx, |thread, _| assert_eq!(thread.title(), None)); + + let restored_titled = cx + .update(|cx| { + connection.load_session( + titled_session_id, + project, + PathList::new(&[Path::new("/a")]), + Some("Stale title".into()), + cx, + ) + }) + .await + .expect("titled thread should load"); + cx.run_until_parked(); + restored_titled.read_with(cx, |thread, _| { + assert_eq!(thread.title(), Some("Saved title".into())); + assert!(!thread.has_provisional_title()); + }); + } + #[gpui::test] async fn test_load_session_replays_provider_native_compaction(cx: &mut TestAppContext) { init_test(cx); diff --git a/crates/agent/src/tests/mod.rs b/crates/agent/src/tests/mod.rs index edabd6065b5..2e5486f55b3 100644 --- a/crates/agent/src/tests/mod.rs +++ b/crates/agent/src/tests/mod.rs @@ -4198,6 +4198,79 @@ async fn test_title_generation(cx: &mut TestAppContext) { }); } +#[gpui::test] +async fn test_title_generation_disabled_by_settings(cx: &mut TestAppContext) { + let ThreadTest { + model, + fake, + thread, + .. + } = setup(cx, TestModel::Fake).await; + + let set_auto_generate_thread_titles = |enabled, cx: &mut TestAppContext| { + cx.update(|cx| { + let mut settings = agent_settings::AgentSettings::get_global(cx).clone(); + settings.auto_generate_thread_titles = enabled; + agent_settings::AgentSettings::override_global(settings, cx); + }) + }; + set_auto_generate_thread_titles(false, cx); + + let summary_model = fake.model("summary"); + thread.update(cx, |thread, cx| { + thread.set_summarization_model(Some(summary_model.clone()), cx) + }); + + let send = thread + .update(cx, |thread, cx| { + thread.send(ClientUserMessageId::new(), ["Hello"], cx) + }) + .unwrap(); + cx.run_until_parked(); + + fake.send_last_text(&model, "Hey!"); + fake.end_last(&model); + cx.run_until_parked(); + + thread.read_with(cx, |thread, _| assert_eq!(thread.title(), None)); + assert_eq!(fake.pending_completions_for(&summary_model), Vec::new()); + send.collect::>().await; + cx.run_until_parked(); + thread.read_with(cx, |thread, _| assert_eq!(thread.title(), None)); + + set_auto_generate_thread_titles(true, cx); + let send = thread + .update(cx, |thread, cx| { + thread.send(ClientUserMessageId::new(), ["Hello again"], cx) + }) + .unwrap(); + cx.run_until_parked(); + fake.send_last_text(&model, "Hey again!"); + fake.end_last(&model); + cx.run_until_parked(); + let summary_request = fake.pending_completions_for(&summary_model).pop().unwrap(); + fake.send_text(&summary_model, &summary_request, "Auto title\n"); + fake.end_stream(&summary_model, &summary_request); + send.collect::>().await; + cx.run_until_parked(); + thread.read_with(cx, |thread, _| { + assert_eq!(thread.title(), Some("Auto title".into())) + }); + + set_auto_generate_thread_titles(false, cx); + thread.update(cx, |thread, cx| { + assert!(thread.regenerate_title(cx)); + }); + cx.run_until_parked(); + let summary_request = fake.pending_completions_for(&summary_model).pop().unwrap(); + fake.send_text(&summary_model, &summary_request, "Manual title\n"); + fake.end_stream(&summary_model, &summary_request); + cx.run_until_parked(); + thread.read_with(cx, |thread, _| { + assert_eq!(thread.title(), Some("Manual title".into())) + }); +} + #[gpui::test] async fn test_stream_thread_title_keeps_only_first_line(cx: &mut TestAppContext) { let request = LanguageModelRequest::default(); diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index 6be30909a5f..a6513bfce7a 100644 --- a/crates/agent/src/thread.rs +++ b/crates/agent/src/thread.rs @@ -3290,7 +3290,9 @@ impl Thread { this.update(cx, |this, cx| { if &this.prompt_id == prompt_id { this.flush_pending_message(cx); - if this.title.is_none() { + if this.title.is_none() + && AgentSettings::get_global(cx).auto_generate_thread_titles + { this.generate_title(cx); } } diff --git a/crates/agent/src/tool_permissions.rs b/crates/agent/src/tool_permissions.rs index fa38a0b0bb0..4ba7304afbb 100644 --- a/crates/agent/src/tool_permissions.rs +++ b/crates/agent/src/tool_permissions.rs @@ -608,6 +608,7 @@ mod tests { sandbox_permissions: Default::default(), show_turn_stats: false, show_merge_conflict_indicator: true, + auto_generate_thread_titles: true, max_idle_retained_threads: 5, threads_sidebar: agent_settings::ThreadsSidebarSettings { auto_open: true, diff --git a/crates/agent_settings/src/agent_settings.rs b/crates/agent_settings/src/agent_settings.rs index 331480c2e6f..f5ae752b271 100644 --- a/crates/agent_settings/src/agent_settings.rs +++ b/crates/agent_settings/src/agent_settings.rs @@ -248,6 +248,7 @@ pub struct AgentSettings { pub message_editor_min_lines: usize, pub show_turn_stats: bool, pub show_merge_conflict_indicator: bool, + pub auto_generate_thread_titles: bool, pub tool_permissions: ToolPermissions, pub sandbox_permissions: SandboxPermissions, } @@ -844,6 +845,7 @@ impl Settings for AgentSettings { message_editor_min_lines: agent.message_editor_min_lines.unwrap(), show_turn_stats: agent.show_turn_stats.unwrap(), show_merge_conflict_indicator: agent.show_merge_conflict_indicator.unwrap(), + auto_generate_thread_titles: agent.auto_generate_thread_titles.unwrap(), tool_permissions: compile_tool_permissions(agent.tool_permissions), sandbox_permissions: compile_sandbox_permissions(agent.sandbox_permissions), } diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index aa6004eb6d7..78a91d1c991 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -3527,10 +3527,15 @@ impl AgentPanel { .read(cx) .entries() .find(|t| t.id == session_id)?; + // The native thread store has no title for threads whose title was + // never generated, e.g. with `auto_generate_thread_titles` off. + let title = ThreadMetadataStore::try_global(cx) + .and_then(|store| store.read(cx).entry_by_session(&session_id)?.title()) + .unwrap_or(thread.title); Some(AgentInitialContent::ThreadSummary { session_id: thread.id, - title: Some(thread.title), + title: Some(title), }) } @@ -4550,9 +4555,18 @@ impl AgentPanel { // also seed the message editor with any prompt text the user had // typed before closing the window (persisted in the scoped kvp // draft-prompt store). - let is_draft = ThreadMetadataStore::try_global(cx) - .and_then(|store| store.read(cx).entry(thread_id).map(|m| m.is_draft())) - .unwrap_or(false); + let (is_draft, saved_title) = ThreadMetadataStore::try_global(cx) + .and_then(|store| { + store + .read(cx) + .entry(thread_id) + .map(|metadata| (metadata.is_draft(), metadata.title.clone())) + }) + .unwrap_or((false, None)); + // Callers such as thread mentions pass a title captured when they were + // created, which can be stale or the default title. Restoring that on + // load would overwrite the title this thread last showed. + let title = saved_title.or(title); let initial_content = is_draft .then(|| crate::draft_prompt_store::read(thread_id, cx)) .flatten() @@ -11704,6 +11718,78 @@ mod tests { }); } + #[gpui::test] + async fn test_load_agent_thread_prefers_sidebar_title_over_caller_title( + cx: &mut TestAppContext, + ) { + let (panel, mut cx) = setup_panel(cx).await; + cx.run_until_parked(); + + panel.update(&mut cx, |panel, cx| { + panel.connection_store.update(cx, |store, cx| { + store.restart_connection( + Agent::Stub, + Rc::new(StubAgentServer::new( + StubAgentConnection::new().with_supports_load_session(true), + )), + cx, + ); + }); + }); + cx.run_until_parked(); + + let thread_id = ThreadId::new(); + cx.update(|_window, cx| { + ThreadMetadataStore::global(cx).update(cx, |store, cx| { + store.save( + crate::thread_metadata_store::ThreadMetadata { + thread_id, + session_id: Some(acp_v2::SessionId::new("saved-session")), + agent_id: Agent::Stub.id(), + title: Some("Sidebar title".into()), + title_override: None, + updated_at: Utc::now(), + created_at: Some(Utc::now()), + interacted_at: None, + worktree_paths: WorktreePaths::from_folder_paths(&PathList::default()), + remote_connection: None, + archived: false, + }, + cx, + ); + }); + }); + + panel.update_in(&mut cx, |panel, window, cx| { + panel.load_agent_thread( + Agent::Stub, + thread_id, + None, + Some(crate::DEFAULT_THREAD_TITLE.into()), + true, + AgentThreadSource::AgentPanel, + window, + cx, + ); + }); + cx.run_until_parked(); + + panel.read_with(&cx, |panel, cx| { + let thread = panel + .active_agent_thread(cx) + .expect("saved thread should load"); + assert_eq!(thread.read(cx).title(), Some("Sidebar title".into())); + }); + cx.update(|_window, cx| { + let metadata = ThreadMetadataStore::global(cx) + .read(cx) + .entry(thread_id) + .cloned() + .expect("sidebar entry should still exist"); + assert_eq!(metadata.title, Some("Sidebar title".into())); + }); + } + #[gpui::test] async fn test_initial_content_for_thread_summary_uses_own_session_id(cx: &mut TestAppContext) { init_test(cx); @@ -11775,6 +11861,36 @@ mod tests { _ => panic!("expected AgentInitialContent::ThreadSummary"), } + cx.update(|cx| { + ThreadMetadataStore::global(cx).update(cx, |store, cx| { + store.save( + crate::thread_metadata_store::ThreadMetadata { + thread_id: ThreadId::new(), + session_id: Some(source_session_id.clone()), + agent_id: Agent::NativeAgent.id(), + title: Some("Sidebar title".into()), + title_override: None, + updated_at: Utc::now(), + created_at: Some(Utc::now()), + interacted_at: None, + worktree_paths: WorktreePaths::from_folder_paths(&PathList::default()), + remote_connection: None, + archived: false, + }, + cx, + ); + }); + }); + let content = cx + .update(|cx| { + AgentPanel::initial_content_for_thread_summary(source_session_id.clone(), cx) + }) + .expect("initial content should be produced for a root thread"); + let AgentInitialContent::ThreadSummary { title, .. } = content else { + panic!("expected AgentInitialContent::ThreadSummary"); + }; + assert_eq!(title, Some("Sidebar title".into())); + // Unknown session ids should still produce no content. let missing = cx.update(|cx| { AgentPanel::initial_content_for_thread_summary( diff --git a/crates/agent_ui/src/agent_ui.rs b/crates/agent_ui/src/agent_ui.rs index a0ae6cc5f67..74a4075e4b3 100644 --- a/crates/agent_ui/src/agent_ui.rs +++ b/crates/agent_ui/src/agent_ui.rs @@ -1106,6 +1106,7 @@ mod tests { sandbox_permissions: Default::default(), show_turn_stats: false, show_merge_conflict_indicator: true, + auto_generate_thread_titles: true, max_idle_retained_threads: 5, threads_sidebar: agent_settings::ThreadsSidebarSettings { auto_open: true, diff --git a/crates/settings_content/src/agent.rs b/crates/settings_content/src/agent.rs index 4078f7aebb4..f9c48da8d12 100644 --- a/crates/settings_content/src/agent.rs +++ b/crates/settings_content/src/agent.rs @@ -394,6 +394,12 @@ pub struct AgentSettingsContent { /// /// Default: true pub show_merge_conflict_indicator: Option, + /// Whether to automatically generate a title for Zed Agent threads using the + /// summary model. When disabled, titles are only created when manually + /// requested (e.g. via the thread's "Regenerate Thread Title" action). + /// + /// Default: true + pub auto_generate_thread_titles: Option, /// Per-tool permission rules for granular control over which tool actions /// require confirmation. /// diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs index 790de77746d..d0801b2052c 100644 --- a/crates/settings_ui/src/page_data.rs +++ b/crates/settings_ui/src/page_data.rs @@ -9584,6 +9584,29 @@ fn ai_page(cx: &App) -> SettingsPage { metadata: None, files: USER, }), + SettingsPageItem::SettingItem(SettingItem { + title: "Auto-Generate Thread Titles", + description: "Whether to automatically generate a title for Zed Agent threads using the summary model. When disabled, titles are only created when manually requested.", + field: Box::new(SettingField { + organization_override: None, + json_path: Some("agent.auto_generate_thread_titles"), + pick: |settings_content| { + settings_content + .agent + .as_ref()? + .auto_generate_thread_titles + .as_ref() + }, + write: |settings_content, value, _| { + settings_content + .agent + .get_or_insert_default() + .auto_generate_thread_titles = value; + }, + }), + metadata: None, + files: USER, + }), ]); items.extend([ diff --git a/docs/src/ai/agent-panel.md b/docs/src/ai/agent-panel.md index c002f506d9b..005f8b769a0 100644 --- a/docs/src/ai/agent-panel.md +++ b/docs/src/ai/agent-panel.md @@ -89,6 +89,7 @@ When focus is in the message editor, you can also use {#kb agent::ScrollOutputPa Thread titles are auto-generated based on the content of the conversation. But you can also edit them manually by clicking the title and typing, or regenerate them by clicking the "Regenerate Thread Title" button in the ellipsis menu in the top right of the panel. +To stop Zed Agent thread titles from being generated automatically, set `agent.auto_generate_thread_titles` to `false`. Threads then use the first line of your first message as their title. ### Following the Agent {#following-the-agent}