feat(main-ai): migrate AI core to main backend#15326
Conversation
6b7882f to
9d1a527
Compare
d619d4d to
2f5815c
Compare
1d0ae00 to
32462a7
Compare
2f5815c to
d757342
Compare
32462a7 to
e52243f
Compare
d757342 to
98add12
Compare
|
Note This comment was translated by Claude. Ran a review with 5 specialized agents (code quality / silent failures / test coverage / type design / comments & docs) locally against PR HEAD 🚨 Critical — Must Fix in This PR1. Build Will Break:
|
3edb986 to
651b0fb
Compare
98add12 to
31a0c7e
Compare
93f20ab to
9eb9236
Compare
Signed-off-by: suyao <sy20010504@gmail.com>
9eb9236 to
8ba1704
Compare
Signed-off-by: suyao <sy20010504@gmail.com>
Signed-off-by: suyao <sy20010504@gmail.com>
Signed-off-by: suyao <sy20010504@gmail.com>
|
Note This comment was translated by Claude. Follow-up: Status Check After 4 CommitsUpdated HEAD to ✅ Fixed
❌ Unhandled Review ItemsCritical (Data Correctness / Test Coverage)
Important
Suggestion (Original List)
🆕 Author Proactively Fixed (Real Bugs Review Didn't Find)
|
| Dimension | Progress |
|---|---|
| Build/Compile (Critical #1-#3) | ✅ All fixed |
| Data Correctness (Critical #4-#6) | ❌ 0/3 |
| Test Coverage (Critical #7-#8) | ❌ 0/2 |
| Important 8 items | ❌ 7/8 untouched (only docs resolved via defer) |
| Type Design | ❌ Untouched |
| Author's newly discovered attach race + push refactor | ✅ Proactively fixed |
Suggestion: Build should pass now (locally verify pnpm build:check). But #4–#8 are data correctness + safety code without tests, unrelated to build — want to confirm if author plans to handle these in this PR or defer to follow-up? If the latter, opening a separate issue to track #4–#6 + #8's ToolApprovalRegistry tests would be appropriate.
Original Content
Follow-up: 4 个 commit 后状态核对
更新 HEAD 0a47d1dfb。逐项 verify 了之前 review 中所有 Critical/Important 的代码状态,记录如下。
✅ 已修复
| 项 | 解决方式 |
|---|---|
| Critical #1 SpanCacheService 路径不存在 | 加在 src/main/ai/observability/cache/SpanCacheService.ts,registry import 同步更新 |
Critical #2 src/main/services/agents/ 42 孤儿文件 |
全删 (git ls-tree 命中数 = 0) |
Critical #3 老 src/main/services/NodeTraceService.ts 重复 |
已删,只剩新位置的版本 |
Important docs 路径全错 + breaking-change introduced_in_pr: TBD |
通过 0a47d1dfb 把 9 份 docs/references/ai/*.md + 14 份 v2-refactor-temp/docs/ai/*-cluster.md 全部移出本 stack。✅ 合理 defer |
❌ 仍未处理的 review 项
Critical(数据正确性 / 测试覆盖)
- 非常棒,简洁,配置方便! #4
PersistenceListener静默吞 DB 持久化失败 —src/main/ai/streamManager/listeners/PersistenceListener.ts:123-131代码原样,catch 里仍然只logger.error+return。AiStreamManager收不到失败信号,WebContentsListener.onDone仍发{status:'success'}。 - 一些建议 #5 ClaudeCode
handleTruncationError死代码 —streamAdapter.ts:282定义 + 测试,但git grep handleTruncationError全树仍只命中定义和它自己的测试,无任何 runtime 调用方。ClaudeCodeRuntimeDriver.ts:231-234的 catch 仍直接eventQueue.push({type:'error'})。 - 总是出现连接错误,网络一切顺通 #6 Aborted stream 路径 —
AiStreamManager.ts:702-705外层launchLoop().catch(...)仍无signal.abortedfork(注释自己写的"Defensive funnel for sync throws")。runExecutionLoop内部对 abort 的 fork 是对的;只有streamText同步 reject 的路径会落到这里 — 触发概率不高,但语义不对的 case 仍存在。 - 功能建议 #7 reasoning 测试 —
src/main/ai/utils/__tests__/reasoning.test.ts仍不存在(git ls-tree | grep reasoning只命中源文件)。base 上的 2071+288 行覆盖未迁移。 - 功能建议 #8 ToolApprovalRegistry /
Ai_ToolApproval_Respond测试 —src/main/ai/__tests__/AiService.test.ts中grep -ci 'toolapproval\\|approvalrespond\\|Ai_ToolApproval'= 0;src/main/ai/runtime/claudeCode/__tests__/ToolApprovalRegistry.test.ts仍不存在。
Important
AiStreamRequest仍是 flat optionals —src/main/ai/types/requests.ts:43-52字段全 optional;runtime guardsrc/main/ai/AiService.ts:283"Agent session stream X requires an agent-session runtime request" 的 throw 仍存在,这是最高 leverage 的类型修复机会。ChannelAdapter配置仍展平 —src/main/ai/channels/ChannelAdapter.ts:33channelConfig: Record<string, unknown>;src/main/ai/channels/ChannelManager.ts:18factory registry 仍 keyed bystring而非ChannelType。Ai_ToolApproval_Respond仍不返 blocked —src/main/ai/AiService.ts:247-252无视dispatchStreamRequest返回值直接return { ok: true }。dispatch.ts:69-72确认 dispatch 在isAgentSessionWorkspaceError时会返{mode:'blocked', reason:'agent-session-workspace'},该路径仍可触发 silent hang。ChannelAdapterListener.onTextUpdate仍.catch(() => {})—ChannelAdapterListener.ts:26原样,Slackchat.update429 / Feishu CardKit 错误仍无任何日志。approvalEmitter.dispose仍是死代码 —src/main/ai/runtime/claudeCode/settingsBuilder.ts:77定义,:188注释自己说 "drops any approval still pending for this session when the stream exits abnormally",但git grep dispose全 codebase 0 调用方。Pending approvals 仍会泄漏到 session 关闭。AgentSessionRuntimeService仍缺@DependsOn—:133类装饰器只有@Injectable + @ServicePhase,但:601-602通过application.get('ClaudeCodeTraceBridgeService')和application.get('ClaudeCodeWarmQueryManager')访问同 phase 服务。同 phase 无@DependsOn时容器按 register 顺序初始化 — latent race。AiService.@DependsOn(['AiStreamManager'])与注释矛盾 —:120仍含'AiStreamManager',而:114-116的注释 "DO NOT mirror@DependsOn(['AiService'])on AiStreamManager" 没有解释为什么单向反过来 OK。messages/fileProcessor.ts+messageConverter.ts:36仍 silent 丢附件 —messageConverter.ts:36改成else logger.warn('Dropped unresolved file part', ...)加了一行警告日志(感谢这个改进),但仍不替换为'data-error'part,LLM 无从知晓附件存在。
Suggestion(原列表)
Ai_GenerateText 仍无 abort registry / messageService.getById 仍 throw / 测试 mock 不一致 / SkillInstaller 备份回滚未测 — 全部未改。
🆕 作者主动修复的(review 没找到的真 bug)
9a21256b5 stream-manager replay tool input
修了一个 attach race:buildCompactReplay 之前直接 fallthrough 丢弃 tool-input-start,导致 attach 在 tool-input-available 之前发生时,renderer 收到的 tool-input-delta 找不到 toolCall part,reducer 卡死。
- case 'tool-input-start':
- case 'tool-input-delta':
+ case 'tool-input-start': {
+ // Preserve the part announcement — without it the renderer's chat
+ // reducer cannot apply subsequent live tool-input-delta chunks
flushPending()
+ compact.push(chunk)
+ break加了 delta 合并(连续相同 toolCallId 合并)、lastCompletedAt 字段、清理 isFulfilledCandidate 死字段、配套 +70 行 AiStreamManager.test.ts 和 +112 行 buildCompactReplay.test.ts。✅ 真 bug,真修,带测试。
9e6a3b075 topic-naming push events
把 SWR cache-version polling 改成 IPC push:加 Topic_AutoRenamed / AgentSession_AutoRenamed 两个新 IPC channel,WindowManager.broadcast 主动推。删掉 topic.cache_version / agent_session.cache_version 两个无用的 cache 字段。✅ 架构上更对。
总结
| 维度 | 进展 |
|---|---|
| Build/编译 (Critical #1-#3) | ✅ 全修 |
| 数据正确性 (Critical #4-#6) | ❌ 0/3 |
| 测试覆盖 (Critical #7-#8) | ❌ 0/2 |
| Important 8 项 | ❌ 7/8 未动(只 docs 通过 defer 解决) |
| 类型设计 | ❌ 未动 |
| 作者新发现的 attach race + push 重构 | ✅ 主动修了 |
建议:Build 应该现在能过了(本地 verify 一下 pnpm build:check)。但 #4–#8 是数据正确性 + 安全代码无测试,与 build 无关 — 想确认下作者计划在本 PR 处理这些,还是要推到 follow-up?如果是后者,把 #4–#6 + #8 的 ToolApprovalRegistry 测试单独开 issue 跟踪比较合适。
What this PR does
Before this PR:
AI execution was split between renderer-owned
aiCore, main-process services, MCP services, agent session code, message conversion, tracing, and transport glue.After this PR:
The AI runtime is consolidated under
src/main/ai, rendereraiCoremigration sources are removed, shared transport/types are introduced, DataApi/schema wiring is updated, and AI architecture documentation is included with the backend migration.Fixes # N/A
Why we need it and why it was done in this way
The following tradeoffs were made:
This PR is intentionally the largest stack layer because it preserves the reviewer focus on backend ownership and the renderer-to-main aiCore migration. Renderer consumer cleanup is deferred to the next PR.
The following alternatives were considered:
Splitting every
src/main/aicluster into separate PRs was considered, but that would make the renderer aiCore migration harder to review as one backend ownership change.Links to places where the discussion took place: N/A
Breaking changes
None for current released users. v2 refactor migration notes are included under
v2-refactor-temp/docs/breaking-changes/for tracking the in-progress v2 data/runtime transition.If this PR introduces breaking changes, please describe the changes and the impact on users.
Special notes for your reviewer
Stack PR 2/3. Base this review on the provider split PR. Please focus on
src/main/ai, the removedsrc/renderer/src/aiCoremigration sources, shared AI transport/types, DataApi/schema wiring, and the architecture docs indocs/references/aiandv2-refactor-temp/docs/ai.Checklist
This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.
/gh-pr-review,gh pr diff, or GitHub UI) before requesting review from othersRelease note