返回顶部
e

error-recovery-automation错误恢复自动化

Standardize handling of common OpenClaw errors (gateway restart, browser service unavailable, cron failures) with automated recovery steps. Use when you need to automate detection and recovery from known failure modes, reducing manual intervention and increasing system resilience.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
945
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

error-recovery-automation

错误恢复自动化技能

本技能提供自动化检测和恢复常见OpenClaw错误的模式:网关无响应、浏览器服务故障、cron调度器问题以及其他重复出现的问题。它在健康监控和系统诊断的基础上,通过添加自动化恢复工作流来增强功能,这些工作流可由cron作业、心跳检查或外部监控触发。

何时使用

  • - 某个服务(网关、浏览器、cron)间歇性故障,您希望自动重启它。
  • 您正在设置主动监控,并且需要超出单纯检测范围的恢复计划。
  • 您希望减少当“一切正常吗?”显示故障时所需的手动步骤。
  • 您需要确保关键OpenClaw组件以最少用户干预持续运行。
  • 您被要求“创建一个错误恢复自动化技能”(这就是该技能)。

核心模式

1. 错误检测模式

在自动化恢复之前,必须可靠地检测错误。使用以下检测方法:

网关无响应:

  • - openclaw gateway status 返回非零退出码或显示 running: false。
  • 网关日志(~/.openclaw/logs/gateway.err.log)包含最近的 CRITICAL 或 ERROR 条目。
  • HTTP健康端点(如果已配置)返回非2xx状态。

浏览器服务不可用:

  • - openclaw browser --browser-profile openclaw status --json 显示 running: false 或CDP未就绪。
  • 浏览器日志包含连接超时或Chrome进程失败。
  • 通过 curl 到CDP端点的简单页面加载失败。

Cron调度器未运行:

  • - openclaw cron status 返回 running: false 或错误。
  • Cron日志显示最近没有活动。
  • 计划任务未被触发(检查 openclaw cron list 是否有遗漏运行)。

内存搜索禁用:

  • - memory_search 工具返回“已禁用”或原生模块错误。
  • openclaw doctor --fix 报告better-sqlite3不匹配。

权限错误:

  • - 文件操作失败,返回 EACCES/EPERM。
  • 日志显示特定路径(存档、日志、配置)权限被拒绝。

2. 自动化恢复步骤

对于每种错误类型,定义一个尝试自动恢复服务的恢复脚本。脚本应:

  1. 1. 检测错误(使用上述模式)。
  2. 尝试恢复(重启服务、修复权限、重建模块)。
  3. 验证恢复(短暂等待后重新运行检测)。
  4. 报告结果(成功退出码0,持续失败非零)。

网关恢复脚本模板

bash
#!/bin/bash
set -e

SERVICE=gateway
MAX_ATTEMPTS=2
SLEEP_SECONDS=5

log() { echo [$(date +%Y-%m-%d %H:%M:%S)] $*; }

check() {
openclaw gateway status > /dev/null 2>&1
}

restart() {
openclaw gateway restart
sleep $SLEEP_SECONDS
}

attempt=0
while [ $attempt -lt $MAX_ATTEMPTS ]; do
if check; then
log $SERVICE is healthy
exit 0
fi
log $SERVICE is unhealthy, restarting (attempt $((attempt+1))/$MAX_ATTEMPTS)...
restart
((attempt++))
done

log $SERVICE could not be recovered after $MAX_ATTEMPTS attempts
exit 1

浏览器服务恢复脚本模板

bash
#!/bin/bash
set -e

SERVICE=browser
PROFILE=openclaw
MAX_ATTEMPTS=2
SLEEP_SECONDS=8

log() { echo [$(date +%Y-%m-%d %H:%M:%S)] $*; }

check() {
openclaw browser --browser-profile $PROFILE status --json 2>&1 | grep -q running:true
}

restart() {
openclaw browser --browser-profile $PROFILE stop
sleep 2
openclaw browser --browser-profile $PROFILE start
sleep $SLEEP_SECONDS
}

attempt=0
while [ $attempt -lt $MAX_ATTEMPTS ]; do
if check; then
log $SERVICE ($PROFILE) is healthy
exit 0
fi
log $SERVICE ($PROFILE) is unhealthy, restarting (attempt $((attempt+1))/$MAX_ATTEMPTS)...
restart
((attempt++))
done

log $SERVICE ($PROFILE) could not be recovered after $MAX_ATTEMPTS attempts
exit 1

