feat: 消息队列 peek/ACK + 持久化,防止消息丢失#3
Open
Isaac20231231 wants to merge 2 commits intoanjiacm:releasefrom
Open
Conversation
问题:飞书 WebSocket 长连接在网络波动或重连时,会重复投递同一条消息, 导致自动回复(离线提示)发送多次。 修复: - 新增 _seen_messages 内存缓存,基于 message_id 去重 - 60秒 TTL 自动过期清理,不占用额外内存 - 在 on_message 入口处检查,重复消息直接跳过
问题:
- GET /api/messages 读取即删除,Claude 处理前崩溃则消息永久丢失
- 调试用 curl GET 也会消费生产消息(已造成实际事故)
- 缺少 GET /api/claude/status 端点,飞书 Bot 始终认为 Claude offline
- 消息仅存内存,Dashboard 重启后队列清空
- PID 文件路径硬编码,多项目实例冲突
修复:
- GET /api/messages 改为 peek(非破坏性读取)
- 新增 POST /api/messages/ack 支持 upToId 精确确认
- 消息入队时分配自增 _id,持久化到 data/message-queue.json
- 新增 GET /api/claude/status 只读端点
- 轮询脚本增加本地 pending-messages.json 兜底
- PID 路径改为动态 ${PROJECT_NAME}
- .gitignore 排除运行时数据文件
- CLAUDE.md.tmpl 更新 API 速查表和处理流程
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.
Summary
upToId精确确认_id,持久化到data/message-queue.jsonpending-messages.json兜底机制${PROJECT_NAME},避免多实例冲突问题背景
旧版
GET /api/messages采用"读取即删除"语义,存在多个可靠性问题:curl GET /api/messages也会消费生产消息(实际已造成事故)GET /api/claude/status,飞书 Bot 始终认为 Claude offline数据流(优化后)
改动文件
skeleton/web/server.jsskeleton/scripts/dashboard-poll.shskeleton/CLAUDE.md.tmplskeleton/.gitignoredata/*.json和data/*.logTest plan