Skip to content

packages/runtime/src/security/rate-limit.ts 零调用点,且注释断言了两个不存在的东西(429 短路 / DispatcherPluginConfig.rateLimit) #4937

Description

@xuyushun441-sys

#4910 开工核查中发现,记录备查,未认领。基线 origin/main @ 2e284b2546

事实

RateLimiter 是一个写得很干净、单测很完整的 in-memory token bucket。它从未被任何生产代码实例化:

$ grep -rn "new RateLimiter(" --include=*.ts --include=*.mjs --include=*.js . | grep -v node_modules | grep -v /dist/
packages/runtime/src/security/rate-limit.test.ts:23,39,54,65,77,86,97,98 ← 全部是它自己的单测
(无其它命中)
# 阳性对照,证明扫描器有效:
$ grep -rn "new DomainHandlerRegistry(" --include=*.ts . | grep -v node_modules
packages/runtime/src/http-dispatcher.ts:167 ← 真实调用点找得到

DEFAULT_RATE_LIMITS 同样只有单测 + barrel 导出两类命中。全仓入站路径没有任何 429 短路:

$ grep -rn "429" --include=*.ts packages/runtime/src packages/adapters packages/rest/src packages/core/src | grep -v .test.
packages/runtime/src/security/rate-limit.ts:8 ← 注释里的那句话本身
packages/rest/src/rest-server.ts:6897 ← [/^THROTTLED/, 429, 'THROTTLED'] 错误码映射,与本限流器无关

defect:注释断言的两件事都不存在

文件头和 DEFAULT_RATE_LIMITS 上方的注释写着:

  • rate-limit.ts:8 — 「the dispatcher calls consume(key) … and short-circuits with 429 if the bucket is empty」 —— 没有任何 dispatcher 调用 consume
  • rate-limit.ts:153 — 「Conservative — tune via DispatcherPluginConfig.rateLimit for your deployment」 —— DispatcherPluginConfig(dispatcher-plugin.ts:23)没有 rateLimit 字段
  • rate-limit.ts:157-163 — 「the dispatcher constructs the key from ${ip}:${bucket}」 —— 没有任何代码构造这个 key。

这不是「注释过期」这种无害漂移:它是用现在时描述一条不存在的执行链,而 #4686 的立单事实(「一个真正在干活的 token bucket,服务入站 dispatcher 的 429 短路」)与 #4910 的整个拆向裁决,正是建立在读到这段注释之上的。一段自称已接线的注释,让两张单据把「从零建执行点」误判成「把声明接到已有执行器」。

建议(不要顺手做,与 #4686 的裁决绑在一起)

无论走哪条,注释不能继续用现在时描述不存在的调用链 —— 这正是 Prime Directive #10 的 declared ≠ enforced,只不过这次说谎的是代码注释而不是 schema。

关联:#4686#4910#4936、Prime Directive #10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions