Skip to content

fix(411): 回收的两张皮收口到一份口径 - #413

Merged
modusensus merged 1 commit into
mainfrom
fix/411-reclaim-unify
Oct 12, 2026
Merged

modusensus merged 1 commit into
mainfrom
fix/411-reclaim-unify

Conversation

@modusensus

@modusensus modusensus commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

背景

#410 把面板路由 /api/dsh-mneme/maintenance/reclaim 的窗口上界与确认门兜错修好了,但数据面 POST /maintenance/reclaim 还停在旧形态 —— 因为这两张皮一直是整段复制的。段头那句注释「改这里时那边一起改」没能拦住任何事,它正是漂移发生的地方。

Closes #411

改了什么

口径只有一份实现,放在新的 src/reclaim-http.js:

导出 作用
MAX_RECLAIM_WINDOW_DAYS = 3650 窗口上界(与 llmAudit.retentionDays / recallRetentionDays 同线)
parseReclaimQuery(raw) GET 的 ?olderThanDays:只收十进制整数字面量,缺省才落默认
parseReclaimJson(text) POST body 的 JSON 与顶层形状(invalid-json 与 invalid-body 是两个错)
readReclaimFields(body) 字段归一与校验(只收 JSON 数字、vacuum 只收布尔、confirm 只认真布尔)
reclaimReply({...}) 把一次请求变成 {status, body};报告不加包装层
RECLAIM_UNAVAILABLE / RECLAIM_CONFIRM_HINT / reclaimWarnMessage 三处共用字面量

两个入口各自只剩鉴权与路径不同:src/api.js 净减 64 行、src/api-standalone.js 净减 52 行。

顺序也是契约:invalid-json → invalid-body → 503 maintenance-unavailable → 字段校验。端点整个没接线时报「窗口不合法」是误导 —— 调用方会去改窗口,改完照样 503。两侧都补了锁钉住这个先后。

防复发:不靠注释,靠静态锁

test/reclaim-http.test.js 断言这六个字面量在 src/api.js 与 src/api-standalone.js 里一个都不许出现:

invalid-older-than-days / invalid-vacuum / confirm-required / maintenance-unavailable / storage reclaim failed / MAX_RECLAIM_WINDOW_DAYS

同时反向也锁:两个文件必须真的 import 共用模块并调用 reclaimReply( / readReclaimFields( —— 光删字面量不接线等于把功能删了。

证据

项目 结果
全量测试 1665 tests / 1664 pass / 0 fail / 1 skipped
新增测试 14 条(test/reclaim-http.test.js 13 + test/maintenance.test.js 1 条从数据面自己的端口打真 HTTP)
变异检验 11 条全 RED,含「把口径复制回数据面」「数据面不再调共用答复」这两条防分叉锁本身
check-sync ✓ src/ 与 lib/ 一致(58 个文件)
规模 13 文件 / +709 −252

数据面那条测试覆盖:窗口上界(3651 / 1e20 → 400、3650 → 200)、确认门报告复述被问的那个窗口、勾了 VACUUM 就真透传(vacuum.ran === true)、没接线时 503 赢过字段校验。

顺手带的

  • AGENTS.md 模块地图加一行(AGENTS.md:3 要求「改完结构顺手更新这里」,新模块不登记就是让地图骗人);
  • 修了 test/maintenance.test.js 里一个挂死:那个「没接线」的实例建在 try 内、只在断言之后内联关,断言一旦先炸 server 句柄就留着,node --test 永不退出(变异检验里实测挂了 26 分钟)。改成 try 外建、finally 里关,同一组测试 26 分钟 → 2 秒。

Refs #411

Summary by CodeRabbit

  • 功能调整
    • 面板与独立数据接口的回收请求现采用一致的参数校验、默认值和响应规则。
    • 回收时间范围支持 0 至 3650 天;未确认的实际执行请求会先返回预览报告,不执行回收。
  • 错误处理
    • 维护服务不可用时统一返回 503;无效请求和回收失败会返回相应错误响应。

Copilot AI lite review requested due to automatic review settings October 12, 2026 01:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: slow-stack/mneme/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 50b5c43c-4774-4aab-a776-626d18a106c5

📥 Commits

Reviewing files that changed from the base of the PR and between 9603d96 and 2001b3c.


📒 Files selected for processing (13)
  • AGENTS.md
  • README.md
  • dsh-mneme/CHANGELOG.md
  • dsh-mneme/README.md
  • dsh-mneme/lib/api-standalone.js
  • dsh-mneme/lib/api.js
  • dsh-mneme/lib/reclaim-http.js
  • dsh-mneme/src/api-standalone.js
  • dsh-mneme/src/api.js
  • dsh-mneme/src/reclaim-http.js
  • dsh-mneme/test/api-routes-gaps.test.js
  • dsh-mneme/test/maintenance.test.js
  • dsh-mneme/test/reclaim-http.test.js

 _________________________
< Think twice, code once. >
 -------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.50980% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
dsh-mneme/src/api-standalone.js 95.45% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@modusensus
modusensus force-pushed the fix/411-reclaim-unify branch from b92058e to 8db7d95 Compare October 12, 2026 10:42
Copilot AI lite review requested due to automatic review settings October 12, 2026 10:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

面板路由 /api/dsh-mneme/maintenance/reclaim 与 Bearer 数据面
POST /maintenance/reclaim 底下是同一份 src/maintenance.js,但 HTTP 外壳一直是
整段复制的。于是 #410 修好面板侧之后,数据面还停在旧形态:窗口没有上界
(1e20 也是整数,maintenance 拿它算 now() - days * 86400000 再 toISOString()
抛 RangeError——而它发生在 readBody 的回调里,外层 try 那时已经退栈,调用方
拿到的是一个字节都没回,不是 500),确认门里那份 dry-run 报告同样没兜错。

口径(错误码字符串、默认值、报告形状、窗口上界、确认提示、warn 文案)现在只
写在新的 src/reclaim-http.js 里,两个入口都调 parseReclaimQuery /
parseReclaimJson / readReclaimFields / reclaimReply,各自只留鉴权与路径。

顺序也是契约的一部分:invalid-json → invalid-body → 503
maintenance-unavailable → 字段校验。端点整个没接线时报「窗口不合法」是误导
(调用方会去改窗口,改完照样 503),两侧都补了锁钉住这个先后。

防复发不靠注释(段头那句「改这里时那边一起改」正是漂移发生的地方),靠
test/reclaim-http.test.js 的静态锁:六个字面量在 src/api.js 与
src/api-standalone.js 里一个都不许出现,同时两个文件必须真的 import 共用模块
并调用它——光删字面量不接线等于把功能删了。

新增测试 14 条。11 条变异逐条打回坏状态全部转红。

Refs #411
@modusensus
modusensus force-pushed the fix/411-reclaim-unify branch from 8db7d95 to 2001b3c Compare October 12, 2026 10:46
@modusensus
modusensus merged commit 042188a into main Oct 12, 2026
10 of 11 checks passed
@modusensus
modusensus deleted the fix/411-reclaim-unify branch October 12, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] standalone /maintenance/reclaim 与面板路由同源的两处形态:窗口无上界 + 确认门的报告未兜错

2 participants