← 返回 Skills 市场
scotthuang

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

作者 scotthuang · GitHub ↗ · v1.0.4
cross-platform ✓ 安全检测通过
728
总下载
0
收藏
8
当前安装
5
版本数
在 OpenClaw 中安装
/install graceful-restart
功能描述
优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。依赖 openclaw CLI。触发词:重启、restart。
使用说明 (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  # 禁止!

这样写

安全使用建议
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.
功能分析
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.
能力评估
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.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install graceful-restart
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /graceful-restart 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
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.
元数据
Slug graceful-restart
版本 1.0.4
许可证
累计安装 8
当前安装数 8
历史版本数 5
常见问题

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

优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。依赖 openclaw CLI。触发词:重启、restart。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 728 次。

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

在 OpenClaw 或 Claude Code 对话框中运行命令「/install graceful-restart」即可一键安装,无需额外配置。

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

是的,优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart 完全免费(开源免费),可自由下载、安装和使用。

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

优雅重启 Gateway。解决重启后丢失会话上下文的问题,重启前设置一次性 cron 任务,重启后自动发送消息到主会话恢复任务。默认 10 秒后唤醒。触发词:重启、restart 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

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

由 scotthuang(@scotthuang)开发并维护,当前版本 v1.0.4。

💬 留言讨论