Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(desktop): keep the Runtime on the Screen Recording Quit & Reopen (#2940)
Max1426755096aa
diff --git a/desktop/src-tauri/src/computer_use.rs b/desktop/src-tauri/src/computer_use.rsindex aafce895e..5181026ee 100644--- a/desktop/src-tauri/src/computer_use.rs+++ b/desktop/src-tauri/src/computer_use.rs@@ -984,6 +984,15 @@ fn arm_setup_resume(state_dir: &Path, now: SystemTime) -> io::Result<()> {std::fs::write(state_dir.join(SETUP_RESUME_FILE), unix_seconds(now).to_string())}+/// Whether a marker's contents name a request inside its window at `now`.+fn setup_resume_in_window(contents: &str, now: SystemTime) -> bool {+ let Ok(armed_at) = contents.trim().parse::<u64>() else {+ return false;+ };+ let now = unix_seconds(now);+ armed_at <= now && now - armed_at <= SETUP_RESUME_WINDOW.as_secs()+}+/// Consumes the marker a guide-driven Screen Recording request left, and says/// whether this launch is that request's relaunch. A marker is read once:/// stale or not, it never steers a second launch.@@ -993,11 +1002,15 @@ fn take_setup_resume_at(state_dir: &Path, now: SystemTime) -> bool {return false;};let _ = std::fs::remove_file(&path);- let Ok(armed_at) = contents.trim().parse::<u64>() else {- return false;- };- let now = unix_seconds(now);- armed_at <= now && now - armed_at <= SETUP_RESUME_WINDOW.as_secs()+ setup_resume_in_window(&contents, now)+}++/// Whether a guide-driven Screen Recording request is still waiting on its+/// relaunch, so a quit now is most likely macOS's "Quit & Reopen". The marker+/// stays for the relaunched shell to consume.+fn setup_resume_pending_at(state_dir: &Path, now: SystemTime) -> bool {+ std::fs::read_to_string(state_dir.join(SETUP_RESUME_FILE))+ .is_ok_and(|contents| setup_resume_in_window(&contents, now))}/// Whether this launch should reopen the Computer Use guide.@@ -1005,6 +1018,11 @@ pub(crate) fn take_setup_resume(app: &AppHandle) -> bool {state_dir(app).is_ok_and(|dir| take_setup_resume_at(&dir, SystemTime::now()))}+/// Whether a quit now is the relaunch the Computer Use guide is waiting on.+pub(crate) fn setup_resume_pending(app: &AppHandle) -> bool {+ state_dir(app).is_ok_and(|dir| setup_resume_pending_at(&dir, SystemTime::now()))+}+fn restored_lifecycle(stored: &StoredComputerUseState, assets_valid: bool) -> ComputerUseLifecycle {let mut lifecycle = match stored {StoredComputerUseState::Current(record) => ComputerUseLifecycle::from_record(record),@@ -2966,6 +2984,40 @@ doneassert!(!dir.join(SETUP_RESUME_FILE).exists());}+ /// macOS's Screen Recording "Quit & Reopen" arrives as an ordinary quit.+ /// While the guide's marker is armed and inside its window, that quit keeps+ /// the Runtime without asking, so the relaunched shell can adopt it; any+ /// other quit asks as before. Deciding never consumes the marker.+ #[test]+ fn a_pending_setup_resume_keeps_the_runtime_on_quit_without_asking() {+ let temporary = tempfile::tempdir().expect("temporary directory");+ let dir = temporary.path();+ let armed = UNIX_EPOCH + Duration::from_secs(1_800_000_000);+ let quit_at = |now| crate::unasked_quit_choice(setup_resume_pending_at(dir, now));++ assert_eq!(quit_at(armed), None, "no marker: the quit question is asked");++ arm_setup_resume(dir, armed).unwrap();+ for now in [armed, armed + SETUP_RESUME_WINDOW] {+ assert_eq!(quit_at(now), Some(crate::QuitChoice::Keep));+ }+ assert!(+ take_setup_resume_at(dir, armed + SETUP_RESUME_WINDOW),+ "the relaunched shell still finds the marker the quit read"+ );+ assert_eq!(quit_at(armed), None, "a consumed marker no longer skips the question");++ for (now, label) in [+ (armed + SETUP_RESUME_WINDOW + Duration::from_secs(1), "expired"),+ (armed - Duration::from_secs(1), "from the future"),+ ] {+ arm_setup_resume(dir, armed).unwrap();+ assert_eq!(quit_at(now), None, "an {label} marker behaves as no marker");+ }+ std::fs::write(dir.join(SETUP_RESUME_FILE), "not a time").unwrap();+ assert_eq!(quit_at(armed), None, "an unreadable marker behaves as no marker");+ }+#[test]fn only_a_pending_screen_recording_grant_keeps_the_resume_marker() {assert!(awaiting_screen_recording(diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rsindex 01f018a27..de700e1cb 100644--- a/desktop/src-tauri/src/lib.rs+++ b/desktop/src-tauri/src/lib.rs@@ -845,6 +845,41 @@ fn stop_for_session_end(app: &AppHandle) -> Option<impl std::future::Future<Outp})}+/// The answer a quit gets without the question, if any. The Computer Use+/// guide's Screen Recording step ends in macOS's "Quit & Reopen", which reaches+/// the shell as an ordinary quit; the relaunched shell adopts a Runtime that+/// kept running, so stopping it would only interrupt every Agent turn in+/// flight. While that relaunch is pending, a quit keeps the Runtime.+fn unasked_quit_choice(setup_relaunch_pending: bool) -> Option<QuitChoice> {+ setup_relaunch_pending.then_some(QuitChoice::Keep)+}++fn setup_relaunch_pending(app: &AppHandle) -> bool {+ #[cfg(target_os = "macos")]+ {+ computer_use::setup_resume_pending(app)+ }+ #[cfg(not(target_os = "macos"))]+ {+ let _ = app;+ false+ }+}++fn carry_out_quit(app: &AppHandle, choice: QuitChoice) {+ match choice {+ QuitChoice::Stop => stop_runtime(app.clone(), true),+ QuitChoice::Keep => {+ if claim_runtime_stop(&app.state::<Shell>().activity) {+ exit_shell(app);+ } else {+ show_lifecycle_busy(app);+ }+ }+ QuitChoice::Cancel => {}+ }+}+fn request_runtime_lifecycle(app: AppHandle, quit: bool) {let shell = app.state::<Shell>();if !matches!(shell.activity.load(Ordering::SeqCst), ACTIVITY_IDLE | ACTIVITY_MONITOR) {@@ -867,6 +902,13 @@ fn request_runtime_lifecycle(app: AppHandle, quit: bool) {shell.dialog_pending.store(false, Ordering::SeqCst);return;}+ if quit {+ if let Some(choice) = unasked_quit_choice(setup_relaunch_pending(&app)) {+ carry_out_quit(&app, choice);+ shell.dialog_pending.store(false, Ordering::SeqCst);+ return;+ }+ }let catalog = native_tray_catalog();if quit {let callback_app = app.clone();@@ -875,17 +917,7 @@ fn request_runtime_lifecycle(app: AppHandle, quit: bool) {.title(catalog.quit_title.clone()).buttons(quit_dialog_buttons(&catalog)).show_with_result(move |result| {- match quit_choice(result, &catalog) {- QuitChoice::Stop => stop_runtime(callback_app.clone(), true),- QuitChoice::Keep => {- if claim_runtime_stop(&callback_app.state::<Shell>().activity) {- exit_shell(&callback_app);- } else {- show_lifecycle_busy(&callback_app);- }- }- QuitChoice::Cancel => {}- }+ carry_out_quit(&callback_app, quit_choice(result, &catalog));callback_app.state::<Shell>().dialog_pendingdiff --git a/docs/desktop-computer-use.md b/docs/desktop-computer-use.mdindex 582f5beb1..dc9ba4bb3 100644--- a/docs/desktop-computer-use.md+++ b/docs/desktop-computer-use.md@@ -47,9 +47,12 @@ as a manual fallback. Accessibility comes first because the managed driverchecks it before Screen Recording.If macOS asks to **Quit & Reopen** after the Screen Recording grant, choose it.-When the request came from this page, the relaunched app opens the Settings-guide again by itself (within 15 minutes of the request), and the page picks up-the new status. A later launch is not redirected.+When the request came from this page, the app quits without asking whether to+stop the Runtime: the Runtime keeps running, so Agent turns in flight are not+interrupted, and the relaunched app reconnects to it. It then opens the+Settings guide again by itself (within 15 minutes of the request), and the page+picks up the new status. Outside that window, Quit asks as usual, and a later+launch is not redirected.The Settings entry appears only in the Avibe desktop app. A browser tab orphone that opens `/settings/computer-use` directly sees the same live steps