fix(device-link): 清理离线控制端的陈旧状态 - #3309
Conversation
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
|
| Filename | Overview |
|---|---|
| packages/device-link/src/client.ts | 新增带 connection epoch 的 peer route offline 生命周期事件、连接代内去重及恢复时的在线标记。 |
| apps/desktop/src/main/device-link/dispatch.ts | 将单控制端、全 relay 和永久关闭场景收敛到统一的 controller 失活状态转换。 |
| apps/desktop/src/main/device-link/index.ts | 接入 peer offline 回调,并在 relay 离开 online 状态时清理全部 active controller projection。 |
| packages/device-link/src/tests/client.test.ts | 覆盖 pending 与非 pending DEVICE_OFFLINE、事件去重及旧 socket 回调隔离。 |
| apps/desktop/src/main/device-link/tests/dispatchWeakNetwork.test.ts | 覆盖多 peer 故障隔离、relay 全量失活和跨连接代离线事件保护。 |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Relay 或 peer 状态变化] --> B{故障范围}
B -->|DEVICE_OFFLINE / presence offline| C[失活单个 controller]
B -->|Relay 非 online| D[失活全部 active controllers]
C --> E[清理 active topics、横幅、busy 与临时 stage]
D --> E
E --> F[保留 remembered topics、capabilities 与可靠待发送状态]
F --> G[重连后通过 link-open 与 subscribe 恢复]
B -->|永久 link-close / 撤权| H[清理 active 与 remembered routing]
Reviews (2): Last reviewed commit: "test(device-link): cover peer offline is..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 790b59ab80
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
|
已按 review 建议补上真实链路回归(commit 986121d):A/B 使用真实 DeviceLinkClient 建链,relay 注入 target→A 的 DEVICE_OFFLINE;B 的在途 subscribe invoke-result 暂存后,在 A 失活期间释放并成功完成,同时断言 B 的 active/remembered 状态保持。新增回归所在的 dispatchWeakNetwork.test.ts 17 个测试全部通过。原 inline thread 因当前 token 不具备 AddPullRequestReviewComment 权限,无法直接回复。 |
|
合了。控制端掉线后陈旧投影不再赖着,对端不用再对着一个已经不在的设备发请求。 |
这次改了什么
摘要
修复 device-link 控制端离线后 Desktop 仍显示“被 iPhone 控制”的生命周期问题。将 relay 的
DEVICE_OFFLINE、presence offline、relay 整体断开和永久 link-close 收敛到统一的 active controller 失活路径,同时保留断线恢复所需的 remembered routing。变更类型
fix缺陷修复范围
DeviceLinkClient为DEVICE_OFFLINE提供 typed peer route lifecycle 事件,覆盖 pending / non-pending 路径并按连接代去重;UI 变化
怎么验证的
自动验证
pnpm test:unit:related已执行;本次相关的packages/device-link和 Desktop device-link 测试通过,但整体门禁仍被既有基线问题阻断:DesktopghostInstallReceipt.test.ts有 2 个既有断言失败,MobilestartupSplashOverlay.test.ts有 1 个既有超时,均不涉及本 PR 文件。手工验证
不涉及真实手机、relay 或 Desktop DEV 启动;本 PR 使用单元测试覆盖生命周期和多 peer 故障半径。
未执行的验证
未执行真实手机后台休眠、真实 relay 弱网和多台真实控制端 E2E。建议合入后用现有 device-link 日志验证 presence offline、
DEVICE_OFFLINE、relay reconnect 与 controlled-state 的时序。风险
风险分类
影响与回滚
packages/device-link客户端路由生命周期通知,以及 Desktop device-link host 的 active controller projection;手机端继续使用共享 client,但没有 Desktop 控制横幅,因此无需新增移动端入口或协议适配。DEVICE_OFFLINE路由失败,或共享 relay 连接离线;790b59ab8;wire protocol 未变化,旧客户端可继续互通。提交前检查
git commit -s)