Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/desktop/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ pub fn build() -> Kernel<App> {
.register_slot(&crate::key_sequence::SEQUENCE)
.register_slot(&crate::servers::dialog::DIALOG)
.register_slot(&crate::shell::memory_reclaim::SWEEP)
.register_slot(&crate::shell::tab_hibernate::HIBERNATE)
.register_slot(&crate::servers::health::HEALTH_WAKE)
.register_slot(&crate::plugin_host::native::embeds::EMBEDS)
.register_slot(&crate::plugin_host::aux_windows::AUX_MANAGER)
Expand Down Expand Up @@ -638,4 +639,6 @@ fn register_core_systems(b: &mut KernelBuilder<App>) {
false
})
.after("restore.persist");
b.schedule(stage::PERSIST_FLUSH, "tab_hibernate.poll", crate::shell::tab_hibernate::poll)
.after("windows.persist");
}
4 changes: 4 additions & 0 deletions apps/desktop/src/session/meta/context_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ impl Windows {
}
}

pub fn contains(&self, server: &str, id: &str) -> bool {
self.map.get(server).is_some_and(|by_id| by_id.contains_key(id))
}

pub fn forget(&mut self, server: &str, id: &str) {
if let Some(by_id) = self.map.get_mut(server) {
by_id.remove(id);
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/session/meta/turn_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl TurnDiffs {
self.states.remove(&(session.to_owned(), from.to_owned()));
}

pub fn has_any(&self, pred: &dyn Fn(&str) -> bool) -> bool {
self.states.keys().any(|(session, _)| pred(session))
}

pub fn retain(&mut self, keep: &dyn Fn(&str) -> bool) {
self.states.retain(|(session, _), _| keep(session));
}
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/session/pages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ impl crate::App {

pub fn open_page(&mut self, id: &str, tx: &mut rune::Tx) {
if self.queue.starts.has(id) { return; }
if !self.transcripts.contains_key(id) { let srv = self.pages.server().to_owned(); self.pages.histories.forget(&srv, id); self.pages.gaps.remove(id); self.pages.bridges.remove(id); }
let Some(pages) = &self.pages.pool else { return };
let ready = pages.peek(id);
let key = self.page_key(id);
Expand Down Expand Up @@ -604,6 +605,7 @@ impl crate::App {
let dirty = if echo_dropped { 0 } else { dirty };
((dirty != usize::MAX).then_some(dirty), (first, delivered))
});
if first && !page.history { let srv = self.pages.server().to_owned(); self.pages.histories.forget(&srv, id); self.pages.gaps.remove(id); self.pages.bridges.remove(id); }
self.settle_inbox(id, &delivered);
if cold { self.launch.cold_transcript = None; }
// A timeline read up from its end (a place kept from the last run) isn't carried to it.
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ pub mod navigation;
pub mod overlays;
pub mod panels;
pub mod perf;
pub mod tab_hibernate;
pub mod tabs;
pub mod view;
491 changes: 491 additions & 0 deletions apps/desktop/src/shell/tab_hibernate.rs

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions apps/desktop/src/workspace/servers/half.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,18 @@ impl Checkout {
parked_xor.hash(&mut h);
h.finish()
}

/// Order-independent untracked stamp of every parked server's hibernation inputs (`0` when no
/// parked servers exist). Eliminates periodic 60 s busy-recheck wakeups for parked servers.
pub(crate) fn parked_hibernate_stamp(&self) -> u64 {
if self.slot.parked.is_empty() { return 0; }
use std::hash::{Hash, Hasher};
let mut xor = 0u64;
for (key, _, half) in &self.slot.parked {
let mut h = std::collections::hash_map::DefaultHasher::new();
(key, Tracked::untracked(&half.opening).is_some(), Tracked::untracked(&half.store).hibernate_data_stamp()).hash(&mut h);
xor ^= h.finish();
}
xor
}
}
20 changes: 20 additions & 0 deletions apps/desktop/src/workspace/windows/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,26 @@ impl Link {
}
}

/// Untracked activity stamp for parked-server hibernation (omits `transcripts` version so
/// token deltas never trigger scans; tracks whole-transcript count and busy cells).
pub(crate) fn hibernate_data_stamp(&self) -> u64 {
use std::hash::{Hash, Hasher};
let hash_data = |d: &ServerData| {
let mut h = std::collections::hash_map::DefaultHasher::new();
(
Tracked::version(&d.running), Tracked::version(&d.stops),
Tracked::version(&d.requests), Tracked::version(&d.pending),
Tracked::version(&d.inboxes), Tracked::version(&d.unsent),
Tracked::untracked(&d.transcripts).len(),
).hash(&mut h);
h.finish()
};
match &self.peer {
Some(peer) => { let v = peer.vault.borrow(); if v.at == At::Home { hash_data(&v.data) } else { 0 } }
None => hash_data(&self.local.borrow()),
}
}

/// Whether this server's known session list contains `sid`.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn has_session(&self, sid: &str) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions features/history/src/fork/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ impl ForkState {
self.machine.pending()
}

/// Session currently running an in-flight fork request, if any.
pub fn forking_session(&self) -> Option<&str> {
match &self.machine.state {
machine::State::Forking { session, .. } => Some(session.as_str()),
machine::State::Idle => None,
}
}

pub fn is_open(&self) -> bool {
matches!(self.modal, ForkModal::Open { .. })
}
Expand Down
5 changes: 5 additions & 0 deletions features/history/src/rewind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ impl RewindState {
self.sessions.get(session).is_some_and(SessionRevert::running)
}

/// True while a stop-induced prompt take-back is active for `session`.
pub fn taking_back(&self, session: &str) -> bool {
self.taking.get(session).is_some_and(|tb| !matches!(tb.state, opencode_runtime::machines::take_back::State::Idle))
}

pub fn menu_is(&self, session: &str, message_id: &str) -> bool {
self.menu.as_ref().is_some_and(|(s, m)| s == session && m == message_id)
}
Expand Down
5 changes: 5 additions & 0 deletions features/inbox/src/send_failed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ impl Log {
self.sent.iter().rev().find(|s| s.session == session).map(|s| s.id.as_str())
}

/// True while `session` has any unresolved, failed, or recoverable outbox entry (excludes `Accepted`).
pub fn has_unresolved_for_session(&self, session: &str) -> bool {
self.sent.iter().any(|s| s.session == session && s.phase != Phase::Accepted)
}

/// True while the outbox holds a live create write (`Start` or `Worktree`) for `session`.
pub fn has_pending_start(&self, session: &str) -> bool {
self.sent.iter().any(|s| {
Expand Down
9 changes: 9 additions & 0 deletions features/review/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ impl ReviewPane {
}
}

/// Whether `prune_cache` would remove any cached diff, VCS record, or orphaned `waiting` key.
pub fn has_prunable_cache(&self, keep_sessions: &HashSet<&str>, keep_dirs: &HashSet<String>) -> bool {
self.cache.keys().any(|k| match k {
ReviewCacheKey::Turn { session_id, .. } => !keep_sessions.contains(session_id.as_str()),
ReviewCacheKey::Vcs { directory, .. } => !keep_dirs.contains(directory),
}) || self.vcs_cache.keys().any(|(_, dir)| !keep_dirs.contains(dir))
|| self.waiting.iter().any(|sid| !self.sessions.contains_key(sid))
}

/// Drops cached diffs and VCS records for sessions and directories no open tab or route keeps
/// (`App::rest`), keeping memory bounded when windows rest.
pub fn prune_cache(&mut self, keep_sessions: &HashSet<&str>, keep_dirs: &HashSet<String>) {
Expand Down
Loading