A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
thinkterm-session: release the image store after idle periods
RoversXa13943a39ee2
diff --git a/thinkterm-session/src/hydrate.rs b/thinkterm-session/src/hydrate.rsindex 30b7de3d..8a97dae5 100644--- a/thinkterm-session/src/hydrate.rs+++ b/thinkterm-session/src/hydrate.rs@@ -1,5 +1,6 @@//! Attaching the pictures serialized lines name, fetching the ones not//! held, and keeping a held copy in step with the original.+use crate::clock::Clock;use crate::host::{request, SessionHost};use crate::images::{file_image, frame_count, merge_into, ImageStore};use crate::Lock;@@ -34,6 +35,7 @@ pub async fn hydrate_lines<H: SessionHost>(let mut requests = HashMap::new();let mut data_by_hash = HashMap::new();let domain = host.image_domain();+ images.lock().touch(host.clock().now());for im in &image_cells {let held = images.lock().get(&(domain, im.data_hash));match held {diff --git a/thinkterm-session/src/images.rs b/thinkterm-session/src/images.rsindex 249f1b7f..37a186fa 100644--- a/thinkterm-session/src/images.rs+++ b/thinkterm-session/src/images.rs@@ -225,6 +225,10 @@ mod tests {/// own.pub const MAX_IMAGES: usize = 128;pub const MAX_IMAGE_BYTES: usize = 64 * 1024 * 1024;+/// How long the store is kept without any picture being looked up or+/// added. The frames of a stream that stopped are refetched if a paint+/// ever wants them again, which for a frame stream is never.+pub const IDLE_IMAGE_RELEASE: std::time::Duration = std::time::Duration::from_secs(300);/// The images fetched from remote panes, by connection and hash, with the/// size each was last measured at.@@ -232,6 +236,7 @@ pub struct ImageStore {images: lru::LruCache<(crate::host::ImageDomainKey, [u8; 32]), (Arc<ImageData>, usize)>,bytes: usize,max_bytes: usize,+ last_touch: crate::clock::Timestamp,}impl Default for ImageStore {@@ -246,9 +251,31 @@ impl ImageStore {images: lru::LruCache::new(std::num::NonZeroUsize::new(max_images.max(1)).unwrap()),bytes: 0,max_bytes,+ last_touch: crate::clock::Timestamp::ZERO,}}+ /// Note that the store was used: `release_idle` counts from here.+ pub fn touch(&mut self, now: crate::clock::Timestamp) {+ self.last_touch = now;+ }++ /// Drop every picture once nothing has used the store for `idle_after`.+ /// Returns the bytes let go.+ pub fn release_idle(+ &mut self,+ now: crate::clock::Timestamp,+ idle_after: std::time::Duration,+ ) -> usize {+ if self.images.is_empty() || now.saturating_duration_since(self.last_touch) < idle_after {+ return 0;+ }+ let released = self.bytes;+ self.images.clear();+ self.bytes = 0;+ released+ }+pub fn get(&mut self, key: &(crate::host::ImageDomainKey, [u8; 32])) -> Option<Arc<ImageData>> {self.images.get(key).map(|(data, _)| Arc::clone(data))}diff --git a/thinkterm-session/src/pane.rs b/thinkterm-session/src/pane.rsindex 2b88069c..795573a3 100644--- a/thinkterm-session/src/pane.rs+++ b/thinkterm-session/src/pane.rs@@ -1068,6 +1068,11 @@ impl<H: SessionHost> PaneSession<H> {fn poll(self: &Arc<Self>, st: &mut PaneState) {let now = self.now();+ // A paint of any pane of this connection is the occasion to let a+ // stopped stream's frames go; the store is shared across them.+ self.images+ .lock()+ .release_idle(now, crate::images::IDLE_IMAGE_RELEASE);let mut forced_retry = false;let in_flight = st.poll_in_flight.load(Ordering::SeqCst);if in_flight != 0 {diff --git a/wezterm-mux-server-impl/src/sent_images.rs b/wezterm-mux-server-impl/src/sent_images.rsindex ec544c6e..bf35df58 100644--- a/wezterm-mux-server-impl/src/sent_images.rs+++ b/wezterm-mux-server-impl/src/sent_images.rs@@ -12,6 +12,9 @@//! So every image sent on a pane is remembered here for a while, keyed by//! hash, and a fetch is answered from memory first. The cell is still//! consulted for anything this has let go of.+//! Entries expire only under the capacity and byte limits, not on an idle+//! timer: elapsed time does not mean the client has fetched the pixels,+//! and the original cell may no longer exist when a delayed request arrives.use lru::LruCache;use std::num::NonZeroUsize;