Lequait/dsh-context-rescue ↗★ 0
dsh-context-rescue
Emergency rescue for DeepSeek Harness sessions that hit the model context window: detect the overflow, fold the oldest history into a durable digest, retry the same step.
Install
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:Lequait/dsh-context-rescueREADME
Read the full README ↗Configuration
All keys are optional; pass them through the plugin's config block.
| Key | Default | Meaning |
|---|---|---|
enabled | true | mount the plugin at all; false leaves the harness untouched |
mode | "auto" | auto runs the full ladder (prune → host engine → mechanical fold → excerpt); fold runs the same ladder without the host compaction engine, so it never asks a model to summarise; diagnose detects and reports but rewrites nothing |
zeroModelOnly | false | never call the model/compactor; go straight to the mechanical fold |
trimOversizedMessages | true | when one message alone overflows, replace it with its own head and tail |
excerptChars | 3000 | characters kept from each end when that happens |
allowModelCompaction | true | allow T2 (the host engine) |
retainRatio | 0.25 | share of the current surface kept as the recent tail |
retainMinTokens / retainMaxTokens | 4000 / 40000 | clamps for the retained tail |
targetRatio | 0.75 | fold until the surface is at most this share of the window |
fitRatio | 0.9 | treat the surface as fitting below this share of the window |
minFoldTokens | 4000 | below this, folding is not worth a transaction |
maxAttemptsPerTurn | 2 | rescue budget per assistant turn |
maxDigestChars | 12000 | hard cap on the checkpoint body |
pinFirstUserMessage | true | keep the first user message outside every fold, unless that message alone is over the budget |
windowFallback | 196608 | window used when neither the failure nor the model info provides one |
extraPatterns | [] | regex sources added to overflow detection |
laneRefusalPatterns | ["dsh_compaction_refused", "bili owns compression"] | proxy refusals that permanently block T2 |
registerTools | true | register the three tools |
registerCommands | true | register /rescue and /rescue-status when the host has a command registry |
preflight | true | fold on agent/pre-step when the projection is already over the window |
repairTransactions | true | close a compaction bracket a crash left open; a dangling one blocks every later fold |
verbose | true | log rescue decisions to the session |
debug | false | log one structured line per decision — the detected code and window, both measurements, every tier with the reason it declined, and the folded span — so a session that is not being rescued says why |
Configuration mistakes are reported, not swallowed
Options are validated when the plugin mounts. An unknown key (retainRation), a mode the
plugin does not know, a ratio outside its usable range, or a targetRatio that sits at or above
fitRatio is logged as a config: warning instead of quietly changing the behaviour you expect.
A rescue plugin that silently ignores a typo is indistinguishable from one that is not installed.
The options are a real schema, not a wish list
lib/schema.js declares every option below as a Cordis/Schemastery schema, which the host uses in
two ways: it validates your patch before the plugin starts, and it documents the options in
dsh --dump-config-schema. A value the schema refuses (retainRatio: 5, mode: aggressive,
preflight: "yes") stops the boot with the field name and the bound, instead of starting with a
silently clamped number:
$.retainRatio expected number <= 0.6 but got 5
Unknown keys are deliberately left alone by the schema so the warning above can name your typo — the two checks cover different failures, and neither hides the other.
Configuration mistakes are reported, not swallowed
Options are validated when the plugin mounts. An unknown key (retainRation), a mode the
plugin does not know, a ratio outside its usable range, or a targetRatio that sits at or above
fitRatio is logged as a config: warning instead of quietly changing the behaviour you expect.
A rescue plugin that silently ignores a typo is indistinguishable from one that is not installed.