From f1c2fc8804526d0ecb3ed0b2f34610f03060b570 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Sat, 31 Oct 2026 04:01:52 +0000 Subject: [PATCH] Assistant: a new tab keeps the agent's sign-in (#9293) (#9669) * claim: #9293 * Assistant: a sign-in confirmed in one tab holds in every tab (#9293) The latest sign-in evidence per agent is window state: keep it across tab switches, new tabs and replaced designs instead of resetting it with the tab's conversation, so a new tab no longer marks the agent as signed out when discovery's login probe is older than the chat's proof. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/agent_chat/mod.rs | 3 +++ crates/ui-egui/src/agent_chat/tests.rs | 32 ++++++++++++++++++++++++++ docs/agent-chat.md | 3 ++- docs/design/in-app-agent-chat.md | 4 ++-- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/agent_chat/mod.rs b/crates/ui-egui/src/agent_chat/mod.rs index 327580369..0cfa52e5f 100644 --- a/crates/ui-egui/src/agent_chat/mod.rs +++ b/crates/ui-egui/src/agent_chat/mod.rs @@ -419,6 +419,7 @@ pub struct AgentChat { /// Settings → AI: the Add agent dialog and connection tests. pub settings: settings::State, /// Latest authentication evidence from a connection test or a chat, per agent; never saved. + /// It belongs to the window, not to one tab's conversation. login_results: std::collections::HashMap, /// Desktop host hook: start the endpoint on demand. pub control_starter: Option, @@ -448,6 +449,8 @@ impl AgentChat { std::mem::swap(&mut self.models_cache, &mut other.models_cache); std::mem::swap(&mut self.window_placed, &mut other.window_placed); std::mem::swap(&mut self.connect_at_start, &mut other.connect_at_start); + // A sign-in proven in one tab holds for that agent in every tab (#9293). + std::mem::swap(&mut self.login_results, &mut other.login_results); #[cfg(not(target_arch = "wasm32"))] { std::mem::swap(&mut self.detection, &mut other.detection); diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rs index c99c9c7ac..82c670999 100644 --- a/crates/ui-egui/src/agent_chat/tests.rs +++ b/crates/ui-egui/src/agent_chat/tests.rs @@ -100,6 +100,38 @@ fn agent_login_refresh_returns_to_unverified_discovery() { assert!(!app.agent_chat.settings.tests.contains_key("qwen")); } +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn a_sign_in_proven_in_one_tab_holds_in_every_tab() { + // #9293: discovery found no login file before the user signed in from the panel. The chat's + // proof of the sign-in belongs to the window, so a new tab doesn't ask for it again. + let mut app = app_with_discovered_login(); + if let Some(d) = app.agent_chat.detection.as_mut() { + d.found[0].login = discover::Login::NotLoggedIn; + } + assert_eq!(assistant_mark(&app), AssistantMark::NeedsAuth); + app.agent_chat.on_event(Event::Ready { agent: "Qwen Code".into(), images: false }); + assert_eq!(agents::current(&app).unwrap().login, "signed_in"); + + crate::documents::open_tab(&mut app, solidcraft_engine::Session::default()).unwrap(); + assert_eq!(app.agent_chat.state(), State::Off, "a new tab starts its own conversation"); + assert_eq!(agents::current(&app).unwrap().login, "signed_in"); + assert_eq!(assistant_mark(&app), AssistantMark::Ready, "no sign-in mark in the new tab"); + + // Evidence from the new tab is the newest, also back in the first one. + app.agent_chat.running_id = "qwen".into(); + app.agent_chat.on_event(Event::AuthRequired { methods: vec![] }); + crate::documents::switch(&mut app, 0); + assert_eq!(agents::current(&app).unwrap().login, "signed_out"); + app.agent_chat.on_event(Event::Ready { agent: "Qwen Code".into(), images: false }); + + // A replacement design starts a fresh conversation, not a fresh sign-in. + crate::documents::reset_chat(&mut app); + assert_eq!(agents::current(&app).unwrap().login, "signed_in"); + crate::documents::close(&mut app, 0, true); + assert_eq!(agents::current(&app).unwrap().login, "signed_in", "closing a tab keeps the window's evidence"); +} + #[test] fn streamed_text_joins_and_tool_updates_change_their_call() { let mut c = chat(); diff --git a/docs/agent-chat.md b/docs/agent-chat.md index 895b0a87c..e2e85672b 100644 --- a/docs/agent-chat.md +++ b/docs/agent-chat.md @@ -133,7 +133,8 @@ clears the files waiting on the chips too. ## Typing while the agent works Each design tab has its own conversation, agent session, draft, attachments and queued messages. -A new tab starts with an empty chat. Switching away stops the current turn and keeps its +A new tab starts with an empty chat and a session of its own; a sign-in the chat confirmed in one +tab still counts in the others, so a new tab doesn't mark the agent as signed out. Switching away stops the current turn and keeps its completed changes in that design's undo history. Returning restores the conversation; queued messages wait for **Send**. Closing a design closes its conversation. Conversations are kept only while the tabs remain open. diff --git a/docs/design/in-app-agent-chat.md b/docs/design/in-app-agent-chat.md index 203c07e11..938b5aabd 100644 --- a/docs/design/in-app-agent-chat.md +++ b/docs/design/in-app-agent-chat.md @@ -184,8 +184,8 @@ conversation shows the merged step with an Undo button while it's still the late Each open design tab owns an `AgentChat`, including its transcript, backend session, agent selection, sign-in retry, draft, attachments, pending messages and approval state. `DocSlot` parks that state alongside its `Session`; switching restores both together. Panel visibility, -placement, agent discovery, endpoint model cache, settings dialogs and the desktop endpoint -starter remain window state. A new tab gets a fresh conversation. Closing a tab drops its +placement, agent discovery, the latest sign-in evidence per agent, endpoint model cache, +settings dialogs and the desktop endpoint starter remain window state. A new tab gets a fresh conversation. Closing a tab drops its backend; closing the last tab or replacing its design (including programmatic New, Open and Recover commands or scripts) clears its conversation. Conversation state is in memory only and does not change the design file format.