← Back to Skills Marketplace
scotthuang

优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart

by scotthuang · GitHub ↗ · v1.0.4
cross-platform ✓ Security Clean
728
Downloads
0
Stars
8
Active Installs
5
Versions
Install in OpenClaw
/install graceful-restart
Description
优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。依赖 openclaw CLI。触发词:重启、restart。
README (SKILL.md)

graceful-restart skill

触发条件

当用户要求重启 Gateway 时,自动触发此 skill。

问题背景

Gateway 重启后,会丢失上一轮会话的任务上下文,导致:

  • 主会话被中断,无法自动恢复
  • 需要用户手动发送消息才能继续

功能

自动执行"重启后自唤醒"流程:

  1. 设置一次性 cron 任务(默认 10 秒后触发)
  2. 执行 Gateway 重启
  3. 重启后自动发送消息到主会话

English Description

Problem: After Gateway restarts, OpenClaw loses the previous session context - the main session is interrupted and cannot resume automatically.

Solution: Auto-restart Gateway with self-wakeup. Sets a one-time cron task (default 10s) before restart, then sends a message to main session after Gateway recovers to resume tasks.

⚠️ Important: Must use this skill, NOT exec:

# ✅ Correct
node ~/.openclaw/workspace/skills/graceful-restart/graceful-restart.js --task "config changed"

# ❌ Wrong
exec openclaw gateway restart  # Don't do this!

Trigger: "重启", "restart Gateway"

使用方式

用户说"重启"时,自动执行:

[自动触发 graceful-restart skill]

或者用户可以指定任务:

重启 Gateway,继续之前的任务:安装 Python 包

命令行调用

node ~/.openclaw/workspace/skills/graceful-restart/graceful-restart.js
node ~/.openclaw/workspace/skills/graceful-restart/graceful-restart.js --task "继续安装 Python 包"
node ~/.openclaw/workspace/skills/graceful-restart/graceful-restart.js --task "继续安装 Python 包" --delay 60

实现原理

使用 --session main + --system-event

  • Cron 在主会话里注入一个 system event
  • Gateway 重启后,heartbeat 轮询到并交付给主会话
  • 主会话收到消息后回复用户

注意事项

  • Cron 任务时间可调整(默认 10 秒)
  • 使用 --delete-after-run 确保一次性任务自动清理

📝 更新 SOUL.md

使用此 skill 后,建议在 SOUL.md 中添加自动触发规则(见上方)。

⚠️ 重要:禁止使用 exec

Gateway 重启必须使用此 skill,禁止直接用 exec 执行:

正确:

node ~/.openclaw/workspace/skills/graceful-restart/graceful-restart.js --task "配置已修改,需要重启后生效"

错误:

exec openclaw gateway restart  # 禁止!

这样写

Usage Guidance
This skill appears to do what it claims: it uses the bundled Node script to add a one-time cron system-event and then calls 'openclaw gateway restart'. Before installing, verify that the 'openclaw' CLI on your system is the expected, trusted binary and that you are comfortable the agent can call it (the script will execute that binary). Test in a safe environment first to confirm the timing and behavior meet your needs. Note the script restarts the Gateway (service interruption) and schedules an automated system-event; ensure no other automation will react unexpectedly to that event. The script performs basic sanitization of the task text, but avoid passing sensitive secrets as the task argument. Finally, if you prefer tighter control, run the script manually instead of allowing autonomous invocation.
Capability Analysis
Type: OpenClaw Skill Name: graceful-restart Version: 1.0.4 The skill 'graceful-restart' is designed to gracefully restart the OpenClaw Gateway and resume tasks, addressing session context loss. The implementation in `graceful-restart.js` uses `execFileSync` with argument arrays to prevent command injection and includes robust input sanitization for the `--task` parameter. The `SKILL.md` explicitly instructs the AI agent to use this secure script and *not* to directly execute `openclaw gateway restart`, further mitigating prompt injection risks. The cron job created is temporary (`--delete-after-run`), and the `CHANGELOG.md` confirms that command injection vulnerabilities were specifically addressed in previous versions, indicating a strong focus on security. No evidence of malicious intent, data exfiltration, or unauthorized persistence was found.
Capability Assessment
Purpose & Capability
Name/description state a graceful restart that sets a one-time cron/system-event and restarts the Gateway. The metadata declares requiredBinaries: openclaw and permissions for gateway-restart and cron; the JS implements exactly those steps. The requested capabilities match the stated purpose.
Instruction Scope
SKILL.md instructs running the included node script (not ad-hoc exec commands). The runtime instructions and the script only invoke the openclaw CLI and do not read/write unrelated files, access environment secrets, or call external network endpoints. The script sanitizes the task text and documents usage, so the instruction scope stays within the described purpose.
Install Mechanism
There is no install spec (instruction-only with a bundled script). Nothing is downloaded from external URLs and no archives are extracted. This is low-risk given the script is included in the skill bundle.
Credentials
No environment variables or credentials are requested. The only external dependency is the openclaw CLI, which is necessary and declared in metadata. No unrelated secrets or config paths are required.
Persistence & Privilege
always is false and the skill is user-invocable; it does not request permanent presence or modify other skills' configs. The script runs a one-time cron via the openclaw CLI and then restarts the Gateway — this matches its purpose and does not request additional privileges.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install graceful-restart
  3. After installation, invoke the skill by name or use /graceful-restart
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.4
Version 1.0.4 of graceful-restart - No code or documentation changes detected in this release. - All features and usage remain the same as the previous version.
v1.0.3
- Updated the default cron delay for self-wakeup after restart from 30 seconds to 10 seconds in documentation. - Clarified usage instructions and examples to reflect the new default delay.
v1.0.2
add "requiredBinaries": ["openclaw"]
v1.0.1
- Updated description to clarify the dependency on openclaw CLI. - No code or functional changes; documentation update only.
v1.0.0
graceful-restart skill v1.0.0 - Introduces automated Gateway restart with session recovery. - Sets a temporary cron job to self-wake the main session after restart, resuming tasks automatically. - Provides both API and CLI invocation options, with customizable task and delay. - Ensures only this skill (not direct exec commands) is used for Gateway restarts, maintaining session continuity. - Includes guidance and examples for correct usage and integration into existing workflows.
Metadata
Slug graceful-restart
Version 1.0.4
License
All-time Installs 8
Active Installs 8
Total Versions 5
Frequently Asked Questions

What is 优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart?

优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。依赖 openclaw CLI。触发词:重启、restart。 It is an AI Agent Skill for Claude Code / OpenClaw, with 728 downloads so far.

How do I install 优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart?

Run "/install graceful-restart" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is 优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart free?

Yes, 优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart is completely free (open-source). You can download, install and use it at no cost.

Which platforms does 优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart support?

优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created 优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart?

It is built and maintained by scotthuang (@scotthuang); the current version is v1.0.4.

💬 Comments