Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add cass-2003/local-workflow-skill --skill graceful-shutdowngit clone --depth 1 https://github.com/cass-2003/local-workflow-skillWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/cass-2003/local-workflow-skill/graceful-shutdown)<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/graceful-shutdown"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/graceful-shutdown/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/graceful-shutdown"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/graceful-shutdown.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00132 | $0.02848 |
| Opus 5.5 | $0.00053 | $0.01139 |
| Sonnet 5.5 | $0.00026 | $0.00570 |
| Haiku 4.5 | $0.00013 | $0.00285 |
Grade A, and why
graceful-shutdown scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 324 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Graceful Shutdown Skill — 优雅停机
何时使用
- 部署滚动更新时用户看到 502 / 连接重置
- 排查"deploy 后丢了几条请求 / 队列消息"
- 设计长连接服务(WebSocket / SSE / gRPC streaming)的发布
- 数据库 / 缓存连接没正确关闭,连接数堆积
- Kubernetes 滚动 deploy 配 preStop / terminationGracePeriodSeconds
一、为什么需要优雅停机
[时刻 T] K8s 收到 deploy 命令
[T+0ms] 新 Pod 创建
[T+xms] 新 Pod ready → Service endpoint 加入新 IP
[T+xms] Service endpoint 移除旧 IP(异步!可能延迟)
[T+xms] 旧 Pod 收到 SIGTERM
[T+30s] grace period 默认 30s 后 SIGKILL
两个并发问题:
- endpoint 摘流延迟:旧 Pod 收到 SIGTERM 但 LB 还在发流量进来 → 502 / 连接重置
- in-flight 请求:旧 Pod 处理中的请求还没完成就被 kill → 数据不一致 / 客户端 retry
二、停机六步标准流程
1. 收到 SIGTERM
2. 标记 health check 为 unhealthy → LB / Service 摘流
3. 等若干秒(让 LB / DNS / kube-proxy 真正生效)
4. 关闭 HTTP listener(不接新连接)
5. 等待所有 in-flight 请求完成(带 timeout)
6. 关闭依赖(DB pool / Redis / message queue / OTel exporter flush)
7. 进程退出
三、Go 标准实现
func main() {
srv := &http.Server{Addr: ":8080", Handler: router}
go srv.ListenAndServe()
// 1. 等信号
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGTERM, syscall.SIGINT)
<-quit
log.Info("shutdown signal received")
// 2. 标记 unhealthy(让 LB 摘流)
healthState.Store(false)
time.Sleep(5 * time.Second) // 等 LB 摘流(K8s readiness 周期 + 误差)
// 3-4-5. 关闭 HTTP(带超时;server.Shutdown 等 in-flight 完成)
ctx, cancel := context.WithTimeout(context.Background(), 25*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
log.Error("forced shutdown", "err", err)
}
// 6. 关依赖
db.Close()
redis.Close()
tracerProvider.Shutdown(context.Background()) // flush spans
log.Info("shutdown complete")
}
四、Node.js (Express / Fastify)
const server = app.listen(8080)
let shuttingDown = false
// healthcheck 路由
app.get('/healthz', (req, res) => {
res.status(shuttingDown ? 503 : 200).json({ ok: !shuttingDown })
})
async function shutdown() {
if (shuttingDown) return
shuttingDown = true
console.log('SIGTERM received, shutting down')
// 1. 等 LB 摘流
await sleep(5000)
// 2. 关 listener
await new Promise<void>((resolve) => {
server.close((err) => err ? console.error(err) : resolve())
// server.close 等所有 keep-alive 连接关闭
// 强制关 keep-alive:server.closeIdleConnections() (Node 18+)
server.closeIdleConnections?.()
})
// 3. 等 in-flight(自家计数器或外部 inflight 中间件)
await waitForInflightToFinish(20_000)
// 4. 关依赖
await db.end()
await redis.quit()
await otelSdk.shutdown()
process.exit(0)
}
process.on('SIGTERM', shutdown)
process.on('SIGINT', shutdown)
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 3mo ago First seen · 324 lines · 132 tokens per session scan A 0e547ed3aea3
graceful-shutdown is a skill published in the GitHub repository cass-2003/local-workflow-skill (12 stars, last pushed 4mo ago), licensed MIT. It adds 132 tokens to every session and 2,848 once invoked, about $0.0005 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
graceful-shutdown compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| graceful-shutdowncass-2003/local-workflow-skill | Skill | 12 | 4mo ago | MIT | A | 132 | Claude Code, Codex |
| local-ai-agentsmicrosoft/ai-agents-for-beginners | Skill | 82k | today | MIT | A | 200 | Claude Code, Codex |
| imagegenopenai/codex | Skill | 137k | today | Apache-2.0 | A | 113 | Codex |
| playwright-climicrosoft/playwright | Skill | 102k | today | Apache-2.0 | A | 19 | Claude Code |
| browser-automationopenclaw/openclaw | Skill | 396k | today | MIT | A | 36 | Claude Code |
| free-llm-apismnfst/awesome-free-llm-apis | Skill | 15k | today | CC0-1.0 | A | 113 | Claude Code, Codex |
| systematic-debuggingobra/superpowers | Skill | 332k | 6d ago | MIT | A | 21 | Claude Code |