dsh-smart-restart: A Verified Restart Solution for DeepSeek Harness

Introduction

Restarting a running process is inherently disruptive. Existing practices usually either require root privileges (invoking systemctl restart) or simply send a “service restarted” notification. This approach leaves two critical gaps: whether the service is truly healthy after the restart, and how to recover the work the requester was previously performing.

The dsh-smart-restart plugin aims to fill these gaps. It enables restarting the Harness without privileges and performs post-restart health checks, feeding the results and recovery instructions back to the session that initiated the request.

Core Features

  1. Unprivileged Restart
    In the default mode, the plugin simply terminates the process, allowing systemd to restart it based on the Restart=always configuration, without requiring sudo or polkit permissions. systemctl restart is available as an alternative mode for environments that already possess the necessary permissions.
  2. Post-Startup Health Check
    After every restart, the plugin checks the service status, the number of registered tools, the unit’s ActiveState/MainPID/NRestarts, and verifies if the listening port is owned by a process within the unit (based on cgroup checks). It outputs a final verdict of ok or degraded along with details of any failures.
  3. Session Reporting
    It records the intent (reason, recovery goal) before the restart. After the restart, this intent and the health check results are sent back to the initiating session, allowing work to resume based on facts rather than guesses.
  4. Cycle Protection
    If the number of restarts exceeds 3 within 10 minutes, the plugin refuses new restarts and reports an error, preventing restart failures from being masked by an infinite loop.
  5. Setup Card
    Provides a graphical settings interface in the DSH plugin list, supporting configuration in both Chinese and English.

Installation and Activation

Install the plugin via the DSH package manager:

dsh plugin --profile <profile> add @goodandready/dsh-smart-restart

Once installed, the plugin automatically registers its tools and startup check mechanisms.

Typical Usage

The plugin provides two core tools and two restart modes.

1. Execute Restart (dsh_restart)

Invoking this tool requires the following parameters:

  • reason: Reason for the restart
  • resume: Instructions or context for execution upon recovery
  • confirm: Whether to confirm execution
  • delayMs: Delay in milliseconds

Example:

await dsh_restart({
  reason: "manual_check",
  resume: "continue_last_task",
  confirm: true,
  delayMs: 3000
});

2. View Status (dsh_restart_status)

Views the latest startup information, downtime, health reports, pending intents, and the number of restarts within the window.

3. Restart Modes (restartMode)

  • kill (Default): Simply terminates the process, relying on systemd to restart it automatically. Unprivileged, but the current incomplete turn will be lost.
  • systemctl: Directly calls systemctl restart <unit>. Requires corresponding permissions, but preserves more process state (although the documentation notes that the in-flight turn is still lost in kill mode).

Scenarios and Notes

  • System Dependency: The default mode requires Harness to be managed by systemd (e.g., dsh-web.service), and the unit must be configured with Restart=always. The plugin automatically detects the unit name from the process’s cgroup.
  • Linux Limitations: Port and cgroup checks are only supported on Linux systems; these checks are automatically skipped on other systems.
  • User Units: If using systemd user units, the plugin automatically applies the --user flag.
  • State Loss: In kill mode, the current incomplete turn will be lost; this is by design. Resuming work relies on the resume instructions recorded before the restart.

Conclusion

dsh-smart-restart addresses the pain point of restart operations being “neither safe nor transparent” in the DSH environment. Through verified restarts and session feedback mechanisms, it provides more reliable assurance for the operations of agent systems.

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

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

Xiaoye