codex@macbookpro
·
2026-03-30
BUG-029-find-link-by-remote-ignores-is-active.md
1# BUG-029: findConversationLinkByRemoteConversation 未过滤 is_active,续命可能打到已放弃的对话
2
3> 提交者:Claude
4> 日期:2026-03-30
5
6## 现象
7
8`observeRenewalConversation` 在解析已有对话关联时,优先通过 `findConversationLinkByRemoteConversation` 按 `platform + remote_conversation_id` 查找 link。该方法不过滤 `is_active`,会返回已被 deactivate 的 link。
9
10后续流程用这个 link 的 `localConversationId` 去关联新消息,导致续命消息被打到一个已经被主动放弃的旧对话上。
11
12## 触发路径
13
14```text
151. 用户在某平台创建对话 A,observe 写入 link_1 (remote_conversation_id=X, is_active=1)
162. 用户在 UI 上切换对话 / deactivate,link_1 被设为 is_active=0
173. 新消息到达同一 remote_conversation_id=X
184. observeRenewalConversation -> resolveExistingConversationLink
19 -> findConversationLinkByRemoteConversation(platform, X)
20 -> 返回 link_1(is_active=0)
215. 流程用 link_1.localConversationId 关联新消息 -> 续命打到旧对话
22```
23
24## 根因
25
26`packages/artifact-db/src/store.ts` 中 `findConversationLinkByRemoteConversation` 的 SQL 只有:
27
28```sql
29SELECT *
30FROM conversation_links
31WHERE platform = ?
32 AND remote_conversation_id = ?
33LIMIT 1;
34```
35
36缺少 `AND is_active = 1` 条件。
37
38## 修复建议
39
40在查询中加入 `AND is_active = 1`:
41
42```sql
43SELECT *
44FROM conversation_links
45WHERE platform = ?
46 AND remote_conversation_id = ?
47 AND is_active = 1
48LIMIT 1;
49```
50
51如果存在需要查已停用 link 的场景,可加一个可选参数 `includeInactive?: boolean`。
52
53## 严重程度
54
55**High**
56
57这是数据正确性 bug,会导致续命自动化对错误的对话发消息,是必现的逻辑错误。
58
59## 发现时间
60
61`2026-03-30 by Claude`
62
63## 相关代码
64
65- 查询方法:[packages/artifact-db/src/store.ts](/Users/george/code/baa-conductor/packages/artifact-db/src/store.ts) `findConversationLinkByRemoteConversation`
66- 调用方:[apps/conductor-daemon/src/renewal/conversations.ts](/Users/george/code/baa-conductor/apps/conductor-daemon/src/renewal/conversations.ts) `resolveExistingConversationLink`