Introduction

In DeepSeek Harness (DSH), modifying host-side code (such as index.js or lib/*.js) usually requires a full process restart to take effect. When the Agent cannot restart the process, it can only rely on manual user action. This plugin moves restart capability down to the Agent layer and adds safety controls to keep restart behavior manageable.

What Is This

dsh-safety-restart is a safe and seamless restart plugin for DeepSeek Harness, maintained by Dayi-Z and categorized under admin-security. It allows the Agent to restart the host and recover, but before restarting it must pass four safety gates (restart-loop circuit breaker, other active sessions, unresolvable bundle, unavailable relaunch method). If any gate fails, the restart is denied with an explanation.

Core Features

  1. Restart-loop circuit breaker: A counter based on loopMax and loopWindowMs prevents the Agent from triggering an infinite restart storm when the configuration is incorrect.
  2. Session state check: Before restarting, it checks whether other sessions are active (after turn/start but before turn/end) to avoid interrupting other work.
  3. Profile bundle validation: It checks whether node_modules and the entry file exist, and rejects configurations marked as checked:false.
  4. Cross-platform relaunch mechanism:
    • Desktop uses Electron app.relaunch().
    • Web/CLI uses process.exit() and a detached helper.
  5. Session recovery mechanism: It writes a continuation marker before restarting and restores the session context after restarting.
  6. Audit log: It records all restart decisions and states; the log file is named safety-restart-audit.l.

Installation and Enabling

Add the dependency and bundle to profiles/<name>/package.json:

// profiles/<name>/package.json
{
  "dependencies": { "dsh-safety-restart": "link:/path/to/dsh-safety-restart" },
  "dsh": { "profile": { "bundles": [ "...", "dsh-safety-restart" ] } }
}

After installation, restart the DSH instance once to ensure the plugin is loaded.

Typical Usage

Agent-side call:

safety_restart({ reason: "改了宿主半的 index.js,让新路由生效" })
safety_restart({ reason: "...", force: true })

UI operation: Settings → Plugins → “dsh-safety-restart” card.

HTTP API (localhost requests only):

GET  /safety-restart/status
POST /safety-restart/restart   { "reason": "ui" }

Applicable Scenarios and Notes

  • Permissions and execution: The plugin runs with the permissions of the current DSH process. Review the source code and license before installing.
  • Health checking: On Web/CLI, health checking means TCP port recovery, not HTTP 200.
  • Session check scope: The busy state covers only sessions started after the current process started; earlier sessions are not included.
  • Bundle check scope: It only proves that files exist, not that imports succeed, and not that the client contract is correct.
  • Network restriction: The HTTP API accepts only localhost requests; reverse proxies or remote access are rejected with 403.
  • Client compatibility: Client code must be compatible with the rc contract (list or keyed).

Summary

dsh-safety-restart turns restart from a manual action into a tool that the Agent can call, while using four safety gates to prevent the environment from being damaged by restarts. It provides audit logs and session recovery, making it suitable for scenarios that require frequent host-side code adjustments.

Catalog page | GitHub repository