Introduction¶
When DeepSeek Harness (DSH) runs local LLM inference or orchestrates tool calls, excessive memory/VRAM usage by tool processes can easily overwhelm the system, causing session interruptions or even process crashes. The Resource Guard plugin (wth373737/dsh-resource-guard) described in this article estimates the peak overhead of a tool before execution, compares it against current hardware headroom, decides to allow/ask/deny, and injects a real-time budget into the system prompt so the model can account for actual hardware constraints when planning concurrency.
Plugin Positioning¶
Resource Guard is a model-inference plugin for DSH, maintained by wth373737. It adds a “pre-flight check” layer to DeepSeek Harness tool invocations: before a tool actually runs, it estimates peak memory and VRAM based on command-line arguments, script contents, historical measurements, and so on, then decides whether to proceed. It does not kill processes directly; instead, it guides the model to converge concurrency through prompts. It also provides a settings page and auto-tuning documentation so thresholds can be adapted to the current machine.
Core Mechanics¶
The plugin implements its functionality through the following hooks:
| Mechanism | Hook | Behavior |
|---|---|---|
| Pre-flight gate | tools/pre-execute |
Estimate peak → compare against current headroom → allow / ask / deny |
| Runtime circuit breaker | 1-second sampling + tools/post-execute |
On violation, append a warning to the tool result, prompting the model to converge concurrency |
| Budget injection | systemPrompt.context |
Inject current memory, VRAM, and safe concurrency count at each step |
| Configuration learning | Local JSON | Record measured deltas per signature (command + arguments) to calibrate estimates |
Estimation Method¶
- Explicit command-line signals: read parameters such as
max_workers=6,-j 8,xargs -P,-ThrottleLimit, etc. - Script content scan: if the command points to an existing
*.py|ps1|sh|js|bat|cmdfile and the file is ≤ 1 MB, read the first 64 KB and scan for worker counts, binary names, and torch/onnx markers. - Per-binary unit cost: e.g.,
qwen3-aligner6 GB/process, Python + torch 3.2 GB,ffmpeg1.2 GB,ollamascaled by model size. - Historical correction: when a signature has been run before, use the measured peak to refine the estimation rules.
Installation & Activation¶
Install from GitHub (recommended):
In DSH, open Plugins → + Add plugin and enter:
github:wth373737/dsh-resource-guard
After installation, restart DeepSeek Harness once so the plugin can load its new modules.
To develop from a local checkout:
- Clone the repository:
git clone https://github.com/wth373737/dsh-resource-guard.git
- Install the directory via the plugin manager’s
install_bundleor have the agent use the absolute directory path to install it. - Restart DeepSeek Harness once.
Once installed, the system prompt will include a resource budget block (currently in Chinese) containing memory, VRAM, and recommended concurrency.
Configuration Options¶
Set under the config section of the plugin package’s cordis.patch.yml; the plugin manager will auto-reload.
| Config Key | Default | Description |
|---|---|---|
enabled |
true |
Master switch |
mode |
ask |
ask to prompt, deny to reject outright, warn to log only |
scope |
heavy |
heavy gates only known expensive tools; all gates every invocation |
reserveGb |
6 |
Reserved headroom when evaluating physical pressure |
askRatio |
0.8 |
Estimated memory/limit ratio; exceeding this triggers a prompt |
denyRatio |
0.94 |
Estimated memory/limit ratio; exceeding this triggers denial |
vramAskRatio |
0.85 |
VRAM ask threshold |
vramDenyRatio |
0.97 |
VRAM deny threshold |
minEstimateGb |
4 |
Estimates below this value are not gated |
perWorkerGb |
3.2 |
Assumed peak memory per worker for safe concurrency estimation; replaced with the measured median when ≥ 3 historical samples exist |
breaker |
true |
Enable runtime monitoring |
breakerRatio |
0.92 |
Observed memory/limit ratio considered a violation |
injectBudget |
true |
Inject the real-time budget block |
learn |
true |
Feed measured peaks back into the estimator |
autoTune |
suggest |
off / suggest (write recommendation doc only) / apply (also write to config) |
tools |
[] |
Additional list of tool names marked as expensive |
debug |
false |
Also output to stderr |
Settings Page¶
After installation, a Settings → Resource Guard page appears, contributed by the plugin’s client (dsh.client + client.js), rather than generated from Host configuration. The page displays:
- Real-time budget (memory, VRAM, safe concurrency)
- Hardware-based recommendations with a “Fill recommended values” action
- All thresholds with descriptions, editable and saveable
- Read/write via the same-origin route
/resource-guard/api, requiring thex-resource-guard-uiheader
The page language follows the system language (navigator.language): Chinese systems see a Chinese UI, other languages show English.
Auto-Tuning Documentation¶
At startup, the plugin measures the machine and writes to $DSH_HOME/resource-guard/recommendation.md, containing hardware facts for each threshold. For example:
askRatio→ 0.78 — commit limit 66.9 GB ÷ 62.9 GB physical = 1.06, page file only 4 GB, so there is almost no overflow room and the ask line drops to 78%.
By default, autoTune: suggest only generates this document; apply writes the configuration to applied.json when the hardware fingerprint matches; off skips this step entirely.
State Files¶
The plugin maintains the following files under $DSH_HOME/resource-guard/:
history.json— typical cost (running average) and peak per signature, used for estimation. Safe to delete; the plugin will fall back to rule-based estimation.recommendation.md— local hardware recommendations, regenerated on every startup.applied.json— hardware fingerprint from the lastautoTune: apply.guard.log— latest run log, rotated at ~512 KB.
Known Limitations¶
- Invisible commands still require guessing: if concurrency is computed at runtime from configuration or CPU count, static analysis cannot read it. The runtime circuit breaker serves as a safety net in this case.
- Slow VRAM sampling:
Get-Countermeasurement blocks for 1–1.5 seconds; VRAM refreshes every 10 seconds, memory every 3 seconds. Short spikes may be missed. - No hard process kill: v1 only warns and prompts the model to converge. Safely killing only the process tree spawned by a specific invocation requires process-tree ownership; killing the wrong PID would be worse than the incident itself, so this is deferred to v2.
- Best-effort schema loading: the settings page relies on Harness’s own
schemastery; if it cannot be parsed, the plugin still runs, just without the form. - Two persistent PowerShell samplers, consuming approximately 40–60 MB.
- The injected budget block currently only supports Chinese.
Use Cases & Cautions¶
Suitable for DSH users who need strict management of local inference/tool-call resource usage, especially when running multiple concurrent tools, working with large VRAM models, or dealing with high-concurrency processes. The plugin runs with the current DSH process permissions; it is recommended to review the source code and license (MIT) before installation. For custom thresholds or extended rules, refer to the GitHub repository and the settings page documentation.
Summary¶
Resource Guard adds a layer of memory/VRAM estimation and gating to DeepSeek Harness tool invocations. Through pre-flight checks, runtime circuit breaking, and budget injection, it enables the model to plan concurrency based on real hardware rather than guesses. It provides a settings page, auto-tuning documentation, and local historical learning, making it ideal for users who want to keep local inference resources within safe boundaries.
Directory page: https://www.skillhub.cn/plugins/wth373737/dsh-resource-guard
GitHub: https://github.com/wth373737/dsh-resource-guard