dsh-session-keepwarm

DSH 0.1.7 introduced a reference-counting-based session management mechanism: when the main view switches sessions, the reference to the old session is released. When the reference count drops to zero, that session’s generation (containing local data, scoped Context, and history window) is destroyed. When switching back to that session, the system reconstructs a new generation and re-fetches the history (at least 50 messages), which causes the UI to display “Loading history…”.

The dsh-session-keepwarm plugin prevents this by holding extra references for recently used sessions, ensuring they are not destroyed. When switching back to these sessions, the already-loaded history window in memory can be directly reused, avoiding redundant reads. The plugin implements an LRU (Least Recently Used) cache based on the keepWarm setting, reducing history re-reads while controlling memory usage.

Basic Information

  • Name: dsh-session-keepwarm
  • Author: dzwalker
  • Category: Memory
  • License: MIT

Core Features

  1. Hold Extra References: Holds extra references for recently used sessions, ensuring they are not destroyed due to the reference count dropping to zero.
  2. Reuse History Window: When switching back to a kept-warm session, reuses the existing history window in memory. Since Session.open() is idempotent for already-open sessions, it does not fetch history again.
  3. LRU Cache: Implements an LRU cache with an upper limit determined by the keepWarm setting, preventing unbounded memory consumption.
  4. Session Monitoring: Monitors the sessions.list snapshot; when a session switch is detected, it moves that session to the head of the LRU queue.
  5. Normal Sessions Only: Only handles normal sessions; sub-agent rows have their own lifecycle management and are not affected by this plugin.
  6. Lightweight Keep-Warm: Only keeps client-local data and history streams warm; it does not start or hold a Host Agent.

Installation and Activation

Install the plugin using the following command:

dsh plugin --profile web add dsh-session-keepwarm

After installation, enable the plugin in the corresponding profile.

Configuration and Usage

The plugin’s configuration options are defined under the session-keepwarm profile entry:

Config Key Default Value Description
enabled true Master switch. Set to false to release all held references.
keepWarm 5 Number of recently used sessions to keep warm. Typically ranges from 1 to 20. A larger value consumes more browser memory.

Use Cases and Limitations

  1. Same Tab Only: This plugin is only effective for session state within the same browser tab. The client does not share session state across tabs or browsers (no SharedWorker or BroadcastChannel), so opening a session in a new window or browser still requires reloading history.
  2. First Open Still Requires Loading: Even if a session is kept warm, the first time it is opened in any tab, the history still needs to be loaded. Keep-warm only affects the “switch away and switch back” scenario.
  3. Exit Condition: This is a temporary solution. If the upstream DSH client adds a native “keep last N sessions” setting or an equivalent delayed-destruction policy, the upstream setting should be used preferentially and this plugin removed.

Summary

dsh-session-keepwarm solves the history re-read issue during session switching in DSH 0.1.7+ through a simple supplement to reference counting. It is suitable for users who frequently switch between multiple sessions to reduce history loading latency, but attention should be paid to its memory usage and same-tab limitations.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye