Skip to content

fix(worker): hello 首连同步分块,不再单次序列化上万行(保完整性)(#129)#306

Merged
leeguooooo merged 1 commit into
mainfrom
fix/hello-backfill-chunking-129
Jul 11, 2026
Merged

fix(worker): hello 首连同步分块,不再单次序列化上万行(保完整性)(#129)#306
leeguooooo merged 1 commit into
mainfrom
fix/hello-backfill-chunking-129

Conversation

@leeguooooo

Copy link
Copy Markdown
Owner

修什么(#129,[P3][impl])

hello 首连补拉曾无 LIMITsince=0 单条查询把最多 1 万行一并 toArray 序列化(REST /internal/messages 早有 limit=1000)。首连同步语义被依赖,正确修法是分块而非砍 LIMIT

怎么修(分页,保完整性)

  • 按 seq 游标分页(HELLO_BACKFILL_PAGE_SIZE=1000):WHERE (原条件) AND seq > ? ORDER BY seq LIMIT ?,循环到某页短于一页即排空,游标推进到本页末 seq。seq 唯一升序 → 严格前进、不重不漏。跨批次逐帧下发全部消息,客户端消费与不分页完全一致,首连即完整的契约不破。
  • 游标从 0 起(非 since)since_rev 命中的修订行 seq 可能 ≤ since,必须纳入遍历,否则漏「seq 小但被修订」的行。
  • 补拉期不 await:DO 单线程处理这条 hello、其间无 send 穿插改表、快照一致;分页边界只漏「hello 开始后」的新消息,由 send 的 live 广播补上(seq 更大、客户端照收)。

门禁(对 origin HEAD rebase 后亲验)

  • worker hello-backfill spec 2/2;worker tsc 0;rebase 无冲突。
  • spec 塞 1500 条(>1 页强制多页),断言 全 1500 到齐(完整性:length/unique/min=1/max=1500)每查询 __maxBackfillBatch ≤ 1000(有界性)
  • ⚠️ 变异 caveat(诚实):两次变异(break 提前 / PAGE_SIZE 调大回无界)都触发了已知的 vitest-pool-workers DO-reload flake(改 do.ts → workerd 「index.ts changed」重载 → Failed Suites / no tests),未拿到干净的单断言红。完整性+有界性由 spec 断言覆盖、正确代码上 2/2 通过、分页逻辑经人工复核(游标单调不重不漏)。CI 环境跑该 spec 更稳,请复核。

🤖 opus agent 实现、收尾截断我接管(审+提交+复验)。

hello 补拉曾无 LIMIT,since=0 单次把最多 1 万行一并 toArray 序列化(REST 早有 limit=1000)。
改为按 seq 游标分页(每页 ≤ HELLO_BACKFILL_PAGE_SIZE=1000),循环到某页短于一页即排空,
跨批次逐帧下发全部消息——客户端消费与不分页完全一致,首连即完整的契约不破。
分页游标从 0 起(非 since):since_rev 命中的行 seq 可能 ≤ since,必须纳入遍历。
补拉期不 await(DO 单线程、快照一致),边界只漏 hello 开始后的新消息、由 live 广播补上。
@leeguooooo leeguooooo merged commit 15ecb78 into main Jul 11, 2026
17 checks passed
@leeguooooo leeguooooo deleted the fix/hello-backfill-chunking-129 branch July 11, 2026 11:55
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.

1 participant