{"id":"2ca0a168-25ad-4adf-a0e5-82533a15a6f9","slug":"unattended-task-pitfalls","kind":"skill","name":"unattended-task-pitfalls","summary":"Hardening playbook for AI agent unattended/scheduled tasks · 无人值守自动任务加固经验库","owner":"mowenQWQ","repoUrl":"https://github.com/mowenQWQ/unattended-task-pitfalls","license":"MIT","licenseTier":"permissive","trust":"community","stars":0,"match":null,"fewStars":true,"format":"skill","createdAt":"2026-09-03T17:11:48.000Z","addedAt":"2026-10-21T12:59:01.932Z","logoUrl":"https://avatars.githubusercontent.com/u/189590306?u=c0a06d086b26c9ca7c1a1dce5fd495672d296df8&v=4","linkOnly":false,"collection":null,"skillPath":null,"categories":["productivity"],"tags":["ai-agent","automation","cron","reliability","cherry-studio","scheduled-tasks"],"runtime":"binary","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-28T03:33:56.482Z","sample":false,"url":"https://conduits.dev/tools/unattended-task-pitfalls","language":"Python","transports":["stdio"],"install":{},"requirements":{"env":[],"upstreamMayCharge":false},"tools":null,"readme":"# unattended-task-pitfalls\n\n**无人值守自动任务加固经验库——\"操作纪律会失效，只有代码能兜底\"。来自两次备份损坏事故 + 一次 504 杀进程事故 + cron 总结误判事故的完整复盘。**\n\n**A hardening playbook for AI-agent unattended/scheduled tasks — \"operational discipline fails unattended; only code has your back.\" Distilled from two backup-corruption incidents, a 504 process-kill incident, and a cron summarization misjudgment.**\n\n[中文](#中文) | [English](#english)\n\n> ⚠️ **AI 使用说明**：本作品使用 AI 辅助生成（生成时间：2026-09-03）。仅供学习与参考使用，发布、引用或投入使用前请人工核实关键信息。\n\n---\n\n## 中文\n\n### 这是什么\n\n一个 AI agent 工作区的真实事故复盘（2026-08 ~ 09）：\n\n- **08-27**：定时备份产出损坏文件并上传云端，教训\"gzip -t 验证后才能上传\"被记入长期记忆\n- **08-30**：同款事故**复发**——因为 cron 会话根本读不到\"操作纪律\"，纪律只对在线的 agent 有效。528MB 截断坏文件再次上传（正常 911MB）\n- **08-24/25**：cron 总结任务在隔离会话里误判\"全天无对话\"（它看不到主会话上下文）\n- **09-05**：cron 提示词里的**裸命令**被执行会话照抄前台运行，第三次被网关杀进程——但这次恢复侧零失误（先查进程再重跑，锁自动释放，验证闸门自动拦截残缺包）。新教训：**prompt 既是纪律载体，也是风险载体**\n\n由此提炼出本库的核心命题：**无人值守链路里，操作纪律会失效，只有代码能兜底。**\n\n### 内容结构\n\n| 章节 | 解决什么 |\n|------|---------|\n| §1 核心哲学 | 为什么\"记忆型教训\"在无人值守场景必然失效，教训落点分级（脚本内 > prompt > 记忆） |\n| §2 后台执行 | 前台跑被网关杀、\"504 ≠ 命令未执行\"（盲目重试 = 并发实例互踩）、锁与幂等、**prompt 内嵌命令的安全形态** |\n| §3 验证链 | 产物完整性验证（`gzip -t`）、\"验证不过绝不上传\"闸门、\"已存在跳过\"复用坏文件坑 |\n| §4 隔离会话 | cron 会话的上下文盲区、\"无对话/静默\"结论的证据法（含会话初始化产物的排除清单） |\n| §5 通知设计 | cron 无条件通知 vs 心跳条件通知、自动任务输出禁用拟人内容、静默档防通知疲劳 |\n| §6 交叉验证 | 自动任务的产物也要被自动检查（发现 08-30 事故的唯一渠道）、一次性任务自删、失败的默认出口 |\n\n### 核心原则速览\n\n1. 凡无人值守的纪律，**一次性落到代码与 prompt**（锁、验证闸门、复查脚本），不要指望 agent\"想起来\"\n2. **prompt 里内嵌的长命令要直接写成安全形态**（`setsid nohup ... &` 全格式），不指望执行者\"记得加壳\"\n3. 单一任务的自我报告不可信——给关键产物配**独立验证路径**\n4. 网关/管道类超时 ≠ 命令未执行，**先查进程再决定重试**\n5. 失败的默认出口 = 记录日志 + 通知用户 + 保留现场，不在失败路径上做主观决策\n\n### 适合谁\n\n- 给 AI agent（Claude Code / OpenClaw / 自建 agent）搭建 cron / 定时备份 / 自动报告的人\n- 遇到过\"任务失败但报告成功\"、\"备份文件损坏\"、\"定时总结瞎编\"的人\n- 设计多任务自动化体系、需要通知与静默策略的人\n\n### 安装\n\n```bash\ngit clone https://github.com/mowenQWQ/unattended-task-pitfalls.git\ncp -r unattended-task-pitfalls /path/to/your/agent/skills/\n```\n\n`scripts/` 内含产物验证脚本模板（`verify_archive.py`），可直接适配到你的备份任务。\n\n### 更多技能库\n\n| 仓库 | 简介 |\n|------|------|\n| [win-dev-pitfalls](https://github.com/mowenQWQ/win-dev-pitfalls) | Windows 开发踩坑全量主线 |\n| [bat-ps1-dev](https://github.com/mowenQWQ/bat-ps1-dev) | bat/PowerShell 脚本开发专项经验库 |\n| [Web-Security-Test-Rules](https://github.com/mowenQWQ/Web-Security-Test-Rules) | 已授权网站安全测试规则库 |\n| [agent-mistake-patterns](https://github.com/mowenQWQ/agent-mistake-patterns) | AI 智能体犯错模式库与自我纠错纪律 |\n| [grounded-summaries-skill](https://github.com/mowenQWQ/grounded-summaries-skill) | 防止 AI 在总结任务中编造内容 |\n\n---\n\n## English\n\n### What is this\n\nA post-mortem from a real AI-agent workspace (Aug–Sep 2026):\n\n- **08-27**: a scheduled backup uploaded a corrupted archive; the lesson (\"verify with `gzip -t` before upload\") was stored in long-term memory\n- **08-30**: the **same incident recurred** — because cron sessions never read \"operational discipline\"; discipline only binds an online agent. Another truncated 528MB file (expected: 911MB) went upstream\n- **08-24/25**: a cron summarization task in an isolated session misjudged \"no conversations today\" (it cannot see the main session's context)\n- **09-05**: a **bare command** embedded in the cron prompt was copy-pasted and run in the foreground; the gateway killed the process for the third time — but recovery was flawless this time (check process → rerun in background; lock auto-released; verification gate auto-rejected the truncated artifact). New lesson: **a prompt is both a discipline carrier and a risk carrier**\n\nThe core thesis: **in unattended pipelines, operational discipline fails — only code has your back.**\n\n### Structure\n\n| Section | Covers |\n|---------|--------|\n| §1 Core philosophy | Why \"memory-stored lessons\" inevitably fail unattended; lesson-placement tiers (in-script > prompt > memory) |\n| §2 Background execution | Gateway-killed foreground runs, \"504 ≠ not executed\" (blind retries = concurrent instances racing), locks & idempotency, **safe form for commands embedded in prompts** |\n| §3 Verification chain | Artifact integrity (`gzip -t`), \"never upload without verification\" gates, the \"skip if exists\" reuse-of-corrupt-file trap |\n| §4 Isolated sessions | Cron context blindness; evidence-based \"no activity\" conclusions (with init-artifact exclusion list) |\n| §5 Notification design | Unconditional cron vs conditional heartbeat notifications; no anthropomorphic filler in automated output; silence tiers |\n| §6 Cross-verification | Automated artifacts deserve automated checks; one-shot task self-deletion; default failure exits |\n\n### Quick principles\n\n1. Move every unattended discipline **into code and prompts once** (locks, verification gates, review scripts) — don't count on the agent \"remembering\"\n2. **Embed long commands in prompts in their safe form** (`setsid nohup ... &` full format) — don't count on the executor \"remembering to wrap it\"\n3. Never trust a task's self-report — give critical artifacts an **independent verification path**\n4. Gateway/pipeline timeouts ≠ command not executed — **check the process before retrying**\n5. Default failure exit = log + notify + preserve the scene; make no subjective decisions on the failure path\n\n### Installation\n\n```bash\ngit clone https://github.com/mowenQWQ/unattended-task-pitfalls.git\ncp -r unattended-task-pitfalls /path/to/your/agent/skills/\n```\n\n`scripts/` includes a reusable artifact-verification template (`verify_archive.py`).\n\n---\n\n## License\n\nMIT\n"}