feat(lifecycle): add stage 4 authoritative unbind and durable task routing
Unify broker-mode binding changes in database transactions: advance device generation, invalidate pending authorizations/tasks and prior pairing-code epochs, and persist audit plus invalidation outbox. Add authenticated device unbind alongside robot/admin paths. Pairing codes are hashed, generation- fenced and consumed atomically with binding. Replay Redis invalidation effects without undoing committed unbind. Guard online cleanup and delayed kill events by generation. Introduce a separate router admission credential with no platform-event injection authority. Router verifies signed nonce-bound internal admission on handshake, task traffic and periodic checks; reject stale sessions and control-plane outages. Persist task owner/device/generation/session/worker and original message mapping. Sign routing metadata, verify late results, claim replies once and mark ambiguous/crashed tasks unknown instead of replaying writes. Fence notifications across same-user rebind. Release in-memory slots/waiters even when database or Redis cleanup fails. Validation: 213 passed, 3 skipped (real PostgreSQL not configured), 30 existing uvicorn/websockets deprecation warnings. New lifecycle coverage: 28 tests, including real loopback WebSocket isolation, reverse completion, missed kill, periodic unbind checks, outbox recovery, transaction rollback and cleanup failures. Syntax, docs and staged diff checks pass. Default legacy mode remains unchanged. Broker mode now requires coordinated router admission configuration and a v2 client handshake. No production ECS configuration, real credentials or client installer was changed. PostgreSQL, real Redis multi-node, ARM64 and actual Work/client rollout remain stage 5.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
| 1 | 服务端加密凭据存储基础 | 密文持久化、应用/用户/环境隔离、版本冲突、密钥轮换与篡改检测测试;不接入旧路由 | 已完成本地开发测试,提交71b9678 |
|
||||
| 2 | 集中凭据Broker及刷新 | 应用/用户锁、持锁重读、版本CAS、响应校验、刷新unknown;新授权不受旧刷新覆盖 | 本次完成本地开发测试 |
|
||||
| 3 | OAuth与认证领取 | 共享state事务、实际用户核验、绑定代次、只返回access的独立DTO及领取认证 | 本次完成本地开发测试,显式broker模式启用 |
|
||||
| 4 | ECS权威解绑与消息任务关联 | 停发Token、失效事务/任务、连接和旧码联动,多实例/异常恢复 | 待开发 |
|
||||
| 4 | ECS权威解绑与消息任务关联 | 停发Token、失效事务/任务、连接和旧码联动,多实例/异常恢复 | 本次完成本地开发测试,broker模式生效 |
|
||||
| 5 | 配置部署、迁移与旧接口退出 | 密钥挂载、产品权限配置、客户端对接、停用旧刷新/claim及代理、ARM64和真实平台验收 | 待开发 |
|
||||
|
||||
产品经理决定功能和Scope清单。阶段1不预设具体权限,不生成真实凭据、不读取现有设备、不调用平台。
|
||||
@@ -126,3 +126,28 @@ Windows / Python 3.12.10,平台桩、临时证书/密钥、SQLite及带Lua的F
|
||||
最后完整回归:**185 passed,3 skipped,15 warnings**(49.77秒)。3个跳过项均需要真实PostgreSQL测试连接;warnings仍为原有uvicorn/websockets弃用提示。文档表格/围栏、relay模块AST及`git diff --check`通过。
|
||||
|
||||
真实PostgreSQL、真实Redis多进程、ARM64镜像、私有化平台及现机业务验收尚未执行;本地ASGI/FakeRedis结果不能作为线上多节点或生产部署结论。
|
||||
|
||||
## 阶段4:ECS权威解绑、连接准入与任务关联(2026-11-04)
|
||||
|
||||
细节见[阶段4协议和边界](BINDING_TASK_LIFECYCLE.md)。本次仅修改ECS项目,未修改或发布PC安装包,未部署现机。
|
||||
|
||||
### 改造内容
|
||||
|
||||
- 新增`BindingState`及Store生命周期挂钩,在broker模式统一bind/unbind/revoke,数据库事务内更改绑定代次、作废未完成授权/任务/配对码epoch、记录审计和outbox。legacy路径保持原行为。
|
||||
- 新增认证设备解绑入口;机器人命令、管理员和设备解绑共用同一权威状态。旧配对码按owner epoch拒绝;新broker配对码只存摘要,和绑定一起一次性消费,不接受原legacy Redis码。
|
||||
- Redis失效动作失败时保留outbox供本节点/其他connector重试;删除在线presence有比较保护,断连消息包含代次,旧事件不误断新连接。接口published/pending不等于PC确认。
|
||||
- router新增独立内部准入Secret,和事件接入Secret分权;请求带nonce并验证connector签名的短期准入结果,不取得Token。握手/订阅后/任务上下行/周期均复核数据库绑定及任务;控制服务失败时拒绝转发。
|
||||
- 新v2设备握手绑定应用、环境、owner和generation;任务下行带签名routing及密文摘要。新模式旧PC握手会拒绝,不能宣称对现有安装透明兼容。
|
||||
- 持久任务记录关联原message/chat/conversation、设备、generation、session、worker及deadline;结果逆序仍按原任务交付,平台回复单次认领;迟到/解绑/死亡worker/超时不改变终态、不重放写任务。
|
||||
- worker使用30秒Redis存活租约和5秒维护;任务扫描轮转避免后续任务饥饿;无结果正文持久化,不承诺重启后恢复丢失的内存结果。
|
||||
- 通知增加broker必填generation并在等待平台凭据后复查,防止同用户重绑后旧通知继续发送;legacy原签名兼容。应用及用户refresh均不下发。
|
||||
|
||||
### 本地验证
|
||||
|
||||
新增阶段4专项28项:真实回环WebSocket而非纯函数桩,覆盖两用户/同用户多任务逆序、机器人解绑断连与旧回包拒绝、数据库提交/Redis失败补偿、事务回滚、另一connector重开补偿、旧码拒绝与一次消费、迟到kill不影响新连接、通知期间重绑不发、吊销与旧握手拒绝、控制面中断拒绝转发、周期查库发现解绑、死亡worker和reply_unknown不重放,以及DB/Redis清理失败仍释放内存连接/等待记录。扩展可选PostgreSQL用例覆盖owner epoch和outbox,但无连接时仍跳过。
|
||||
|
||||
专项测试不代表真实Hermes客户端的记忆隔离已经完成;本次测试用合成PC设备/平台桩和本地SQLite/FakeRedis,客户端可信TaskContext传入Agent/MCP仍需后续适配。默认旧模式、服务器配置和真实凭据均未切换。
|
||||
|
||||
最后完整回归:**213 passed,3 skipped,30 warnings**(45.87秒)。3个跳过项均需要真实PostgreSQL连接,warnings为既有uvicorn/websockets旧API弃用提示(新增真实回环连接增加提示次数);relay模块AST、文档和diff检查通过。
|
||||
|
||||
生产部署、真实Redis/PostgreSQL多实例、ARM64镜像、平台实际撤权/Scope/容量和客户端安装升级仍待阶段5及现场验收。平台已接收的请求不可靠解绑撤回,已发access仍可能有效到期。
|
||||
|
||||
Reference in New Issue
Block a user