Introduction¶
DeepSeek Harness (DSH) adopts the “everything is a plugin” philosophy. Existing restart plugins often interrupt the current response turn during user operations. The dsh-graceful-restart plugin aims to solve this problem. It uses an automatic “wrapper” mechanism to maintain a daemon process in the background. When a restart is required, it does not immediately kill the process; instead, it waits for the current turn to finish, ensuring that no work is lost. It also supports automatic rollback on startup failure and automatic page refresh.
Core Features¶
Graceful Restart¶
After the restart_harness tool or /restart slash command is triggered, the plugin does not immediately terminate the process; it waits for all current agent turns to finish. Only after confirming that the current response has been fully persisted to disk does the first-generation process launch the next generation, achieving a seamless handoff.
Automatic Wake-up After Restart¶
Before restart, the plugin writes the active session ID to a marker file. After the next generation starts, it polls and waits for the session to be restored, then automatically executes the steer() operation to wake the agent. The priority of the wake-up prompt is: continuePrompt parameter > default value in settings.yaml > built-in default.
Startup Supervision and Failure Rollback¶
This is the core capability of the plugin. It uses a git-style snapshot chain mechanism: before each startup, it records a plugin manifest snapshot, creates a time-ordered linked list, and uses a current pointer to reference the active version.
When startup fails (exit code is non-zero or the process exits within the grace period), the system performs the following steps:
1. Records the error separately.
2. Rolls the current pointer back to an earlier snapshot.
3. Compares the actual manifest with the current snapshot and calculates the difference.
4. Performs reverse operations (uninstall newly added items, reinstall items that were uninstalled, and restore the baseline for items with version changes).
5. Retries startup, looping until successful or until no earlier snapshots remain.
Automatic Page Refresh¶
The plugin uses the WebSocket connection state and generation ID (process startup timestamp) comparison to determine whether the page needs to be refreshed. Only when the connection is restored and the ID has changed does the page automatically refresh once. This approach does not rely on polling; actions are triggered only by connection events.
Settings Menu¶
A “Graceful Restart” tab is added to the DSH settings page, allowing users to view the snapshot timeline, error messages, and rollback records.
Installation and Configuration¶
The installation command is as follows:
dsh plugin --profile web add dsh-graceful-restart
After installation, restart DSH to make it take effect. For local development, if using a file: dependency, after code changes you must first remove and then add to resynchronize.
In settings.yaml, you can configure the default prompt used during wake-up:
dsh-graceful-restart:
continuePrompt: (系统已重启完成)请继续之前未完成的工作。
How to Use¶
Users can interact in the following ways:
- Model tools:
restart_harness(supports thecontinuePromptparameter and automatically wakes the agent),shutdown_harness(graceful shutdown without restart),cancel_harness_action(cancels a scheduled restart or shutdown that has not been executed). - Slash commands:
/restart(restart; requires waiting for wake-up),/shutdown(shutdown).
Working Principle and Files¶
The plugin redirects output back to the user terminal through the ConPTY handle inheritance chain. The first-generation process acts as an invisible Launcher, responsible for launching the next generation and handling the daemon logic.
Related files are located under $DSH_HOME:
* dsh-process.json: process index.
* dsh-graceful-restart-snapshot.json: startup supervision snapshot chain and current pointer.
* dsh-resume.json: wake-up marker.
* dsh-graceful-restart.log: plugin and daemon logs.
* dsh-graceful-restart-stderr-<timestamp>.log: full error output for each startup attempt.
Notes¶
- Runtime environment: Users must start via
dsh web; the plugin relies on the Windows Terminal ConPTY handle inheritance chain to display output correctly. - Activation: It takes effect only after restarting DSH following installation.
- Rollback mechanism: Rollback has no count limit; it continues until startup succeeds or no earlier snapshot exists.
- Cancellation: Scheduled but not yet executed restart or shutdown operations can be canceled at any time with
cancel_harness_action.
Conclusion¶
This plugin solves the problem that DSH had to interrupt the current task during plugin upgrades or configuration changes. With automatic rollback and wake-up mechanisms, it provides a more stable and more intelligent runtime experience than the native restart.
- Plugin catalog: https://www.skillhub.cn/plugins/msilita/dsh-graceful-restart
- Source code: https://github.com/msilita/dsh-graceful-restart