dsh-local-host-guard: DSH Intra-Host Sentinel

Preface

The DeepSeek Harness (DSH) host process is responsible for loading plugins, scheduling sessions, and handling I/O. In daily development, two types of “silent failures” commonly occur: the window remains open and the interface shows no errors, but the event loop has been hung by a synchronous subprocess call; or the heap memory approaches the ~4192 MB limit, causing the process to exit with a FATAL ERROR (exit code 134), where even a full GC can barely reclaim the numerous live objects before the crash. Relying solely on guessing the call stack or restarting makes it difficult to identify “which call caused the hang” or “which memory pressure should be reduced first” after the fact.

The following section introduces the community plugin dsh-local-host-guard (Maintainer: maozhuoshushu, Category: Workflow). It performs instrumentation for synchronous calls within the host process, forensics for main thread hangs, and provides rate limiting and observation features such as write gates, cold backfill gates, idle session offloading, and queue sentinels. It has zero dependencies (using only Node built-in modules). The interface and logs are primarily in Chinese. By default, it only reports issues; it does not automatically kill processes or forcefully alter business behavior.

What is this

dsh-local-host-guard is a companion observation tool and set of three-layer memory-related “gates” attached to the DSH host. When a hang occurs, it produces a hang report containing a command-line summary; when memory is tight, it can scan and (upon explicit configuration enabling actions) remove idle sessions from the SessionStore to reduce live objects. The plugin is loaded by the host and does not modify the DSH kernel asar. The author explains that attempts using NODE_OPTIONS preloading were unfeasible in the packaged Electron main process, hence the adoption of the DSH plugin form.

Core Features

Synchronous Calls and Hang Forensics

The plugin wraps spawnSync / execFileSync / execSync: it writes “Enter / Return” trace logs before and after each call; it applies a default timeout (generally 120 seconds, 10 seconds for taskkill-like commands) if the caller has not set one; and it logs slow calls if the threshold (default 3 seconds) is exceeded. An independent worker monitors the main thread heartbeat; if it stalls for more than the threshold (default 8 seconds), it writes a Hang Report to disk. This report includes the detection time, duration of the stall, currently unreturned synchronous calls, recent trace logs, memory and CPU stats, and is accompanied by a node process report. Once the main thread recovers, the same report is updated with the recovery time and total stall duration in milliseconds.

Capability Boundaries (As stated truthfully in the README): The instrumentation covers all wrapped synchronous subprocess waits. The timeout is effective for CommonJS modules that fetch child_process only at call time, and for modules loaded after the plugin, but cannot govern named imports bound during the ESM loading period. However, such calls still appear in the trace logs, allowing identification of the last “entered but not returned” call during a hang. It does not capture kernel-mode stacks; it only performs forensics, does not automatically kill processes.

Three Memory Gates and Queue Sentinel

In addition to the hang detection chain, the plugin includes a Write Gate, Cold Backfill Gate, Idle Session Offloading, and Queue Sentinel. These are used to suppress issues where “a single action amplifies into massive I/O / backfill / queue accumulation.” The offloading logic resides in lib/下放.mjs and removes idle, fully persisted sessions from the memory table via steps such as sessions.flush, strict disk verification, and sessions.detachEntered(entry) (it does not delete disk data or write session files; the three main sessions are in the default protection list). When the default 下放动作 (Offload Action) is “只报告” (Report Only), it does not execute detach, but only observes candidates and skip reasons (The README installation section states that without host-guard.json, the built-in defaults are 启用下放=true (Enable Offload) and 下放动作="只报告" (Offload Action = Report Only); see the README configuration table for complete key defaults).

Local State and HTTP Routes

The data directory is configurable by default; if not configured, it falls back to %USERPROFILE%\.dsh\host-guard. Typical artifacts include: 日志.log, 当前同步调用.log (instrumentation trace, rolling limit ~256 KB), 卡死报告\卡死-<timestamp>.json, node-reports\node-report-<timestamp>.json (directory names use ASCII because node’s built-in report generator struggles with Chinese paths on Windows), 状态.json, and 最近卡死报告.txt.

Read-only status (Local Loopback): http://127.0.0.1:19387/__dsh/host-guard/status. It also provides routes such as probe (read-only semantic probe), offload (manual scan round), and arm (reload configuration and re-arm gates, equivalent to avoiding a host restart after config changes); For external requests, please prioritize ASCII paths (e.g., /status, /arm). The README documents a case where Chinese pathnames registered successfully but resulted in a 404.

