外观
Day 7:Realtime、Local-first 与恢复
当日成果
让 Day 2–6 的身份、关系、会话和消息在断线、事件丢失、cursor 过期、进程重启和多设备并发下可靠收敛。
能力边界
本日不增加明显的新页面,重点把已有能力从“联网时可用”提升为“可以恢复的成熟系统”。
能力合同
| Capability ID | API | Admin | iOS | Android | 关键证据 |
|---|---|---|---|---|---|
| RT-001 Durable event | ✓ | ✓ | ✓ | ✓ | cursor monotonicity |
| RT-002 Live SSE | ✓ | ✓ | ✓ | ✓ | reconnect |
| RT-003 Catch-up | ✓ | ✓ | ✓ | ✓ | missed events |
| RT-004 Gap repair | ✓ | ✓ | ✓ | ✓ | sequence/cursor gap |
| LOCAL-001 Projection | ✓ | ✓ | ✓ | ✓ | restart/offline |
| LOCAL-002 Durable outbox | ✓ | ✓ | ✓ | ✓ | replay/idempotency |
调查提示
text
进入 REALTIME-LOCAL-FIRST。绘制权威数据库、RealtimeEventLog、Redis live hint、
SSE、cursor、客户端 projection、outbox 和 REST repair 的完整数据流。找出任何会
提前推进 cursor、越过未修复 gap、重复执行 mutation 或用 live event 代替最终真值的路径。1
2
3
2
3
学员决策
- 哪些事件 durable,哪些 ephemeral。
- cursor 过期后按哪些 repair scope 重建。
- sequence gap 如何阻止 cursor 前进。
- session expiry、logout 和账号切换各自保留哪些本地数据。
Feature Goal
text
/goal 完成 REALTIME-LOCAL-FIRST,使 Day 2–6 的所有状态在 live、catch-up、gap repair、
offline outbox 和 restart 下最终收敛。以故障注入、cursor/sequence 不变量、重复事件、
过期 cursor、Redis 不可用和移动端进程重建测试为完成证据。1
2
3
2
3
跨端实施面
- API/worker/gateway:durable log、live hint、catch-up、cursor expiry、metrics。
- Admin:realtime/outbox 健康、延迟和失败观测。
- iOS:GRDB projection、SSE runtime、gap repair、network gate、durable outbox。
- Android:Room projection、runtime recovery、WorkManager、gap repair worker。
Mandatory gates
- [ ] durable cursor 单调且不越过未修复 gap。
- [ ] Redis 失败不破坏最终正确性。
- [ ] duplicate/out-of-order event 幂等。
- [ ] cursor expired 可以全域 repair。
- [ ] conversation gap 可以按 sequence 补洞。
- [ ] app restart 后 projection 和 outbox 恢复。
- [ ] 多账号不会串 projection/cursor。
- [ ] Admin 能区分当前故障和历史 terminal failure。
常见假完成
- SSE 收到事件就推进 cursor,业务 mutation 失败也不回退。
- Redis 被当作权威事件存储。
- catch-up 只拉事件,不验证 sequence gap。
- iOS/Android recovery 只在页面打开时运行。
- fake realtime test 不模拟重复、乱序和 cursor expiry。
Checkpoint
冻结 realtime catalog、repair scope matrix、故障注入结果、两端重启录像/日志和 realtime-local-first-green。