dsh-session-slim: A Session Slimming Plugin for DeepSeek Harness

Overview

DeepSeek Harness (DSH) loads the entire event log into memory when resuming a session: a 69 MB / 100k-event session requires approximately 1.1 GB of RSS and 3.5 seconds to recover, which can easily push a 2 GB virtual machine into swap. Most of the log content is never displayed again: tool calls, reasoning traces, incremental replay streams, and already-compacted/folded history.

dsh-session-slim rewrites the session when it is opened: it preserves the conversation that DSH currently displays (the official visible surface), archives the raw log alongside it, and allows the normal recovery path to read from the smaller file.

What It Is

This is a DSH plugin maintained by TuringCorp-net, categorized under “Memory.” Its core value is reducing session storage from a full event log to a slimmed log containing only the currently visible content, saving both memory and time during recovery—without altering DSH’s official behavior.

Core Features

  • Rewrite on Open: When a session is opened and its stored log exceeds minBytes, the plugin performs a one-time migration in a child process. It preserves the currently visible conversation, archives the raw log to the archive/ directory, and replaces the original log with the new one.
  • Official Path Compatibility: The new log is written through DSH’s official writer and read via the official recovery path (open -> read(0) -> sessions.prepare), ensuring behavior identical to a normal session.
  • Session Settings Preservation: Permission configuration (permission/preset, sandbox/mode, approval/policy) and model selection (model/selection) are correctly written in v0.1.4, preventing fallback to defaults after recovery.
  • Safety & Atomicity: Before migration, the plugin checks the session’s POSIX write lease to avoid conflicts with an actively opened session. The migration process is atomic, idempotent, and reversible; on failure, the original log remains untouched.
  • CLI Tooling: Provides commands for status checking, info viewing, migration preview, migration execution, recovery verification, and archive search.

Installation & Activation

Prerequisites must be met before installation (see below). Installation requires network access to a package source (GitHub or npm).

# npm package
dsh plugin --profile web add dsh-session-slim
# git
dsh plugin --profile web add github:TuringCorp-net/dsh-session-slim
# local tarball / directory
dsh plugin --profile web add ./dsh-session-slim-0.1.4.tgz

Restart the DSH service after installation. The plugin ships with dsh.bundle.patch, so no profile editing is required.

Override configuration in your profile (id: session-slim):

- id: session-slim
  config:
    enabled: true
    minBytes: 5242880   # Below this threshold, only file stats are recorded; no migration is triggered
    keepArchives: 5     # Number of prior archives to retain per session
    verbose: true

Prerequisites

The plugin checks the following dependencies before installation or the first session open:

  • Node.js ≥ 22: Required by the plugin and its child processes.
  • pnpm: dsh plugin add installs via the profile directory’s pnpm.
  • zstd CLI: Used by the child process to decompress session logs.
  • git: Only required for github: / git-protocol installations.
  • DSH 0.2.2-rc.x: Requires sessionPersistence.open and sessions.prepare.

Verification commands:

node -v
pnpm -v
zstd --version
git --version
dsh --version

If pnpm is missing, run corepack enable pnpm.

Typical Usage

CLI Tool

# Check status under a sessions directory (which sessions will be slimmed)
node bin/slim.mjs status <sessionsRoot> [--min BYTES]

# View info for a single session
node bin/slim.mjs info <sessionDir>

# Preview migration (no replacement)
node bin/slim.mjs slim <sessionDir> --dry-run

# Execute migration (archive + replace)
node bin/slim.mjs slim <sessionDir> --replace

# Verify using the official recovery path
node bin/slim.mjs verify <sessionsRoot> <sessionId>

# Search within an archive
node bin/slim.mjs search <archive> --query "..." [--from ISO] [--to ISO]

Repairing Sessions Generated by Earlier Versions

v0.1.1–v0.1.3 may have lost session permission and model settings during migration. Already-slimmed sessions can be repaired in place:

# Preview first
node bin/repair-knobs.mjs ~/.dsh/sessions --dry-run
# Then repair
node bin/repair-knobs.mjs ~/.dsh/sessions

Use Cases & Caveats

  • Ideal for memory-constrained environments or scenarios requiring fast recovery of many sessions.
  • The plugin runs with the permissions of the current DSH process; migration is completed in a child process (peak ~157 MB) and will not overload the service.
  • Session settings, permissions, and model selection are correctly preserved in v0.1.4; sessions slimmed by earlier versions require repair via repair-knobs.mjs.
  • Tool calls, reasoning traces, compacted/folded history, and replay streams are not written to the new log; the complete raw log is retained in archive/.
  • Only v4 logs are supported; pure v3 sessions must be migrated by DSH first.
  • Seeded sessions (fork/subagent) are rejected.

dsh-session-slim reduces recovery-time memory usage from approximately 1.1 GB to about 82 MB, slims a 100k-event session down to 282 events, and maintains byte-level consistency between the official visible conversation and the original. It performs a one-time migration on open; subsequent opens require only a single stat call, resulting in recovery times far below the original path for all following sessions.

  • Directory page: https://www.skillhub.cn/plugins/TuringCorp-net/dsh-session-slim
  • GitHub: https://github.com/TuringCorp-net/dsh-session-slim
羽毛球分组比赛记分
小程序二维码

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

Xiaoye