Introduction¶
When running long sessions in DeepSeek Harness (DSH), the context window gets progressively filled by historical messages, tool calls, and checkpoints. The official Basic compaction performs summarization and pruning when approaching the window limit; however, the calculation for the default threshold and output reserve might trigger proactive compaction too early when the model allows a large max_tokens. If you still want to use Basic’s built-in summarizer, /compact, overflow recovery, and token metering, but only wish to modify “when to compact, which segment to compact, and how to back off on failure” without switching presets or installing a separate compaction engine, the community plugin dsh-compaction-policy (maintainer huohua-dev, category: workflow) provides a global policy-layer path.
The following introduces its positioning, default behavior, installation methods, and key configuration points. Facts are subject to the GitHub repository README and the v0.2.2 release notes; the plugin is in the Experimental stage, and the README explicitly states that summary quality under native Windows or real model GUI sessions has not been verified.
What is this¶
dsh-compaction-policy is a lightweight global compaction policy plugin for DeepSeek Harness: built upon the official Basic implementation that passes fingerprint verification, it replaces the proactive budget, interval selection, and no-progress retry guards; it retains Basic’s native pressure mechanism, checkpoints, tool pairing, token meter, UI event protocol, native /compact, and overflow recovery. It does not register presets, filter the preset registry, or add new automatic compaction listeners.
After installation, the default bundle only adds one root plugin entry compaction-policy-global (dsh-compaction-policy/global), which applies to eligible official Basic instances (including standard presets) within the same Cordis runtime. Instances with custom backends, subclasses, or overridden methods will be skipped; minimal combinations without compaction are unaffected. “Global” does not imply all DSH processes or profiles on the machine.
Host Compatibility (README): The bundle declares support for loading DSH ^0.2.1-rc.1 (including subsequent RCs for 0.2.x) and Cordis 4.0.x; the policy only activates if the five sets of Basic method fingerprints match the verified implementation; unrecognized host builds will remain loaded but in an inert state rather than failing to start.
Core Features¶
Default Policy: 90% Threshold, Avoiding Double Deduction of Output Reserve¶
Compared to stock Basic, the plugin recalculates the proactive threshold using fields like thresholdRatio, outputReserveCap, and headroomTokens. The defaults are thresholdRatio: 0.9, outputReserveCap: 0, headroomTokens: 0, meaning the proactive threshold is floor(W × 0.9), leaving approximately 10% as headroom that is not deducted a second time.
The README provides a comparative calculation example (arithmetic explanation, not a performance benchmark): for a window of 262,144 tokens and an output limit of 131,072, the stock threshold is approximately 65,536, while under the policy, it is approximately 235,929.
Key formula points (consistent with README):
reservedOutput = min(requestMaxTokens, outputReserveCap)
policy threshold = floor(min(W × thresholdRatio,
W − reservedOutput − headroomTokens))
retentionTarget = floor((W − reservedOutput) × retainRatio)
pruneToolResults: false (default) only applies to the new proactive-pressure path: this path does not prune tool results first; old content is summarized via Basic. It does not disable the native pruner, nor does it change stock mode, manual, or confirmed-overflow behavior.
The README reminds: output cap is not equal to guaranteed available space; a 90% full prompt and a full-capacity completion cannot coexist in a fixed window. The adapter layer/server still needs to constrain remaining capacity; this plugin is not an HTTP output budget clamp.
Interval Selection and Failure Guards¶
- Retain recent history: The soft target defaults to
retainRatio: 0.16(relative toW − reservedOutput); entire message and tool-call/result units remain atomic. The latest unit is retained as-is even if it exceeds the target. - Segment selection logic: Allows older large messages to enter the summary scope to avoid repeatedly summarizing only extremely small checkpoints; system nodes are protected, and subsequent system nodes act as segment selection barriers.
- Minimum segment selection: Before proactive summarization, the selected range must contain at least 2,048 non-checkpoint tokens (
minFreshTokensdefault 2048). - Single-step transaction: Each pressure step performs at most one summarization transaction and does not immediately re-summarize a checkpoint just written.
- Failure backoff: On failure, backoff is 60s, 120s, 240s… up to a maximum of 10 minutes; upon expiration, one probe is allowed during the next pressure check. This is not a background model call; material changes in candidates allow earlier retries, while irrelevant tail additions will not.
- Native paths retained: Manual and confirmed-overflow paths, retry limits, transaction completion, and durable-progress checks still follow native logic, bypassing the proactive guard.
Installation and Enabling¶
Distribution is via GitHub, not npm. To install v0.2.2 tag:
github:huohua-dev/dsh-compaction-policy#v0.2.2
Desktop Managed Profile¶
- Add or update the above GitHub source in the Desktop Plugin Management UI.
- Fully quit and restart Desktop (refreshing the page or reloading the profile cannot substitute; the README records cases where old processes failed to import and required a full restart to recover).
- Continue using the existing preset; no dedicated preset is needed.
- Run
/compaction-policy-global statusin the session to view coverage and active policies.
In the Desktop managed environment, do not use CLI to modify plugins; the README explicitly rejects CLI workarounds like --profile desktop.
Web Profile Not Managed by Electron¶
Applies only to web profiles not managed by Desktop/Electron:
dsh plugin --profile web add github:huohua-dev/dsh-compaction-policy#v0.2.2
Then reload/restart the corresponding host. This CLI path is not an alternative installation method for Desktop.
Installation does not change the current default provider and preset, nor will it rewrite the main request’s output limit, reasoning effort, or token accounting.
Typical Usage: Configuring Global Entries¶
Override compaction-policy-global in the user profile. Policy fields are placed under config.policy. Line-based configuration is a whole-line replacement, not a deep-merge; after changing configuration, you need to reload the profile and restate custom items to be retained.
Example of using stock for everything except a specific exact route (from README):
- id: compaction-policy-global
config:
policy:
mode: stock
modelPolicies:
- provider: your-local-provider
model: your-model-id
mode: policy
thresholdRatio: 0.9
outputReserveCap: 0
headroomTokens: 0
pruneToolResults: false
provider / model matching is exact and case-sensitive. If modelPolicies is not configured, the default mode: policy applies to all eligible Basic instances.
Common policy fields (see README table for defaults and meanings):
| Policy field | Default | Summary of Meaning |
|---|---|---|
mode |
policy |
policy uses the new proactive policy; stock hands back to Basic. |
thresholdRatio |
0.9 |
Proactive window ratio, constrained by the remaining capacity branch. |
outputReserveCap |
0 |
Proactive output reserve cap (not the API output cap). |
headroomTokens |
0 |
Additional proactive deduction; the default 10% margin is already in the ratio. |
pruneToolResults |
false |
Whether the new proactive path calls the native tool-result pruner first. |
retainRatio |
0.16 |
Recent tail soft target ratio. |
retainTokens |
unset | Absolute soft target, mutually exclusive with retainRatio. |
minFreshTokens |
2048 |
Minimum non-checkpoint token weight for segment selection. |
retryAfterTokens |
4096 |
Required candidate change amount for retry before cooldown ends. |
retryCooldownMs |
60000 |
Initial cooldown for summarization failure. |
maxRetryCooldownMs |
600000 |
Exponential backoff limit. |
modelPolicies |
[] |
Exact override by { provider, model, ... }. |
dryRun |
false |
Observe the proactive path but do not prune/summarize; stock, manual, and overflow remain available. |
Except for modelPolicies and dryRun, other fields can be overridden on a single route. Unknown keys and illegal values will be rejected.
Applicable Scenarios and Notes¶
Who is it for: Developers already using official Basic compaction in DSH who wish to delay proactive triggering (default 90%), improve summary segment selection and failure backoff, and are unwilling to switch presets or fork the compaction engine.
Experimental and Test Scope: Version 0.2.2 is marked Experimental; the README states that actual-host testing with synthetic sessions and scripted model responses has passed, but this cannot be equivalent to proof of summary quality in live GUI or real models; it makes no promises of lossless summarization or larger context windows.
Security and Permissions: The plugin runs under the current DSH process permissions and participates in session compaction decisions. Please review the source code and MIT license yourself before installation, and confirm that local DSH / Cordis versions satisfy the engines and peer declarations (e.g., Node ^22.19.0 || >=24.0.0, DSH ^0.2.1-rc.1).
Ecosystem Note: DSH adopts an “everything is a plugin” philosophy; the SkillHub directory page is a community site and has no official affiliation with DeepSeek / Huanfang.
Conclusion¶
dsh-compaction-policy adjusts the proactive threshold (default 90%), retention intervals, and failure retry guards via a global policy without touching Basic’s core capabilities, making it suitable for long-session workflow tuning. The installation source is github:huohua-dev/dsh-compaction-policy#v0.2.2; after enabling, use /compaction-policy-global status to verify its effectiveness.