Skip to content

fix(device-link): 减少手机恢复重复同步和误报中断 - #3326

Merged
MagicLizi merged 18 commits into
makecindy:mainfrom
zqchris:device-link-mobile-recovery
Aug 25, 2026
Merged

fix(device-link): 减少手机恢复重复同步和误报中断#3326
MagicLizi merged 18 commits into
makecindy:mainfrom
zqchris:device-link-mobile-recovery

Conversation

@zqchris

@zqchris zqchris commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

#3309 应先合并。本 PR 当前临时包含其 peer lifecycle 清理提交;#3309 合入 main 后,本分支会 merge 最新 main,PR diff 自动收敛为第二批手机恢复止血净增量。

这次改了什么

摘要

手机从新连接进入任务时,页面加载与全局恢复不再重复拉取同一份快照;某一个读取超时只重试自己,不再重放整组请求。当前连接代的任务元数据尚未同步完成时,不再用旧时间戳误报“任务中断”。同时补充不含用户内容的 ACK timeout 归因日志,便于发布后区分线路未推进与本地发送异常。

变更类型

  • feat 新功能
  • fix 缺陷修复
  • refactor / perf 重构或性能优化
  • docs / test / chore 文档、测试或工程维护
  • 其他:

范围

故障半径:本 PR 处理的是单个任务快照读取与手机本地状态判定,恢复动作限定在失败的单项请求;不新增连接级 teardown,不扩大到共享 relay socket。多 peer 共享连接行为由 #3284 的既有回归覆盖,本 PR 不改变该路径。

UI 变化

不涉及视觉、布局、颜色或文案变化;只在当前连接元数据未同步完成时抑制旧状态推导的中断横幅,继续沿用现有同步界面。

  • 引用的设计规范:不涉及视觉规格;遵循 DESIGN.md 的状态连续性原则,不让恢复中的旧状态闪成确定性错误。

怎么验证的

自动验证

pnpm --filter mobile exec vitest run src/__tests__/sessionSnapshotSingleFlight.test.ts src/__tests__/sessionTailBannerModel.test.ts src/__tests__/optimisticSessionComposer.test.ts src/__tests__/sessionComposerDesktopFirst.test.ts
结果:42/42 通过

pnpm --filter mobile typecheck
结果:通过

pnpm --filter @cindy/device-link exec vitest run src/__tests__/client.test.ts
结果:158/158 通过

pnpm --filter @cindy/device-link build
结果:通过

pnpm test:unit:related
结果:Mobile 全量通过;device-link 通过;Desktop 仅 ghostInstallReceipt.test.ts 两个既有环境失败,已在干净 main 单独复现,与本 PR 无关。

git diff --check
结果:通过

手工验证

不涉及视觉手工验收;完成代码路径与并发顺序自审。

未执行的验证

未启动 Desktop DEV、Electron、Vite 或 CDP。未执行真实手机 + relay + VPN E2E;发布包含本 PR 的手机 JS/OTA 与桌面版本后,需要对比任务首屏等待、ACK timeout 归因和误报中断数量。

风险

风险分类

  • 无已知风险
  • SQLite / migration
  • system prompt
  • 协议兼容
  • 权限 / 安全 / 用户数据
  • 存量插件兼容(批准状态 / 指纹 / manifest 校验 / 安装布局 / 包格式)
  • 原生层 / fingerprint / OTA
  • 跨平台差异
  • 其他:弱网恢复与并发时序