Cron调度器恢复脚本模板

bash
#!/bin/bash
set -e

SERVICE=cron
MAX_ATTEMPTS=1
SLEEP_SECONDS=3

log() { echo [$(date +%Y-%m-%d %H:%M:%S)] $*; }

check() {
openclaw cron status 2>&1 | grep -q running:true
}

restart() {
# Cron在网关重启时自动重启。
# 如果cron未运行,重启网关。
openclaw gateway restart
sleep $SLEEP_SECONDS
}

attempt=0
while [ $attempt -lt $MAX_ATTEMPTS ]; do
if check; then
log $SERVICE scheduler is running
exit 0
fi
log $SERVICE scheduler is not running, restarting gateway (attempt $((attempt+1))/$MAX_ATTEMPTS)...
restart
((attempt++))
done

log $SERVICE scheduler still not running after $MAX_ATTEMPTS attempts
exit 1

内存搜索恢复脚本模板

bash
#!/bin/bash
set -e

SERVICE=memory_search
MAX_ATTEMPTS=1

log() { echo [$(date +%Y-%m-%d %H:%M:%S)] $*; }

check() {
openclaw memory search --query test 2>&1 | grep -q -v disabled\|Module did not self-register
}

restart() {
# 尝试重建better-sqlite3
cd $(dirname $(which openclaw))/../lib/node_modules/openclaw
npm rebuild better-sqlite3
# 重启网关以加载重建的模块
openclaw gateway restart
sleep 5
}

attempt=0
while [ $attempt -lt $MAX_ATTEMPTS ]; do
if check; then
log $SERVICE is functional
exit 0
fi
log $SERVICE is disabled, rebuilding native module (attempt $((attempt+1))/$MAX_ATTEMPTS)...
restart
((attempt++))
done

log $SERVICE could not be recovered after $MAX_ATTEMPTS attempts
exit 1

3. 与Cron集成实现自动化恢复

一旦有了恢复脚本,将其安排为cron作业,仅在服务可能失败时运行(例如,浏览器每30分钟,网关每小时)。使用隔离的代理会话执行脚本并宣布失败。

浏览器恢复的cron作业示例:

bash
openclaw cron add \
--name Browser‑Recovery‑Automation \
--schedule every 30 minutes \
--session isolated \
--payload {kind:agentTurn,message:Run browser recovery automation script,model:default,thinking:low} \
--delivery {mode:announce,channel:telegram}

隔离会话中的代理响应: 代理读取脚本(或内联逻辑)并通过 exec 执行。如果脚本退出码为0,代理宣布成功;如果非零,cron传递转发失败消息。

替代方案: 为简单起见,您可以将恢复逻辑直接嵌入代理的响应中(无需单独的脚本),但脚本更易于测试和重用。

4. 自动化失败时的升级处理

如果自动化恢复在最大尝试次数后失败,进行升级:

  • - 记录失败到 memory/YYYY‑MM‑DD.md,标签为 error‑recovery‑failed。
  • 添加任务到 inbox/agent‑aufgaben.md 进行手动诊断。
  • 发送高优先级通知(如果支持)给用户。
  • 回退到安全状态(例如,如果可能,禁用有问题的组件)。

升级代码片段示例:

bash
if [ $? -ne 0 ]; then
echo Browser recovery failed. Adding manual diagnosis task.
# 追加到agent-aufgaben.md
echo | 99 | Diagnose browser recovery failure – automated recovery failed after 2 attempts | ⬜ | >> inbox/agent-aufgaben.md
# 存储到memory
echo ## [error] Browser recovery automation failed >> memory/$(date +%Y-%m-%d).md
echo Date

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 error-recovery-automation-1776420021 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 error-recovery-automation-1776420021 技能

通过命令行安装

skillhub install error-recovery-automation-1776420021

下载

⬇ 下载 error-recovery-automation v1.0.0(免费)

文件大小: 4.8 KB | 发布时间: 2026-4-17 18:50

v1.0.0 最新 2026-4-17 18:50
Initial release of the Error Recovery Automation skill for OpenClaw:

- Standardizes detection and automated recovery steps for common errors (gateway, browser, cron, memory search, and permissions).
- Provides concrete detection patterns and ready-to-use bash script templates for each error type.
- Details how to integrate recovery automation with cron jobs and agent sessions.
- Describes clear escalation procedures when automation fails, including logging and task assignment.
- Designed to minimize manual intervention and ensure system resilience.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部