Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 对账不误判 legacy transcript 父 id;读排在持久化 FIFO 之后

Kafeifei2d6c3ad2f847
diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.ts
index b3f3f9b86b..22802f81fc 100644
--- a/apps/desktop/src/main/im/shared/turnRunner.ts
+++ b/apps/desktop/src/main/im/shared/turnRunner.ts
@@ -105,6 +105,7 @@ import { agentHandoffPending } from '../../maker-ipc/agentHandoffPendingSingleto
import { prependHandoffToUserMessage, prependNoteToWireUserMessage } from '../../maker-ipc/agentHandoff';
import { buildPlanReconcileNote, summarizeOpenPlan } from '../../maker-ipc/planReconcile';
import { listMessagesForAgentHandoff } from '../../localDb/ipc/messages';
+import { enqueueDurableWrite } from '../../messagePersistBroadcaster';
import {
cancelPending,
registerPending,
@@ -884,7 +885,11 @@ export function createTurnRunner(
// 读库失败静默跳过,不挡发送。
const planReconcileNote = await (async () => {
try {
- const rows = await listMessagesForAgentHandoff(rowId, 1000);
+ // 与 register.ts 同口径:读排在持久化 FIFO 之后,不然会读到终态章/失败
+ // 印记尚未落库的旧快照(review P2)。
+ const rows = await enqueueDurableWrite(`plan-reconcile-read:${rowId}`, () =>
+ listMessagesForAgentHandoff(rowId, 1000),
+ );
const summary = summarizeOpenPlan(rows);
return summary ? buildPlanReconcileNote(summary) : null;
} catch {
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/planReconcile.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/planReconcile.test.ts
index 245bd00e9d..7ee858ce36 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/planReconcile.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/planReconcile.test.ts
@@ -89,6 +89,27 @@ describe('summarizeOpenPlan', () => {
).toBeNull();
});
+ it('still reconciles a top-level plan whose agent_meta carries a legacy transcript parent', () => {
+ // legacy Claude 导入把 transcript 链边(非 RFC 串)存进 agent_meta.parentUuid。
+ // 把裸字段一律提升成显式 parentToolUseId 会让它被判成子代理、顶层计划从对账里
+ // 消失,还与保留裸字段的 mobile 分叉(review P2)。
+ const legacyPlan: PlanReconcileCandidateRow = {
+ ...planRow([{ step: 'Open work', status: 'in_progress' }]),
+ agentMeta: { parentUuid: 'preceding-user-uuid' },
+ };
+ expect(summarizeOpenPlan([legacyPlan])).toEqual({
+ openSteps: ['Open work'],
+ totalSteps: 1,
+ });
+
+ // 真正的 SDK 子代理归属(toolu_ / call_ 形态)照旧过滤。
+ const subagentPlan: PlanReconcileCandidateRow = {
+ ...planRow([{ step: 'Subagent work', status: 'in_progress' }]),
+ agentMeta: { parentUuid: 'toolu_01AbCdEf' },
+ };
+ expect(summarizeOpenPlan([subagentPlan])).toBeNull();
+ });
+
it('reconciles only the latest plan session after a user turn boundary', () => {
const summary = summarizeOpenPlan([
planRow([{ step: 'Old abandoned', status: 'in_progress' }]),
diff --git a/apps/desktop/src/main/maker-ipc/planReconcile.ts b/apps/desktop/src/main/maker-ipc/planReconcile.ts
index 7d3ebfa84f..cea9a8efa3 100644
--- a/apps/desktop/src/main/maker-ipc/planReconcile.ts
+++ b/apps/desktop/src/main/maker-ipc/planReconcile.ts
@@ -42,15 +42,14 @@ function toRenderSourceMessage(row: PlanReconcileCandidateRow): MessageRenderSou
const toolName = typeof content?.toolName === 'string' ? content.toolName : undefined;
const toolInput = content?.input;
const toolUseId = typeof content?.toolUseId === 'string' ? content.toolUseId : undefined;
- // 子代理归属:Claude 子代理的 TodoWrite 行把父 id 持久化在 agent_meta.parentUuid
- // (messagePersistBroadcaster 写入),content 里没有;两处都认。
+ // 子代理归属:显式 parentToolUseId 才提升为 parentToolUseId 字段。裸
+ // agent_meta.parentUuid 原样带过去,由 maker-shared 的 hasSubagentParent 按
+ // SDK tool-parent 形态(toolu_ / call_)判定——legacy Claude 导入把 transcript
+ // 链边(preceding-user-uuid 这类非 RFC 串)也存在这个键上,一律提升会把顶层
+ // 计划误判成子代理并从对账里过滤掉,还与保留裸字段的 mobile 分叉(review P2)。
const meta = row.agentMeta ?? null;
const parentToolUseId =
- typeof content?.parentToolUseId === 'string'
- ? content.parentToolUseId
- : typeof meta?.parentUuid === 'string' && meta.parentUuid
- ? meta.parentUuid
- : undefined;
+ typeof content?.parentToolUseId === 'string' ? content.parentToolUseId : undefined;
return {
clientId: row.clientId,
role: row.role,
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index efc8c319a1..576ee68b1d 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -9834,7 +9834,14 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
// null → 本轮不注入——降级方向是"少提醒",不会误提醒,可接受;不做全量
// 分页回溯,避免每次发送为一个提示扫全历史。
peekPlanReconcileNote: async (sessionId) => {
- const rows = await listMessagesForAgentHandoff(sessionId, 1000);
+ // 读排在同一条持久化 FIFO 之后:终态章(persistCodexPlanOnDone)与失败印记
+ // 只是 enqueueWrite 入队,不等它们落库就查,会读到未盖章的旧快照 → 给已经
+ // 收口的计划多注入一次对账;反过来,全勾完但失败的计划可能因 turnCompleted:false
+ // 还没写进去而漏掉唯一的收口通道(review P2)。调用方对失败已经 catch 成 null,
+ // 队列被 app-session 边界打断时最多这一轮不注入。
+ const rows = await enqueueDurableWrite(`plan-reconcile-read:${sessionId}`, () =>
+ listMessagesForAgentHandoff(sessionId, 1000),
+ );
const summary = summarizeOpenPlan(rows);
return summary ? buildPlanReconcileNote(summary) : null;
},