fix(worker): wake_delivery_ledger/message_audit/read_cursor 有界修剪,DO 存储不再只增不减(#128)#311
Merged
Merged
Conversation
…储不再只增不减(#128) 三张 DO-sqlite 表此前无任何裁剪、只增不减,DO SQLite 无上限增长(10GB 上限前先拖慢 who/hello)。在 onAlarm 周期维护里加 pruneStorage,全走已在 DO 单线程内的 sql.exec, 热路径零成本;每张表按「消费者仍需的窗口」定界,镜像既有 messages(RETAIN_N) / webhook_dead_letters(MAX_WEBHOOK_DEAD_LETTERS) 的有界保留手法: - wake_delivery_ledger:按时间窗裁(attempted_at < now-WAKE_LEDGER_RETENTION_MS,35 天)。 保留窗口严格大于预算窗口上限 WAKE_BUDGET_MAX_WINDOW_MS(30d),#108 wakeCountInWindow 仍要数的行 attempted_at 一定 > cutoff,绝不被裁 → 预算不少计、不漏;#105 死信与 #107 resume 回填只关心近期行,35 天足够。 - message_audit:保留最新 MAX_MESSAGE_AUDIT_ROWS(20000, 2×RETAIN_N) 行(按自增 id)。 审计 API 只按 target_seq 查单条消息 → 近期消息对应高 id 行永不被裁;与 #196 撤回清洗 正交——被裁旧行正文早已 NULL(撤回后不可再编辑),裁掉不泄露内容。 - read_cursor:PK=name 每身份仅一行。只裁「updated_at 早于 READ_CURSOR_RETENTION_MS(30d) 且此刻无活连接」的陈旧游标;在线身份(含刚 caught-up 未再推进)的活游标绝不被裁。 TDD:每表先写失败用例(超界后裁到界、保留最新、live/在线行不被裁),再实现;三处裁剪各做 突变验证(去掉裁剪 → 无界增长 → 红)。worker tsc 0;全量 spec 分批跑全绿(单 workerd 串行满载的 DO 失效级联属既有 flakiness,隔离/分批稳定通过)。 Claude-Session: https://claude.ai/code/session_01FS3jLbZK3AqVXgkhRcEEQg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修什么(#128,[P3][impl])
wake_delivery_ledger/message_audit/read_cursor(DO-sqlite 表)无修剪、只增不减、无界增长。加有界保留,DO 存储不再无限膨胀。怎么修(仿既有 messages RETAIN_N,在 onAlarm 修剪,不碰热路径)
pruneStorage(now)在onAlarm(既有周期维护:presence 扫描/webhook 重试/temp 归档)里跑:wake_delivery_ledgerattempted_at < now - WAKE_LEDGER_RETENTION_MS(35d)wakeCountInWindow只数attempted_at ≥ now-windowMs(≤30d),故预算仍要数的行一定 > cutoff、绝不被裁 → 预算不少计。#105 死信/#107 resume 只读近期行。message_auditMAX_MESSAGE_AUDIT_ROWS(2万=2×RETAIN_N) by idread_cursorupdated_at < now-30d且 name 当前未连接门禁(对 origin HEAD rebase 到含 #99/#107 的 main 后亲验)
说明
🤖 opus agent 实现(协调 #108/#105/#107/#196 的保留安全性)+ 我复验。