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¶
- Unprivileged Restart
In the default mode, the plugin simply terminates the process, allowing systemd to restart it based on theRestart=alwaysconfiguration, without requiringsudoor polkit permissions.systemctl restartis available as an alternative mode for environments that already possess the necessary permissions. - Post-Startup Health Check
After every restart, the plugin checks the service status, the number of registered tools, the unit’sActiveState/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 ofokordegradedalong with details of any failures. - 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. - 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. - 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 restartresume: Instructions or context for execution upon recoveryconfirm: Whether to confirm executiondelayMs: 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 callssystemctl restart <unit>. Requires corresponding permissions, but preserves more process state (although the documentation notes that the in-flight turn is still lost inkillmode).
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 withRestart=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
--userflag. - State Loss: In
killmode, the current incomplete turn will be lost; this is by design. Resuming work relies on theresumeinstructions 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.