Skip to content

fix: forward noble BLE write options through desktop preload - #12928

Open
originalix wants to merge 3 commits into
hotfix/v6.5.2from
fix/desktop-ble-preload-write-options
Open

fix: forward noble BLE write options through desktop preload#12928
originalix wants to merge 3 commits into
hotfix/v6.5.2from
fix/desktop-ble-preload-write-options

Conversation

@originalix

Copy link
Copy Markdown
Collaborator

Problem

desktopApi.nobleBle.write in the preload only forwards (uuid, data) to the NOBLE_BLE_WRITE IPC, silently dropping the third options argument. The 1.2.x renderer transport (hd-transport-web-device electron-ble-transport.ts) passes { pacingDelayMs: 0 } to suppress per-packet write pacing for V2 high-throughput transfers; because the preload drops it, the main handler falls back to the default 5 ms delay on every packet, slowing V2 firmware/resource transfers.

Change

  • apps/desktop/app/preload.ts: write accepts and forwards the optional { pacingDelayMs } argument.
  • packages/shared/types/desktop.ts: widen INobleBleApi.write accordingly (inline type, no new imports).

The main-process handler (@onekeyfe/hd-transport-electron ≥1.2.x, pinned at 1.2.0-alpha.142 on this branch) already accepts options?: NobleBleWriteOptions; older 2-arg handlers ignore extra IPC args, so version skew is safe in both directions (worst case is falling back to today's behavior).

Verification

yarn agent:check --profile commit passes (lint-worktree-ts / lint-staged / tsc-staged).

Related: OneKeyHQ/hardware-js-sdk#888, OneKeyHQ/hardware-js-sdk#889 (desktop BLE hardening from the same investigation).

@sidmorizon

Copy link
Copy Markdown
Contributor

@codex review

@sidmorizon

Copy link
Copy Markdown
Contributor

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@originalix

Copy link
Copy Markdown
Collaborator Author

Added the SDK bump to 1.2.0-alpha.147 on this branch — published from OneKeyHQ/hardware-js-sdk#888 (combined desktop BLE hardening: stale peripheral cache clear on disconnect, process-lifetime state listener, desktop-scoped 60s acquire deadline + immediate cancel, queue task leak fix). One branch now carries the preload fix + the SDK for desktop self-testing: switch to it, yarn && yarn app:desktop.

@originalix

Copy link
Copy Markdown
Collaborator Author

Coordination note: #12917 (about to merge) bumps SDK pins to 1.2.0-alpha.150, which does NOT contain the desktop BLE fixes in this PR's alpha.147 (npm next line is content-forked between hardware-js-sdk#888 and #886 — no published version has both). After #12917 merges: this PR will be rebased to keep only the two code files (preload.ts + desktop.ts, which #12917 doesn't touch — zero code conflicts), and the pin should move to alpha.151 once hardware-js-sdk#888 is rebased onto #886 and republished. Do NOT resolve pins toward 147 (#12917's cancel-ownership requires SDK ≥148); resolving to 150 silently drops the desktop fixes — 151 is the correct target.

@originalix
originalix force-pushed the fix/desktop-ble-preload-write-options branch from 620df13 to e99ef2b Compare August 19, 2026 04:41
@originalix

Copy link
Copy Markdown
Collaborator Author

Rebased onto hotfix/v6.5.2 post-#12917 and bumped SDK pins to 1.2.0-alpha.151 — the first published version containing BOTH hardware-js-sdk#888 (desktop BLE hardening, rebased onto #886 and republished) and #886. Verified from installed artifacts: transport stale-cache/state-listener fixes present, hd-core contains both raceBleAcquire (deadline) and beginConnectionAttempt (#886). agent:check commit profile passes.

@socket-security

socket-security Bot commented Aug 19, 2026

Copy link
Copy Markdown

@sidmorizon

Copy link
Copy Markdown
Contributor

@cursoragent review

@cursor

cursor Bot commented Aug 20, 2026

Copy link
Copy Markdown

PR #12928 代码审查报告

审查的是 fix: forward noble BLE write options through desktop preloadpreload 转发本身是对的,可以合;当前分支不能直接合,因为已经和 hotfix/v6.5.2 冲突,且 SDK pin 落后于 hotfix 上的 1.2.0-alpha.162

审查概要

  • 变更范围: 5 个文件, +197 / -185 行(有效代码约 2 个文件;其余为 SDK pin + lockfile)
  • 风险等级: High(合入/pin 冲突;代码缺陷风险 Low)
  • 涉及平台: Desktop(preload);当前 SDK bump 会波及 Mobile / Web / Extension / CLI
  • Codex 交叉验证: ⏭️ 未启用
  • PR 评论分析: ✅ 已分析 (10 条评论, 其中 4 条来自 Bot)

评分

维度 得分 说明
🔒 安全性 8/10 未新增 IPC channel;pacingDelayMs 只影响节流,main 侧有 [0,1000] clamp
💎 代码质量 9/10 补的是真实丢参空洞,改动小、类型对齐、注释说明了为何不能再静默丢掉 options
🏛️ 架构合理性 8/10 修在 preload 这一层是对的;shared 内联类型避免新依赖,可接受
✅ 完整性 5/10 mergeable: CONFLICTING;pin 停在 161,hotfix 已是 162;PR 描述仍写 alpha.142
总分 7.9/10 ⚠️ 需 rebase 后再合,不要按当前 pin 强合

PR 评论分析

来源 类型 发现 判定 说明
@originalix 👤 Human #12917 后 pin 目标是 151,不要回 147 / 误用 150 🔍 Enriched 方向对,但已经过时:本分支到了 161origin/hotfix/v6.5.2 已是 162
@originalix 👤 Human rebase 后只留 preload.ts + desktop.ts ✅ Confirmed hotfix 已改过这两个文件(断开 reason),但和 write options hunk 不重叠,应能干净合并
Socket Security 🤖 Bot 一等依赖 150→154 评分表 ❌ Noise 一等包都是 @onekeyfe/*,无 CVE;现已到 161
Codex connector 🤖 Bot usage limit,没有实际审查 ❌ Noise 无有效 finding
@sidmorizon 👤 Human 触发 review 📋 Already Covered 本次审查

评论误报分析

  • [Socket] 误报: 评分波动来自 OneKey 自有 alpha 包,不是第三方供应链告警。
  • [Codex] 误报: 没有产出可核验的安全/代码结论。

发现的问题

[🔴 高] [🔵 High] 与 hotfix 冲突,SDK pin 落后于已合入的 162

文件: package.json, yarn.lock, apps/cli/package.json
类型: 构建 / 合入
描述: GitHub 状态是 CONFLICTING。hotfix 在本 PR merge-base 之后又合了 #12942 / #12940 / #12933 等,并把硬件 SDK 推到 1.2.0-alpha.162。按当前 161 去 resolve,会把 hotfix 降级write optionsalpha.150 起就在 @onekeyfe/hd-transport-electron 里(NobleBleWriteOptions + resolveNobleBleWritePacingDelay),162 仍然保留,所以 preload 修复不依赖 161。
修复建议: rebase 到最新 hotfix/v6.5.2;pin 保留 ≥162;SDK bump commit 若已无增量就丢掉,只留 preload.ts + desktop.ts。不要把冲突 resolve 成 161。


[🟢 低] [🟠 Medium] PR 描述过期

文件: PR body
类型: 规范
描述: 正文仍写 main handler「pinned at 1.2.0-alpha.142」。实际分支是 161,hotfix 是 162。
修复建议: rebase 后改成当前 pin,并写明只转发 options、不再靠本 PR 带 SDK。


[🟢 低] [⚪ Low] preload 内联了 pacingDelayMs,没复用 SDK 类型

文件: apps/desktop/app/preload.ts:296
类型: 规范
描述: 文件已经 import type { NobleBleAPI }。再内联 { pacingDelayMs?: number },下次 SDK 给 write 加字段时,还可能再被静默丢掉。shared 的 INobleBleApi 内联是合理的(@onekeyhq/shared 不应新挂 hd-transport-electron)。
修复建议: preload 改为 NobleBleWriteOptions;不是合入阻塞。

修改清单

优先级 置信度 文件 类型 描述 Auto-fix
🔴 高 🔵 High package.json / yarn.lock 合入 rebase,pin ≥162,勿回退到 161
🟢 低 🟠 Medium PR body 规范 去掉过期的 alpha.142
🟢 低 ⚪ Low preload.ts:296 规范 复用 NobleBleWriteOptions

代码路径核对(通过)

V2 传输在 hd-transport-web-devicewriteOnce() 里传 { pacingDelayMs: 0 };V1 仍走两参数 write(),继续用默认 5ms。main 的 NOBLE_BLE_WRITE 从 150 起就收第三参,并 Number.isFinite + floor + clamp 到 [0, 1000]。preload 补上转发后,这条链才通。旧的两参数 handler 会忽略多余 IPC 参数,版本错位最多回到今天的慢写,不会炸。

未发现密钥/PII 泄漏、鉴权绕过、或 import hierarchy 破坏。options 多出来的字段 main 不会读;恶意渲染进程本来就能反复 write,节流参数不新增能力。DApp webview 共用 preload 是既有问题,这次没有加重。

测试建议

  1. Desktop BLE + Pro2 / V2:固件或资源传输,确认不再是每包 5ms。
  2. Desktop BLE + Classic / V1:签名、小包通信,确认默认 pacing 还在。
  3. rebase 之后回归 fix: detect hardware disconnect on desktop USB and BLE (OK-60486) #12942 的 USB/BLE 断连检测,以及 onDeviceDisconnected.reason
  4. 不要把「IPC handler 存在」当成通过;要看实际传输耗时和设备是否仍稳定。

Affects: Desktop(preload);rebase 前的 SDK bump 还会碰到所有平台。
Does NOT affect: 其它平台上的这条 write-options 路径。

本次是只读审查,没有改代码,也没有往 PR 上留 comment。需要的话我可以 rebase 到 hotfix(pin ≥162,只留两个代码文件)并更新 PR 描述。

Open in Web Open in Cursor 

Comment thread package.json Outdated
@originalix
originalix force-pushed the fix/desktop-ble-preload-write-options branch 3 times, most recently from eb9bce4 to 849d35c Compare August 21, 2026 03:18
@originalix
originalix force-pushed the fix/desktop-ble-preload-write-options branch from 849d35c to 3a94b42 Compare August 21, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants