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(bots): keep runtime recovery text classified as commentary

zqchrise31138965461
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
index f6c5d8dd2a..cd10158499 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
@@ -699,6 +699,13 @@ describe('makerChatStore text delta batching', () => {
assertRows();
});
+ it('keeps runtime recovery commentary hidden even when the provider marks it final', () => {
+ onEvent?.({ sessionId: SESSION_ID, persistId: 'recovery-note', event: { type: 'text', source: 'codex',
+ data: { text: 'Internal recovery', isFinal: false, phase: 'final_answer', runtimeRecovery: true } } });
+ vi.advanceTimersByTime(32);
+ expect(makerChatStore.getSnapshot(SESSION_ID).messages[0]).toMatchObject({ assistantPhase: 'commentary' });
+ });
+
it('preserves provider final phase through text batching before a turn completes', () => {
for (const text of ['First ', 'words']) onEvent?.({ sessionId: SESSION_ID, persistId: 'phase-answer',
event: { type: 'text', source: 'codex', data: { text, isFinal: false, phase: 'final_answer' } } });
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 504792eb63..6d763de954 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -5582,6 +5582,10 @@ export function handleStreamEvent(
// - model / parentUuid 让纯文本子代理在 streaming 阶段也能反查模型 chip;
// - turnCompleted 由 main 在 done 边界盖到该 SDK turn 的最后一条 assistant 上,
// 让后台任务自动续跑时前一轮正式总结不会被后续补充回复顶掉。
+ const phaseData = event.data as { phase?: unknown; runtimeRecovery?: boolean } | undefined;
+ const assistantPhase = phaseData?.runtimeRecovery === true
+ ? 'commentary'
+ : typeof phaseData?.phase === 'string' ? phaseData.phase : incomingMeta?.assistantPhase;
const assistantMetaFields: {
botPrivateReply?: boolean;
assistantPhase?: string;
@@ -5589,9 +5593,7 @@ export function handleStreamEvent(
parentToolUseId?: string;
turnCompleted?: boolean;
} = {
- ...(typeof (event.data as { phase?: unknown })?.phase === 'string'
- ? { assistantPhase: (event.data as { phase: string }).phase }
- : typeof incomingMeta?.assistantPhase === 'string' ? { assistantPhase: incomingMeta.assistantPhase } : {}),
+ ...(typeof assistantPhase === 'string' ? { assistantPhase } : {}),
...(typeof incomingMeta?.model === 'string' && incomingMeta.model
? { model: incomingMeta.model }
: {}),
@@ -7597,7 +7599,8 @@ function enqueueTextDeltaPayload(
ingress: LiveIngressContext = {},
): void {
if (!event) return;
- const data = event.data as { text?: unknown };
+ const data = event.data as { text?: unknown; phase?: unknown; runtimeRecovery?: boolean };
+ const phase = data.runtimeRecovery === true ? 'commentary' : typeof data.phase === 'string' ? data.phase : undefined;
const text = typeof data.text === 'string' ? data.text : '';
const dataOwner = getDataOwnerGeneration();
let existing = pendingTextDeltaBatches.get(sessionId);
@@ -7618,9 +7621,7 @@ function enqueueTextDeltaPayload(
if (!existing.persistId && persistId) existing.persistId = persistId;
if (event.source) existing.source = event.source;
if (event.agentMeta) existing.agentMeta = { ...existing.agentMeta, ...event.agentMeta };
- if (typeof (event.data as { phase?: unknown }).phase === 'string') {
- existing.agentMeta = { ...existing.agentMeta, assistantPhase: (event.data as { phase: string }).phase };
- }
+ if (phase) existing.agentMeta = { ...existing.agentMeta, assistantPhase: phase };
} else {
pendingTextDeltaBatches.set(sessionId, {
text,
@@ -7628,10 +7629,7 @@ function enqueueTextDeltaPayload(
ingress,
source: event.source,
persistId,
- agentMeta: { ...event.agentMeta,
- ...(typeof (event.data as { phase?: unknown }).phase === 'string'
- ? { assistantPhase: (event.data as { phase: string }).phase } : {}),
- },
+ agentMeta: { ...event.agentMeta, ...(phase ? { assistantPhase: phase } : {}) },
});
}
scheduleTextDeltaFlush();