影响与回滚

  • 影响范围:手机任务详情同步、手机全局 rehydrate、任务尾部中断提示、device-link 最终 ACK timeout 日志。
  • 回滚 / 降级方式:回滚本 PR 后恢复旧的整组重试与中断判定;没有数据迁移或协议状态需要清理。
  • 原生 fingerprint:不修改原生配置、依赖或 fingerprint 输入,属于 JS/TS 更新。
  • 协议兼容:不修改 envelope、字段或 wire 行为;新旧端可分阶段升级。

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名(git commit -s,见 DCO
  • UI 改动已在「UI 变化」注明引用的设计规范(不涉及 UI 则跳过)
  • 未提交凭证、令牌或授权文件
  • 已补充必要文档
  • 已确认测试结果或说明未执行原因

dashhuang and others added 4 commits August 24, 2026 06:04
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
@zqchris
zqchris requested a review from a team as a code owner August 24, 2026 06:10
@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown

Greptile Summary

本 PR 收敛手机端弱网恢复流程,避免页面加载与全局 rehydrate 重复读取同一会话快照,并将失败恢复限制到单项请求。

  • 新增按设备、会话、连接代次和本地权限栅栏区分的快照 single-flight
  • 为订阅及快照重试增加同轮 peer reopen 协调
  • 使用当前连接的元数据同步状态抑制过早的任务中断判断
  • 为 peer 路由状态增加 link generation,避免旧链路的离线事件清理新链路
  • 补充最终 ACK timeout 的结构化归因日志及相关回归测试

Confidence Score: 5/5

当前没有仍需阻止合并的已知故障,PR 看起来可以安全合并。

当前没有阻塞性故障遗留。

Important Files Changed

Filename Overview
apps/mobile/app/sessions/[sessionId].tsx 会话页将订阅、元数据、消息、待处理交互和输入投影拆分恢复,并用连接代次控制中断横幅判定。
apps/mobile/src/device-link/sessionSnapshotSingleFlight.ts 新增带完整请求语义和本地权限栅栏的会话快照 single-flight,实现相同读取合并与结算后清理。
apps/mobile/src/device-link/remoteSyncTask.ts 新增单轮同步内的 peer reopen 协调器,使同一故障代次的错峰失败共享恢复动作。
apps/mobile/src/device-link/DeviceLinkContext.tsx 同步推进连接代次,接入全局快照 single-flight,并提供可刷新已结算 link-open 的 reopenLink。
packages/device-link/src/client.ts peer 路由事件增加 link generation,并为最终 ACK timeout 输出不含用户内容的分类诊断。
apps/desktop/src/main/device-link/dispatch.ts 桌面端记录活跃控制链路代次,忽略来自旧连接或旧 link 的迟到离线事件。
apps/mobile/src/session/sessionTailBannerModel.ts 中断状态仅在当前连接的会话元数据完成同步后参与推导,避免使用旧时间戳误报。

Sequence Diagram

sequenceDiagram
    participant P as 手机会话页
    participant G as 全局 Rehydrate
    participant S as Snapshot Single-flight
    participant L as Device Link
    participant D as 桌面端
    P->>S: 按设备/会话/连接代请求快照
    G->>S: 请求相同范围的快照
    alt key 与权限栅栏一致
        S->>L: 合并为一次物理读取
    else 请求语义不同
        S->>L: 分别读取
    end
    L->>D: invoke
    D-->>L: snapshot
    L-->>S: 返回结果
    S-->>P: 页面按当前权限栅栏提交
    S-->>G: rehydrate 按当前权限栅栏提交
    opt 单项读取瞬时失败
        P->>L: 协调一次 peer reopen
        P->>S: 仅重试失败项
    end
Loading

Reviews (15): Last reviewed commit: "fix(device-link): release route ledger e..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ce1e4f488

ℹ️ 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".

Comment thread apps/mobile/app/sessions/[sessionId].tsx Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edd480e1f0

ℹ️ 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".

Comment thread apps/desktop/src/main/device-link/dispatch.ts
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89232ac5a0

ℹ️ 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".

Comment thread packages/device-link/src/client.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 825cf0203d

ℹ️ 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".

Comment thread packages/device-link/src/client.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbf80d83bf

ℹ️ 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".

Comment thread packages/device-link/src/client.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14a070586a

ℹ️ 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".

Comment thread packages/device-link/src/client.ts
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0a2ac0288

ℹ️ 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".

Comment thread packages/device-link/src/client.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f392f5a9f

ℹ️ 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".

Comment thread apps/mobile/app/sessions/[sessionId].tsx Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c199c8e339

ℹ️ 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".

Comment thread packages/device-link/src/client.ts
Comment thread apps/mobile/app/sessions/[sessionId].tsx Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7797bd91a1

ℹ️ 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".

Comment thread apps/mobile/src/device-link/remoteSyncTask.ts Outdated
Comment thread packages/device-link/src/client.ts Outdated
@MagicLizi

Copy link
Copy Markdown
Contributor

@zqchris 👋 这个 PR 还有 2 条 review conversation 没 resolve(apps/mobile/src/device-link/remoteSyncTask.ts / packages/device-link/src/client.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

@MagicLizi MagicLizi added status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) touches:large-diff 改动量较大(review-pr 自动维护,仅展示) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示) labels Aug 24, 2026
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7018a7a564

ℹ️ 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".

Comment thread packages/device-link/src/client.ts
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00657059a3

ℹ️ 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".

Comment thread packages/device-link/src/client.ts
Comment thread apps/mobile/app/sessions/[sessionId].tsx Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
@MagicLizi MagicLizi removed the status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) label Aug 24, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

命中 UI 路径(mobile sessions / DeviceLinkContext 等)但 description 未附界面效果证据——建议补充改动后效果:截图/录屏,或改动后界面的 HTML 页面,便于确认界面符合 DESIGN.md 设计规范。本条不阻断合并。

@MagicLizi

Copy link
Copy Markdown
Contributor

@zqchris 👋 这个 PR 目前与 main 有合并冲突,auto-review 因此暂时跳过、没法继续审查 / 合并。

请在本地 merge 最新的 origin/main 解决冲突后推送;冲突解除后,下一轮 auto-review 会自动重新处理这个 PR。

@MagicLizi MagicLizi added the status:conflict 与目标分支有冲突(review-pr 自动维护,仅展示) label Aug 25, 2026
…recovery

Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

# Conflicts:
#	apps/desktop/src/main/device-link/__tests__/dispatchWeakNetwork.test.ts
#	apps/desktop/src/main/device-link/dispatch.ts
#	packages/device-link/src/__tests__/client.test.ts
#	packages/device-link/src/client.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16ed7803c2

ℹ️ 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".

Comment thread packages/device-link/src/client.ts
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
@MagicLizi MagicLizi removed the status:conflict 与目标分支有冲突(review-pr 自动维护,仅展示) label Aug 25, 2026
@MagicLizi
MagicLizi merged commit 111939c into makecindy:main Aug 25, 2026
11 checks passed
@MagicLizi

Copy link
Copy Markdown
Contributor

合了。手机恢复不再把一次超时当成整条链路断掉,重复同步也会少很多。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) touches:large-diff 改动量较大(review-pr 自动维护,仅展示) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants