Skip to content

fix(bridge): guard against undefined params in sendMessage provider#1909

Merged
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-FK
Mar 30, 2026
Merged

fix(bridge): guard against undefined params in sendMessage provider#1909
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-FK

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • Guard against undefined params in ipcBridge.conversation.sendMessage.provider callback
  • WebSocket messages without a data payload (e.g. bypassPermissions) cause TypeError: Cannot destructure property 'conversation_id' of 'undefined'
  • Returns { success: false, msg: 'Missing request parameters' } instead of crashing

Sentry Issue

ELECTRON-FK — 85 events in 1 day, escalating

  • Error: TypeError: Cannot destructure property 'conversation_id' of 'undefined' as it is undefined.
  • Culprit: src/process/bridge/conversationBridge.ts:397 (sendMessage.provider)
  • Affected release: [email protected]

Root Cause

The WebSocketManager parses incoming messages as { name, data }. When a message has a valid name but no data field, data is undefined. This flows through adapter.ts@office-ai/platform bridge → sendMessage.provider callback, where destructuring { conversation_id, files, ...other } from undefined throws a TypeError.

Fix

Add a null/undefined check at the top of the provider callback before destructuring.

Test Plan

  • Unit test: undefined params returns error response
  • Unit test: null params returns error response
  • Unit test: valid params proceeds normally
  • bunx tsc --noEmit passes
  • bun run lint:fix — no errors
  • bun run test — all relevant tests pass (pre-existing previewFileWatch.dom.test.ts failures unrelated)

WebSocket messages without a data payload cause TypeError when
destructuring conversation_id from undefined. Add null check
before destructuring to return a graceful error response.

Fixes ELECTRON-FK
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 30, 2026 07:13
@piorpua piorpua added the bot:reviewing Review in progress (mutex) label Mar 30, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 30, 2026

Code Review:fix(bridge): guard against undefined params in sendMessage provider (#1909)

变更概述

此 PR 修复了 Sentry 高频错误 ELECTRON-FK(1天85次):WebSocketManager 解析到无 data 字段的消息时,dataundefined,在 sendMessage.provider 回调中解构时崩溃。修复方案是在解构前添加 null/undefined 守卫,并新增了专项测试文件覆盖该场景。


方案评估

结论:✅ 方案合理

修复精准、最小侵入,!params 守卫同时覆盖 nullundefined,返回结构与文件中其他错误返回一致。修复位置(callback 入口处)正确,未引入不必要的抽象。测试文件结构合理,通过捕获 provider 回调的方式隔离了依赖,无需启动完整进程环境。


问题清单

🔵 LOW — 测试 mock 使用 as any 产生 lint 警告

文件tests/unit/process/bridge/conversationBridge.sendMessage.test.ts,第 100、106 行

问题代码

} as any;

问题说明:oxlint 报告 2 个 no-explicit-any 警告,建议替换为具体类型或 unknown。虽然在测试文件中影响有限,但与项目 lint 规则不符。

修复建议

// 方式一:使用具体类型(如已有 IConversationService、IWorkerTaskManager 接口)
const mockConversationService = {
  ...
} satisfies IConversationService;

// 方式二:临时 unknown 强转(最小改动)
} as unknown as IConversationService;

汇总

# 严重级别 文件 问题
1 🔵 LOW conversationBridge.sendMessage.test.ts:100,106 as any lint 警告

结论

批准合并 — 无阻塞性问题

修复逻辑正确,测试覆盖了触发 Sentry 的核心路径,仅有 2 处测试文件的 lint 警告(LOW),不阻塞合并。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

CONCLUSION: APPROVED
IS_CRITICAL_PATH: false
PR_NUMBER: 1909

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 30, 2026

✅ 已自动 review,无阻塞性问题,正在触发自动合并。

@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 30, 2026
@piorpua piorpua merged commit 864624a into main Mar 30, 2026
17 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-FK branch March 30, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants