ln-629-lifecycle-auditor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Lifecycle Auditor (L3 Worker)

生命周期审计Worker(L3 Worker)

Specialized worker auditing application lifecycle and entry points.
专门用于审计应用生命周期和入口点的Worker。

Purpose & Scope

用途与范围

  • Worker in ln-620 coordinator pipeline
  • Audit lifecycle (Category 12: Medium Priority)
  • Check bootstrap, shutdown, signal handling, probes
  • Calculate compliance score (X/10)
  • ln-620协调器流水线中的Worker
  • 审计生命周期(类别12:中等优先级)
  • 检查启动、关闭、信号处理、探针
  • 计算合规分数(X/10)

Inputs (from Coordinator)

输入(来自协调器)

Receives
contextStore
with tech stack, deployment type, codebase root.
接收包含技术栈、部署类型、代码库根目录的
contextStore

Workflow

工作流程

  1. Parse context
  2. Check lifecycle patterns
  3. Collect findings
  4. Calculate score
  5. Return JSON
  1. 解析上下文
  2. 检查生命周期模式
  3. 收集检测结果
  4. 计算分数
  5. 返回JSON

Audit Rules

审计规则

1. Bootstrap Initialization Order

1. 启动初始化顺序

Detection:
  • Check main/index file for initialization sequence
  • Verify dependencies loaded before usage (DB before routes)
Severity:
  • HIGH: Incorrect order causes startup failures
Recommendation: Initialize in correct order: config → DB → routes → server
Effort: M (refactor startup)
检测方式:
  • 检查main/index文件中的初始化序列
  • 验证依赖项在使用前已加载(数据库在路由之前)
严重程度:
  • 高: 错误的顺序会导致启动失败
建议: 按正确顺序初始化:配置 → 数据库 → 路由 → 服务器
修复工作量: M(重构启动逻辑)

2. Graceful Shutdown

2. 优雅关闭

Detection:
  • Grep for
    SIGTERM
    ,
    SIGINT
    handlers
  • Check
    process.on('SIGTERM')
    (Node.js)
  • Check
    signal.Notify
    (Go)
Severity:
  • HIGH: No shutdown handler (abrupt termination)
Recommendation: Add SIGTERM handler, close connections gracefully
Effort: M (add shutdown logic)
检测方式:
  • 搜索
    SIGTERM
    SIGINT
    处理器
  • 检查
    process.on('SIGTERM')
    (Node.js)
  • 检查
    signal.Notify
    (Go)
严重程度:
  • 高: 无关闭处理器(突然终止)
建议: 添加SIGTERM处理器,优雅关闭连接
修复工作量: M(添加关闭逻辑)

3. Resource Cleanup on Exit

3. 退出时的资源清理

Detection:
  • Check if DB connections closed on shutdown
  • Verify file handles released
  • Check worker threads stopped
Severity:
  • MEDIUM: Resource leaks on shutdown
Recommendation: Close all resources in shutdown handler
Effort: S-M (add cleanup calls)
检测方式:
  • 检查关闭时是否已关闭数据库连接
  • 验证文件句柄已释放
  • 检查工作线程已停止
严重程度:
  • 中: 关闭时存在资源泄漏
建议: 在关闭处理器中关闭所有资源
修复工作量: S-M(添加清理调用)

4. Signal Handling

4. 信号处理

Detection:
  • Check handlers for SIGTERM, SIGINT, SIGHUP
  • Verify proper signal propagation to child processes
Severity:
  • MEDIUM: Missing signal handlers
Recommendation: Handle all standard signals
Effort: S (add signal handlers)
检测方式:
  • 检查SIGTERM、SIGINT、SIGHUP的处理器
  • 验证信号已正确传播到子进程
严重程度:
  • 中: 缺少信号处理器
建议: 处理所有标准信号
修复工作量: S(添加信号处理器)

5. Liveness/Readiness Probes

5. 存活/就绪探针

Detection (for containerized apps):
  • Check for
    /live
    ,
    /ready
    endpoints
  • Verify Kubernetes probe configuration
Severity:
  • MEDIUM: No probes (Kubernetes can't detect health)
Recommendation: Add
/live
(is running) and
/ready
(ready for traffic)
Effort: S (add endpoints)
检测方式(针对容器化应用):
  • 检查是否存在
    /live
    /ready
    端点
  • 验证Kubernetes探针配置
严重程度:
  • 中: 无探针(Kubernetes无法检测健康状态)
建议: 添加
/live
(是否正在运行)和
/ready
(是否准备好接收流量)端点
修复工作量: S(添加端点)

Scoring Algorithm

评分算法

See
shared/references/audit_scoring.md
for unified formula and score interpretation.
统一公式和分数解释请参见
shared/references/audit_scoring.md

Output Format

输出格式

json
{
  "category": "Lifecycle",
  "score": 7,
  "total_issues": 4,
  "critical": 0,
  "high": 1,
  "medium": 3,
  "low": 0,
  "checks": [
    {"id": "bootstrap_order", "name": "Bootstrap Order", "status": "passed", "details": "Initialization sequence correct: config -> DB -> routes -> server"},
    {"id": "graceful_shutdown", "name": "Graceful Shutdown", "status": "failed", "details": "No SIGTERM handler found"},
    {"id": "resource_cleanup", "name": "Resource Cleanup", "status": "warning", "details": "DB connection closed, but file handles not released"},
    {"id": "signal_handling", "name": "Signal Handling", "status": "warning", "details": "SIGINT handled, SIGTERM missing"},
    {"id": "probes", "name": "Liveness/Readiness Probes", "status": "passed", "details": "/health and /ready endpoints present"}
  ],
  "findings": [
    {
      "severity": "HIGH",
      "location": "src/index.ts:1-50",
      "issue": "No SIGTERM handler for graceful shutdown",
      "principle": "Graceful Shutdown / Resource Management",
      "recommendation": "Add SIGTERM handler to close DB connections and server gracefully",
      "effort": "M"
    }
  ]
}
json
{
  "category": "Lifecycle",
  "score": 7,
  "total_issues": 4,
  "critical": 0,
  "high": 1,
  "medium": 3,
  "low": 0,
  "checks": [
    {"id": "bootstrap_order", "name": "Bootstrap Order", "status": "passed", "details": "Initialization sequence correct: config -> DB -> routes -> server"},
    {"id": "graceful_shutdown", "name": "Graceful Shutdown", "status": "failed", "details": "No SIGTERM handler found"},
    {"id": "resource_cleanup", "name": "Resource Cleanup", "status": "warning", "details": "DB connection closed, but file handles not released"},
    {"id": "signal_handling", "name": "Signal Handling", "status": "warning", "details": "SIGINT handled, SIGTERM missing"},
    {"id": "probes", "name": "Liveness/Readiness Probes", "status": "passed", "details": "/health and /ready endpoints present"}
  ],
  "findings": [
    {
      "severity": "HIGH",
      "location": "src/index.ts:1-50",
      "issue": "No SIGTERM handler for graceful shutdown",
      "principle": "Graceful Shutdown / Resource Management",
      "recommendation": "Add SIGTERM handler to close DB connections and server gracefully",
      "effort": "M"
    }
  ]
}

Reference Files

参考文件

  • Audit scoring formula:
    shared/references/audit_scoring.md
  • Audit output schema:
    shared/references/audit_output_schema.md

Version: 3.0.0 Last Updated: 2025-12-23
  • 审计评分公式:
    shared/references/audit_scoring.md
  • 审计输出 schema:
    shared/references/audit_output_schema.md

版本: 3.0.0 最后更新: 2025-12-23