ai-debt-detector

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AI Debt Detector

AI Debt Detector

Overview

概述

AI agents generate code that passes the happy path but hides debt: missing error handling, orphaned resources, ignored failure modes, hallucinated packages, silent architectural drift. This skill forces a targeted audit for the exact patterns AI agents get wrong.
AI Agent生成的代码能通过正常流程测试,但会隐藏技术债务:缺失错误处理、孤立资源、忽略故障模式、虚构依赖包、无感知的架构偏移。本技能针对AI Agent容易出错的特定模式进行定向审计。

When to Use

适用场景

  • After any AI code generation session (20+ lines produced)
  • Before merging AI-generated PRs
  • When code works but something feels off
  • After vibe-coding sprints where debt accumulates fastest
  • When the agent claims done without showing verification
  • 任何AI代码生成会话后(生成代码超过20行)
  • 合并AI生成的PR之前
  • 代码能运行但感觉存在问题时
  • 在快速编码导致技术债务快速累积的阶段之后
  • AI Agent声称任务完成但未提供验证依据时

Process

审计流程

After code generation, scan for these AI-specific debt patterns:
  1. FAILURE MODES - What happens when this fails?
    • Network timeout? Disk full? Permission denied? Null input?
    • Is there a try/catch? Does it catch SPECIFIC errors or swallow everything?
    • Are resources cleaned up on failure? (streams closed, connections returned, temp files deleted)
  2. ORPHANS - What gets created but never cleaned up?
    • Temp files, event listeners, intervals, subscriptions, connections
    • Are there corresponding cleanup/dispose/close calls for every open/create?
    • In React: does every addEventListener have a removeEventListener in cleanup?
  3. EDGE CASES - What inputs break this?
    • Empty array/string? null/undefined? Multi-MB input? Unicode? Concurrent calls?
    • Does the code assume the happy path? (AI almost always does)
  4. HALLUCINATED DEPS - Do all imports actually exist?
    • Is every package in package.json/requirements.txt?
    • Are API methods real? (AI invents plausible-sounding methods that don't exist)
    • Does this library's latest version still export this function?
  5. ARCHITECTURAL DRIFT - Does this match the project's patterns?
    • Same error handling style as existing code?
    • Uses the project's established utilities (not reinventing)?
    • Follows the file structure convention?
代码生成完成后,扫描以下AI特有的技术债务模式:
  1. 故障模式 - 代码失败时会发生什么?
    • 网络超时?磁盘已满?权限被拒绝?输入为空?
    • 是否有try/catch语句?它是捕获特定错误还是吞掉所有错误?
    • 故障发生时资源是否被清理?(流已关闭、连接已归还、临时文件已删除)
  2. 孤立资源 - 哪些资源被创建后从未被清理?
    • 临时文件、事件监听器、定时器、订阅、连接
    • 每个打开/创建的资源是否有对应的清理/释放/关闭调用?
    • 在React中:每个addEventListener是否在清理阶段对应removeEventListener?
  3. 边缘情况 - 哪些输入会导致代码崩溃?
    • 空数组/字符串?null/undefined?多MB级输入?Unicode字符?并发调用?
    • 代码是否只假设正常流程?(AI几乎总是这样)
  4. 虚构依赖 - 所有导入的依赖是否真实存在?
    • 每个包都在package.json/requirements.txt中吗?
    • API方法是否真实存在?(AI会编造听起来合理但实际不存在的方法)
    • 该库的最新版本是否仍导出此函数?
  5. 架构偏移 - 代码是否符合项目的模式?
    • 与现有代码的错误处理风格一致吗?
    • 使用项目已有的工具函数(而非重复造轮子)?
    • 遵循文件结构规范吗?

Red Flags (stop and fix immediately)

危险信号(立即停止并修复)

  • catch (e) {}
    or
    catch (e) { console.log(e) }
    - swallowed error
  • No
    finally
    block when resources were opened
  • // TODO: handle error
    - AI's way of punting
  • Import from a path that doesn't exist in the project
  • Timeout set but no abort/cleanup on timeout
  • Database connection opened but never released back to pool
  • catch (e) {}
    catch (e) { console.log(e) }
    - 错误被吞掉
  • 打开资源后没有
    finally
  • // TODO: handle error
    - AI用来逃避问题的方式
  • 从项目中不存在的路径导入
  • 设置了超时但超时后没有终止/清理操作
  • 数据库连接已打开但从未放回连接池

Common Mistakes

常见误区

  • Trusting that compilation means correctness (compilation checks syntax, not logic)
  • Reviewing only the diff without checking what the AI did NOT generate (missing error paths)
  • Assuming the AI used the right library version (it often uses deprecated APIs)
  • Skipping the orphan check because garbage collection handles it (it doesn't for connections, listeners, timers)
  • 认为编译通过就代表代码正确(编译仅检查语法,不检查逻辑)
  • 仅审查代码差异,未检查AI未生成的内容(缺失的错误处理路径)
  • 假设AI使用了正确的库版本(它经常使用已废弃的API)
  • 跳过孤立资源检查,认为垃圾回收会处理(但垃圾回收无法处理连接、监听器、定时器)

Why This Exists

设计初衷

AI agents systematically optimize for "looks correct" and "passes the happy path." They miss failure modes, orphan resources, and hallucinate dependencies at rates significantly higher than manual code. This skill forces an audit for those specific blind spots.
AI Agent会系统性地优化代码,使其'看起来正确'并'通过正常流程测试'。它们遗漏故障模式、留下孤立资源、虚构依赖的概率远高于人工编写的代码。本技能针对这些特定的盲区进行强制审计。