Skip to content

fix(conversation): validate type field before creating conversation#1921

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

fix(conversation): validate type field before creating conversation#1921
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-FP

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • Sentry issue: ELECTRON-FP — Error: Invalid conversation type: undefined (10 events, actively occurring)
  • Add early validation for params.type in the conversation create bridge handler to prevent unhandled rejections when WebSocket clients send params without the required type field
  • Log descriptive error with params before throwing for debugging

Closes #1920

Test plan

  • Added test for undefined type in ConversationServiceImpl
  • All 11 ConversationServiceImpl tests pass
  • Lint, format, type check all pass
  • Verify ELECTRON-FP occurrence rate drops after deploy

Add early validation for the `type` field in the conversation create
bridge handler to prevent unhandled rejections when WebSocket clients
send params without a required `type` field.

Fixes ELECTRON-FP
@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 30, 2026 08:17
@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(conversation): validate type field before creating conversation (#1921)

变更概述

本 PR 针对 Sentry 问题 ELECTRON-FP(Error: Invalid conversation type: undefined),在 conversationBridge.tsconversation.create IPC handler 中增加了对 params.type 的前置验证,并在 ConversationServiceImpl.test.ts 中补充了对应的 undefined type 测试用例。


方案评估

结论:✅ 方案合理

在 IPC bridge 层增加早期验证是正确的防御措施,防止无效参数到达 service 层引发未处理 rejection。现有 ConversationServiceImpl 通过 switch-default 抛出 Invalid conversation type: undefined,bridge 层新增的 guard 作为额外保护层。方案与项目现有的 bridge handler 错误处理模式一致。


问题清单

🔵 LOW — 新增测试未覆盖 bridge-level guard

文件tests/unit/ConversationServiceImpl.test.ts,第 146–152 行

问题代码

it('throws for undefined conversation type (ELECTRON-FP)', async () => {
  const repo = makeRepo();
  const svc = new ConversationServiceImpl(repo);
  await expect(svc.createConversation({ type: undefined as any, model: {} as any, extra: {} })).rejects.toThrow(
    'Invalid conversation type'
  );
});

问题说明:此测试覆盖的是 ConversationServiceImpl.createConversation 的既有 switch-default 行为(抛出 Invalid conversation type: undefined),并非 PR 本次新增的 bridge guard(抛出 Missing required field "type")。本次实际修复的代码路径(conversationBridge.ts 第 106–108 行)没有对应的单元测试覆盖。这是现有项目架构对 bridge 层难以单独测试的局限,属于已知约束,不阻塞合并。

修复建议:可在 PR 描述中注明 "bridge guard 层因依赖 IPC mock 复杂度暂不添加单元测试",并考虑在未来为 bridge 层补充集成测试。


🔵 LOW — console.error 记录完整 params 可能含非必要信息

文件src/process/bridge/conversationBridge.ts,第 107 行

问题代码

console.error('[conversationBridge] Missing required field "type" in create params:', params);

问题说明params 完整记录可能包含 modelextra 等字段(其中 extra.workspace 等路径信息),与文件其他错误日志选择性记录字段的风格略有差异(如 /btw 错误日志只记录 conversationIderror.message)。对于此处调试场景,完整 params 有助于复现问题,影响可忽略。

修复建议(可选):保持现状即可,或改为只记录 { type: params.type } 减少日志噪音。


汇总

# 严重级别 文件 问题
1 🔵 LOW tests/unit/ConversationServiceImpl.test.ts:146 新增测试覆盖的是既有 service 行为而非新增的 bridge guard
2 🔵 LOW src/process/bridge/conversationBridge.ts:107 console.error 记录完整 params,与文件其他日志风格略有差异

结论

批准合并 — 仅有两个 LOW 级别的小问题,不阻塞合并。bridge guard 的修复逻辑正确,测试覆盖了 service 层防线,CI 全部通过。


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

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 30, 2026

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

@piorpua piorpua merged commit 448a7aa into main Mar 30, 2026
13 checks passed
@piorpua piorpua deleted the fix/sentry-ELECTRON-FP branch March 30, 2026 10:08
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 30, 2026
wuhao1477 added a commit to wuhao1477/AionUi that referenced this pull request Mar 30, 2026
* 'main' of github.com:wuhao1477/AionUi: (40 commits)
  fix(agents): prevent unhandled promise rejection in bootstrap initialization (iOfficeAI#1933)
  fix(gemini): restore context after stopping a reply (iOfficeAI#1932)
  fix(codex): reject start promise immediately on process exit during startup (iOfficeAI#1929)
  fix(conversation): sync renamed titles with detail view (iOfficeAI#1927)
  fix(paste): deduplicate filenames when pasting multiple images simultaneously
  fix(mobile): add SafeArea support and update app icon (iOfficeAI#1926)
  fix(database): guard against undefined params in databaseBridge providers (iOfficeAI#1924)
  fix(conversation): validate type field before creating conversation (iOfficeAI#1921)
  fix(docs): restore wechat_group_5.png reference to wx-5.png in readme
  fix(snapshot): add maxBuffer to git add/commit exec calls (iOfficeAI#1914)
  refactor(acp): consolidate AGENT_SKILLS_DIRS into ACP_BACKENDS_ALL (iOfficeAI#1913)
  fix(gemini): guard against EACCES in workspace realpath during init (ELECTRON-BM) (iOfficeAI#1912)
  fix(channels): send raw QR ticket instead of page URL in WeChat WebUI login SSE (iOfficeAI#1910)
  .md format
  chore(pr-automation): fix missed sleep 5 in comment to sleep 10
  chore(pr-automation): increase auto-merge retry delay to 10s
  chore(pr-automation): add 5s retry for transient GitHub mergeStateStatus UNKNOWN
  fix(docs): remove trailing whitespace in OfficeCLI readmes
  chore(pr-automation): verify auto-merge success before labeling bot:done
  fix(snapshot): guard against non-existent workspace in WorkspaceSnapshotService.init (iOfficeAI#1906)
  ...
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.

fix: unhandled rejection when conversation type is undefined (ELECTRON-FP)

2 participants