dsh-reaper: Reclaiming Orphaned Ports and Processes from Agent Sessions

Preface

When running frontend servers or scripts with agents in DeepSeek Harness (DSH), the common workflow is to launch vite, next dev, file watchers, or tunnels. After a round of conversation ends and the session closes, these processes often continue listening on ports such as 5173 or 3000. Starting a dev server again then triggers EADDRINUSE, leaving you to guess in the Task Manager or ps which node process is the one to kill.

Simple “kill by port number” tools can only tell you who occupies a port, but rarely whether it should be killed: will it accidentally terminate local MySQL, will it take down the running Harness itself, is the occupying process even related to the current workspace? dsh-reaper is a community plugin for DSH (maintainer 11111353535, workflow category). On top of inventorying local listening endpoints, it tags each occupant with ownership and risk level, presents a plan first, and only sends signals to reclaim ports after explicit confirmation.

What Is This

dsh-reaper is positioned as follows: it inventories listening endpoints for DeepSeek Harness, distinguishes occupants from the current session, workspace, and system services, previews the process trees to be terminated, and reclaims ports after user confirmation. The README summarizes it in one sentence: recover orphaned dev servers and listening processes left behind by agent sessions but never handed back.

The plugin registers tools and slash commands to the Harness through Cordis; it is implemented in pure ESM JavaScript (lib/), depending on node:* and @deepseek-ai/dsh-tools, resolved by the host, without bundling dependencies that could override host versions.

Core Capabilities

Scanning and Classification

The read-only scan enumerates local listening endpoints (TCP by default; UDP can be included via configuration or parameters) and combines the process table to make ownership determinations. Each endpoint receives a verdict, used to decide whether it qualifies for “safe bulk reclamation”:

verdict Meaning Selected by default when all: true?
agent-spawned Child process originating from the current Harness host process Yes
workspace Current workspace path appears in the command line Yes
dev-server Looks like a dev server, watcher, or tunnel No
unattributed Listening but cannot be attributed to this session No
system System process or well-known service port (e.g., 3306) No
protected Matches neverKill / protectPorts, or holds the Harness process tree No

Two rules keep the classification trustworthy: the scan walks upward from its own pid and refuses to terminate the entire ancestor chain and the Harness process tree; processes holding well-known service ports are recorded as system, not selected by all: true, and annotated as left alone rather than implying they can be force-overridden.

Reclaiming and Safe Defaults

Reclaiming is a destructive operation, and the defaults are extremely conservative:

  1. Without confirm: true, it only computes and returns the plan, sending no signals to any process.
  2. The plan includes the full descendant closure: killing the npm run dev wrapper without its children would leave processes still holding ports, so the plugin sorts by “deepest child first” before sending signals.
  3. It always refuses the Harness process tree, pids 0–4, neverKill matches, and occupants on protectPorts, even when the user explicitly passes pids, and it returns the reason.
  4. It sends SIGTERM first by default; only escalates to SIGKILL when force: true, and processes that still survive are reported in the result.
  5. After sending signals it re-probes the ports, reporting ports confirmed free or ports still held.

Scanning uses PowerShell/netstat fallbacks, ss, and lsof on Windows, Linux, and macOS respectively, as best effort; if a data source fails, the result ends with a degraded: ... note, attribution may become weaker but never fails silently.

Installation and Configuration

Install in DSH (command from the official README):

dsh plugin add https://github.com/11111353535/dsh-reaper

If installing from a local directory rather than a Git-hosted address, use an absolute path:

dsh plugin add /absolute/path/to/dsh-reaper

When tuning by profile, add config to the corresponding entry in ~/.dsh/profiles/<profile>/cordis.patch.yml written by the installer, for example:

- insert:
    - id: reaper
      name: 'dsh-reaper'
      config:
        neverKill: ['my-precious-daemon']
        protectPorts: [80, 443, 19387]
        includeUdp: false
        graceMs: 3000
        scanTimeoutMs: 20000
Config Key Default Description
neverKill [] Process name or command-line substring; matches are never signaled
protectPorts [] Processes occupying these ports are always refused; the Harness’s own web port is auto-added
includeUdp false Whether to enumerate UDP; dev servers are mostly TCP
graceMs 3000 How long to wait after SIGTERM before treating the process as still alive
scanTimeoutMs 20000 Upper time limit for a single system enumeration

Typical Usage

Slash Commands

/reap                  # inventory only
/reap --all            # preview all endpoints confidently attributable to this session
/reap --all --confirm  # execute reclamation after confirmation
/reap 5173             # preview reclamation of a single port
/reap 5173 3001 --confirm --force

Example inventory output (from the README, environment win32) lists the number of listening endpoints, processes, and reclaimable items, and shows per port the verdict, pid, runtime duration, and command line; system services and protected processes get an explanatory line.

Tool Interface

  • reaper_scan: read-only full scan. Optional includeUdp, workspace (defaults to the current session workspace).
  • reaper_reap: generates a plan; executes when confirm: true. Supports pids, ports, all (only agent-spawned and workspace), force, confirm (default false).
  • reaper_free_port: targets a single TCP port. If the port is already free it says so directly; if it cannot be attributed or is protected it reports the reason without guessing.

Agents can also call the above tools directly during conversations, with behavior consistent with the slash commands: preview first, then confirm.

Use Cases and Notes

Suitable for developers who frequently have agents in DSH start/restart dev servers and repeatedly hit port occupation. Also suitable before ending a long session, using /reap to see which local listeners are still related to the current workspace or Harness, before deciding whether to run --all --confirm.

Before using, note:

  1. The plugin runs with the permissions of the current DSH process, and the signal targets are real OS processes; before installing, it is recommended to read the GitHub repo source and MIT license.
  2. The community directory SkillHub plugin page and GitHub are independent information sources, with no official affiliation to DeepSeek / High-Flyer; stars and versions follow what each page displays at the time (package.json currently at version 0.1.0).
  3. Do not rely on port numbers or pids to bypass protected / system protection; daemons that need to be kept long-term should be written into neverKill or protectPorts.

Conclusion

dsh-reaper separates “who is occupying the port” from “can it be killed”: classify first, then plan the closure, and only reclaim after confirmation, then verify whether the ports are released. If you mainly do local development within the DSH workflow, it is a checkable path for dealing with EADDRINUSE and orphaned node processes.

羽毛球分组比赛记分
小程序二维码

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

Xiaoye