diff --git a/CHANGELOG.md b/CHANGELOG.md index 55f7caea5..02e73a87d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ macOS, Linux, and Android downloads are Preview builds. #### Fixed +- Fixed session restore and saving being disabled whenever Pebrel ran elevated: the administrator marker had also been applied to the workspace snapshot, so every elevated launch started from a single home-directory tab and nothing was written on exit. - Fixed a delegated prompt remaining in the terminal editor when the agent changed keyboard mode before Enter was sent. - Fixed delegated Claude Code tasks reporting that no final message was available even when Claude supplied an answer. - Fixed a reply from a worker’s previous turn being returned for a newly delegated task. @@ -37,6 +38,7 @@ macOS、Linux 和 Android 下载为预览版。 #### 修复 +- 修复以管理员身份运行 Pebrel 时不再恢复也不再保存会话的问题:管理员标记被一并套用到工作区快照,导致每次提权启动都只剩一个默认标签,退出时也不落盘。 - 修复 Agent 在接收委派内容后切换键盘模式,导致回车未提交、指令留在输入框的问题。 - 修复 Claude Code 已经给出最终答复,发起委派的窗格却显示没有最终消息的问题。 - 修复新任务刚被委派时,调用方可能收到上一轮答复的问题。 diff --git a/nebula_app/src/gpui_shell/workspace/session_persistence.rs b/nebula_app/src/gpui_shell/workspace/session_persistence.rs index 917cb18fb..9c558493f 100644 --- a/nebula_app/src/gpui_shell/workspace/session_persistence.rs +++ b/nebula_app/src/gpui_shell/workspace/session_persistence.rs @@ -13,30 +13,22 @@ pub(super) struct SessionPersistence { latest: Option, saved: Option, quitting: bool, - isolated: bool, } impl Default for SessionPersistence { fn default() -> Self { - Self { - latest: None, - saved: None, - quitting: false, - isolated: crate::platform::elevation::requires_isolation(), - } + Self { latest: None, saved: None, quitting: false } } } impl SessionPersistence { - #[cfg(test)] - pub(super) fn ordinary_for_test() -> Self { - Self { isolated: false, ..Self::default() } - } - pub(super) fn update_windows(&self) -> std::io::Result> { - // 管理员只在显式更新事务中落盘;commit 会在授权安装前持久保存这份内存快照。 - (if self.isolated { &self.latest } else { &self.saved }) + // The workspace snapshot is user-visible state, not a control-plane resource: + // prefer the persisted snapshot and fall back to the in-memory one so the + // update handoff sees a complete workspace even before the first write. + self.saved .clone() + .or_else(|| self.latest.clone()) .ok_or_else(|| std::io::Error::other("No durable workspace snapshot"))? .into_update_windows() } @@ -98,15 +90,13 @@ impl SessionPersistence { } // A failed final write is cancellable: windows stay live and subsequent // checkpoints must still be able to save newly confirmed identities. - if self.isolated { - // 未预约更新时只记忆当前会话,绝不写入普通会话文件或开启常规管理员恢复。 - if !crate::update_download::handoff::checkpoint_scheduled(&session)? { - self.quitting |= reason == SaveReason::Quit && !system_ending; - return Ok(()); - } - } else { - write(&session)?; + // An elevated instance with an armed update still hands the workspace to the + // update transaction's own snapshot file, but that snapshot must not replace + // the workspace snapshot: every instance takes the same write path below. + if crate::platform::elevation::is_elevated().unwrap_or(false) { + crate::update_download::handoff::checkpoint_scheduled(&session)?; } + write(&session)?; self.saved = Some(session); self.quitting |= reason == SaveReason::Quit && !system_ending; Ok(()) @@ -122,27 +112,23 @@ mod tests { use super::*; #[test] - fn isolated_windows_never_write_shared_session_storage() { - let mut state = SessionPersistence { isolated: true, ..SessionPersistence::default() }; - for reason in [ - SaveReason::Checkpoint, - SaveReason::TabsClosed, - SaveReason::WindowClose, - SaveReason::Quit, - ] { - let _ = state.save_with(Some(sample_session()), reason, |_| { - panic!("privileged session reached shared storage") - }); - } - assert!(state.saved.is_none(), "ordinary privileged launches do not persist a workspace"); - assert_eq!(state.update_windows().unwrap()[0].tabs, sample_session().tabs); + fn elevated_launches_use_the_same_session_storage() { + // Elevation is not an input to the workspace snapshot: the constructor the + // app actually uses must persist. + let directory = tempfile::tempdir().unwrap(); + let path = directory.path().join("session.json"); + let expected = sample_session(); + let mut state = SessionPersistence::default(); + save_to(&mut state, &path, Some(expected.clone()), SaveReason::Checkpoint); + let restored = crate::session::load_from(&path).unwrap(); + assert_eq!(restored.tabs, expected.tabs); } use crate::session::{AgentSession, LayoutSession, TabSession}; fn ordinary_window() -> SessionPersistence { - // Hosted Windows runners can be elevated. These tests exercise ordinary - // window persistence; privileged isolation has its own negative test. - SessionPersistence::ordinary_for_test() + // Elevation does not change how the snapshot is read or written; these + // tests use the same constructor as application startup. + SessionPersistence::default() } fn sample_session() -> Session { diff --git a/nebula_app/src/gpui_shell/workspace/session_persistence/shutdown_tests.rs b/nebula_app/src/gpui_shell/workspace/session_persistence/shutdown_tests.rs index 2930ae30c..6765ce7b5 100644 --- a/nebula_app/src/gpui_shell/workspace/session_persistence/shutdown_tests.rs +++ b/nebula_app/src/gpui_shell/workspace/session_persistence/shutdown_tests.rs @@ -34,7 +34,7 @@ fn workspace() -> Session { fn checkpoint() -> (SessionPersistence, Session, Reset) { set_pending(false); let expected = workspace(); - let mut state = SessionPersistence::ordinary_for_test(); + let mut state = SessionPersistence::default(); state.save_with(Some(expected.clone()), SaveReason::Checkpoint, |_| Ok(())).unwrap(); (state, expected, Reset) } @@ -134,7 +134,7 @@ fn repeated_system_notifications_do_not_recapture_partial_state_or_rewrite() { #[test] fn system_shutdown_without_a_checkpoint_keeps_the_first_nonempty_snapshot() { let _reset = Reset; - let mut state = SessionPersistence::ordinary_for_test(); + let mut state = SessionPersistence::default(); set_pending(true); state.save_with(None, SaveReason::Quit, |_| panic!("no snapshot exists")).unwrap(); let expected = workspace(); @@ -169,7 +169,7 @@ fn pi_explicitly_exited_before_the_system_notification_is_not_revived() { #[test] fn an_empty_startup_during_system_shutdown_never_erases_storage() { let _reset = Reset; - let mut state = SessionPersistence::ordinary_for_test(); + let mut state = SessionPersistence::default(); set_pending(true); state .save_with(Some(Session::new(0, vec![])), SaveReason::WindowClose, |_| { @@ -180,20 +180,45 @@ fn an_empty_startup_during_system_shutdown_never_erases_storage() { } #[test] -fn system_shutdown_does_not_bypass_administrator_isolation() { +fn an_elevated_session_writes_the_snapshot_on_every_reason() { let _reset = Reset; - let mut state = SessionPersistence::ordinary_for_test(); - state.isolated = true; + set_pending(false); let expected = workspace(); - state - .save_with(Some(expected.clone()), SaveReason::Checkpoint, |_| panic!("shared storage")) - .unwrap(); - set_pending(true); - state - .save_with(Some(Session::new(0, vec![])), SaveReason::WindowClose, |_| { - panic!("shared storage") + // Same constructor as application startup: elevation is not an input to the + // workspace snapshot, so an elevated process persists like any other. + for reason in [ + SaveReason::Checkpoint, + SaveReason::TabsClosed, + SaveReason::WindowClose, + SaveReason::Quit, + ] { + let mut state = SessionPersistence::default(); + let mut wrote = 0; + state + .save_with(Some(expected.clone()), reason, |session| { + assert_eq!(session.tabs.len(), expected.tabs.len()); + wrote += 1; + Ok(()) + }) + .unwrap(); + assert_eq!(wrote, 1, "save reason {reason:?} must reach shared storage"); + } +} + +#[test] +fn scheduled_update_reads_the_workspace_before_the_first_write() { + let _reset = Reset; + set_pending(false); + // The handoff still needs a complete workspace even when nothing has been + // written yet, which is the case right after a failed checkpoint. + let mut state = SessionPersistence::default(); + let expected = workspace(); + let _ = state + .save_with(Some(expected.clone()), SaveReason::Checkpoint, |_| { + Err(std::io::Error::other("storage is unavailable right now")) }) - .unwrap(); - assert!(state.saved.is_none()); - assert_eq!(state.latest.as_ref().unwrap().tabs, expected.tabs); + .ok(); + let windows = state.update_windows().expect("the checkpoint still holds the workspace"); + assert_eq!(windows.len(), 1); + assert_eq!(windows[0].tabs.len(), expected.tabs.len()); } diff --git a/nebula_app/src/gpui_shell/workspace/windowing/shutdown.rs b/nebula_app/src/gpui_shell/workspace/windowing/shutdown.rs index cf5a6b90f..fd10566fe 100644 --- a/nebula_app/src/gpui_shell/workspace/windowing/shutdown.rs +++ b/nebula_app/src/gpui_shell/workspace/windowing/shutdown.rs @@ -113,7 +113,7 @@ fn request_quit(update: Option, cx: &mut App) return; } if let Some(prepared) = prepared.as_mut() { - // 提交持久保存包括活跃窗口顺序的快照;管理员不经过普通共享会话文件。 + // 提交持久保存包括活跃窗口顺序的快照;会话快照对提权实例同样有效。 let result = cx .global::() .session_persistence diff --git a/nebula_app/src/gpui_shell/workspace/windowing/startup_geometry.rs b/nebula_app/src/gpui_shell/workspace/windowing/startup_geometry.rs index ccde4bdc8..8ab7d1cce 100644 --- a/nebula_app/src/gpui_shell/workspace/windowing/startup_geometry.rs +++ b/nebula_app/src/gpui_shell/workspace/windowing/startup_geometry.rs @@ -101,9 +101,8 @@ pub(super) fn load_restore( let restore_directory_size = crate::platform::CAPABILITIES.restore_directory_window_size && !has_regular_window; load_restore_from(id, startup, restore_directory_size, cx, || { - if crate::platform::elevation::requires_isolation() { - return None; - } + // Elevation is not an input to restore: an administrator instance reads the + // same workspace snapshot as an ordinary one. crate::session::load().and_then(|session| session.startup_window_state()) }); } diff --git a/nebula_app/src/update_download/handoff.rs b/nebula_app/src/update_download/handoff.rs index 663336269..b11060309 100644 --- a/nebula_app/src/update_download/handoff.rs +++ b/nebula_app/src/update_download/handoff.rs @@ -383,7 +383,7 @@ fn validate_windows(windows: &[Session]) -> Result<(), String> { Ok(()) } -/// Only an explicitly armed administrator update persists privileged session state. +/// Only an explicitly armed administrator update writes the update-transaction snapshot. pub(crate) fn checkpoint_scheduled(session: &Session) -> io::Result { if !SCHEDULED_IN_THIS_PROCESS.load(Ordering::Acquire) { return Ok(false);