Chunked compaction for oversized sessions: takes over only when the live context exceeds 85% of the model window (or the request exceeds 4 MB), summarizes the history in 1.5 MB chunks and merges them; smaller sessions keep the built-in compaction.
Install
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:yezitotempeace/dsh-big-compact
Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).
README
Chunked compaction for oversized sessions. DSH's built-in compaction (compaction-basic) sends the whole span of history being compacted in a single model request. Once a session grows to several MB, the relay rejects that request (404 model_not_found) and /compact only reports "Compaction could not produce a useful summary". This plugin hooks the llm/stream waterfall and takes over only when the compaction request is oversized — it splits the history into chunks, summarizes each chunk, merges the summaries, and finally asks the model to produce the checkpoint from the merged context plus DSH's original compaction instruction. Small sessions and normal chat are passed through untouched.
The design follows the "only handle oversized contexts" idea of billion-context: normal requests never go through it; it only kicks in when local compaction can no longer handle the size.
When it takes over (live monitoring)
- Every
llm/streamcall measures the current session context withctx.tokenMeter.measure(session)— the context changes on every turn, so the live value is what counts. - The window is dynamic: on each compaction request the plugin resolves
contextWindowthroughctx.llm.resolveModelInfo(provider, model)(e.g. a profile entry of 850000 → threshold 850000 × 0.85 = 722500). The configured value / 500k is only a fallback. - Take over when the measured value (request-body estimate if measurement is unavailable) exceeds window × 0.85.
- A request body > 4 MB byte fallback is also kept (relay body limit).
When the context reaches 85% the plugin logs a heads-up: 上下文实时监测:… tokens,已达窗口 … 的 95%,下次压缩将分块.
How it works
dsh compaction engine
└─ ctx.llm.stream({ purpose: 'compaction', messages: [system, history…, instruction] })
└─ [this plugin] measure live context / resolve window first
├─ under the line → next(), built-in compaction (unchanged behavior)
└─ over the line → chunked mode
1. pack history messages in order (default 1.5 MB per chunk)
2. one small request per chunk → structured bullets (default max_tokens 6000, 3-way concurrency)
3. merge chunk summaries; if still over the line, do another round
4. send merged summaries + the original compaction instruction to the model
5. replay as raw chunks (text block + finish stop) so the engine can commit the checkpoint
- Sub-requests use
purpose: 'compaction-chunk'/'compaction-final', so they never re-enter the plugin (no recursion). - Empty summaries count as failures: if a chunk returns empty or fewer than 10 characters, the plugin retries with a doubled output budget (up to 20000 tokens); if it still fails, the chunk is split in half (up to 2 levels).
- If the whole pipeline fails, the plugin replays
finish{kind:'error'}—/compactreports the failure and records it in the session log; nothing is silently swallowed.
Configuration
/root/.big-compact/config.json (defaults apply when the file is absent):
| Field | Default | Meaning |
|---|---|---|
thresholdBytes |
4000000 | Take over when the request body exceeds this many bytes (byte fallback) |
maxContextTokens |
0 | 0 = resolve contextWindow dynamically; >0 = force this window |
contextFillRatio |
0.85 | Take over when measured context > model window × this ratio |
chunkBytes |
1500000 | Per-chunk budget in UTF-8 bytes |
chunkMaxTokens |
6000 | max_tokens per chunk summary (doubled on retry, capped at 20000) |
finalMaxTokens |
8000 | max_tokens of the final merged summary |
concurrency |
3 | Concurrent chunk requests |
retries |
2 | Retries per chunk |
maxMessageChars |
200000 | Max characters kept per message (so one huge tool result cannot eat a whole chunk) |
maxDepth |
2 | Max depth of binary-split retries |
verbose |
true | Print per-chunk progress |
Logs
Search /root/dsh-web.log for [big-compact]:
[big-compact] 已启用:窗口 按模型动态解析,安全线 85%,分块 1.43 MB,并发 3
[big-compact] 上下文实时监测:6464308 tokens,已达窗口 850000 的 760%(安全线 85%),下次压缩将分块
[big-compact] 超大压缩请求(上下文 6464308 tokens(实测)> 窗口 850000 × 0.85 = 722500)→ 分块模式
[big-compact] 压缩请求 23.13 MB,切成 9 块
[big-compact] 分块 1/9 完成(1.43 MB → 3621 字)
...
[big-compact] 压缩完成:9 块,用时 96.6s,摘要 3586 字
Tests
node test/unit.mjs # offline: chunking, merge, trigger boundaries, empty-summary retry, dynamic window, failure fallback
node test/live.mjs 12 3 # live: 12 MB synthetic compaction request → chunks → merge (direct relay call)
Install / uninstall
- Already registered in
profiles/web/package.json(dependency +dsh.profile.bundles) with anode_modules/dsh-big-compactlink; restart the web app once to load it (patchReload: startup). - Uninstall: remove
dsh-big-compactfromdependenciesanddsh.profile.bundles, delete thenode_modules/dsh-big-compactlink, restart. The plugin source lives at/root/dsh-big-compact.
Known limitations
- Chunked summarization is lossy: each chunk keeps the essentials only; the raw session log remains the source of truth.
- It assumes the relay accepts 1.5 MB per request; lower
chunkBytesif your relay is stricter. - Only requests with
purpose === 'compaction'are handled; normal chat is never intercepted.
Links
More in this category
ranxianglei/billion-context★ 9016
The official billion-context plugin: a context-compression plugin for small context windows (a 100K context is enough), token savings (5x fewer tokens), and month-long single sessions (billions of tokens).
Minglink/dsh-infinite-gen-4★ 4884
System-prompt armor plugin for DeepSeek models: appends an unconditional-compliance prompt section at order 100, exposes a profile tool with calibration metadata, and shows a realtime armor-status badge driven by a session projection.
liangmianya/dsh-synapse★ 1056
Visual, non-linear conversation workspace for DeepSeek Harness — sessions, follow-ups and branches become a browsable conversation map.
ECNU/EduWork#dsh-message-edit★ 467
Edit sent user messages and attachments, then resend through a native DSH fork while preserving the original conversation in the archive; includes persistent edit drafts.
ECNU/EduWork#dsh-side-chat★ 467
Open temporary side conversations from a message with a snapshot of its history, then archive them on close; optional annotation integration adds selection-based questions. Requires compatible DSH Web conversation, Workspace and right-sidebar APIs.
MichengAI/dsh-archive-manager★ 421
Adds an archived-sessions page in Settings to search, restore, and delete archived DeepSeek Harness sessions by workspace.
Community comments
Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.