Installation and Activation

Install under the desktop profile (commands from the repository README):

# From npm (Package name reserved; available after release)
dsh plugin --profile desktop add dsh-local-host-guard

# Or install directly from Git repository
dsh plugin --profile desktop add https://github.com/maozhuoshushu/dsh-local-host-guard

After installation, mount it within the host. Configuration is written to %USERPROFILE%\.dsh\host-guard.json; if this file is missing, built-in defaults are used. The README explains that the default semantics are: 启用下放=true (Enable Offload) but 下放动作="只报告" (Offload Action = “Report Only”), meaning offloading logic is primarily for observation and does not execute detach.

Runtime Environment: package.json requires Node >= 20; License MIT; Current package version 1.0.0.

To actually execute offloading (rather than just reporting), you must explicitly set it in the configuration, for example:

{
  "启用下放": true,
  "下放动作": "detach",
  "下放闲置分钟": 10,
  "下放事件下限": 500,
  "下放阈值MB": 2600
}

To disable offloading, set "启用下放": false or change "下放动作": "只报告". You can also call GET /__dsh/host-guard/arm to apply configuration and gate reloading. For more keys (scan interval, per-minute limit, strict verification MB, protection list, etc.), refer to the README configuration table.

Typical Usage

CLI (Paths need to be replaced with your local plugin installation location)

The README uses the author’s Windows paths as examples; the general approach is to call the package’s lib/cli.mjs:

node <插件目录>\lib\cli.mjs --状态
node <插件目录>\lib\cli.mjs --标记
node <插件目录>\lib\cli.mjs --报告
node <插件目录>\lib\cli.mjs --自测卡死 4000

--状态 (Status) checks if the sentinel is on duty, instrumentation statistics, and the latest hang report; --标记 (Markers) views the trace tail and the last unreturned call; --报告 (Report) lists and prints the latest hang report; --自测卡死 (Self-test Hang) deliberately blocks the main thread for a specified number of milliseconds in an independent process to verify if the sentinel can capture evidence.

Hang and OOM Troubleshooting Workflow

  1. Host “Stops working entirely, no errors” → Open the latest Hang Report in the data directory or use CLI --报告, check “Currently stuck synchronous calls” and command line summaries, and compare against the 当前同步调用.log trace.
  2. Host OOM before exit → Check offloading-related fields and logs in status; if only observing, keep the default “Report Only”, and decide whether to adjust session volume or enable detach based on candidates and skip reasons.
  3. After changing host-guard.json → GET http://127.0.0.1:19387/__dsh/host-guard/arm?t=<timestamp>, no host restart is needed to re-arm the gates.

Applicable Scenarios and Notes

Suitable for: Developers and maintainers running DSH on a local desktop host for long periods, needing to reproducibly record “which sync subprocess hung the event loop,” or needing to explore reducing SessionStore live object pressure without deleting data.

Must Know:

  • The plugin runs with the same permissions as the current dsh host process. It hooks subprocess synchronous calls, reads/writes the audit directory, and calls Host Session APIs when configuration permits. You should review the GitHub Source Code and MIT License before installation.
  • After offloading/detach, new events for that session may only remain in memory and persistence behavior may change (as explained in the README). The author notes that “client re-entering and reading back from disk” has not yet been verified across the full chain in a real host, so the first version defaults to report only.
  • The community directory SkillHub Plugin Page and GitHub are independent ecosystem information sources and have no official affiliation with DeepSeek / High-Flyer. Star counts etc. are subject to the page display at the time (The clue indicated 0 stars).

Conclusion

dsh-local-host-guard consolidates the two major critical points of the host—synchronous call hangs and memory ceiling—into disk-persisted traces, hang reports, and configurable memory gates/offloading strategies. It is conservative by default, reporting without acting, making it suitable as a diagnostic plugin in local DSH workflows. For further information and installation:

  • Directory Page: https://www.skillhub.cn/plugins/maozhuoshushu/dsh-local-host-guard
  • Repository: https://github.com/maozhuoshushu/dsh-local-host-guard
羽毛球分组比赛记分
小程序二维码

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

Xiaoye