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(scheduler): 保留空权威终稿的撤回语义

Dashf0875a6fe233
diff --git a/apps/desktop/src/main/scheduler-host/__tests__/runnerSilentNotify.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/runnerSilentNotify.test.ts
index 5196fc3bfa..129e3ffe44 100644
--- a/apps/desktop/src/main/scheduler-host/__tests__/runnerSilentNotify.test.ts
+++ b/apps/desktop/src/main/scheduler-host/__tests__/runnerSilentNotify.test.ts
@@ -261,10 +261,10 @@ describe('MakerScheduleRunner silent-run notification skip', () => {
const { runner, notifier } = createRunnerHarness(h.session, { silenced: true });
const pending = runner.fire(baseSchedule({ silentWhenIdle: true }), createFireContext());
await vi.waitFor(() => expect(mocks.createMessage).toHaveBeenCalled());
- h.emit({ type: 'text', data: { text: 'Checking the PR.', isFinal: true, phase: 'commentary' } });
+ h.emit({ type: 'text', source: 'codex', data: { text: 'Checking the PR.', isFinal: true, isFullText: true, phase: 'commentary' } });
// Codex emits the empty final item, then done falls back to its last
// nonempty assistant item. That commentary already belongs to the transcript.
- h.emit({ type: 'text', data: { text: emptyFinal, isFinal: true, phase: 'final_answer' } });
+ h.emit({ type: 'text', source: 'codex', data: { text: emptyFinal, isFinal: true, isFullText: true, phase: 'final_answer' } });
h.emit({ type: 'done', data: { result: 'Checking the PR.' } });
await expect(pending).resolves.toMatchObject({ resultText: 'Checking the PR.' });
expect(mocks.createMessage.mock.calls.filter(([, body]) => body.role === 'assistant')).toHaveLength(0);
@@ -272,6 +272,23 @@ describe('MakerScheduleRunner silent-run notification skip', () => {
},
);
+ it.each([false, true])('honors an empty authoritative final after deltas (codex=%s)', async (codex) => {
+ const h = createSessionHarness(acceptingSend());
+ const { runner, notifier } = createRunnerHarness(h.session, { silenced: false });
+ const pending = runner.fire(baseSchedule(), createFireContext());
+ await vi.waitFor(() => expect(mocks.createMessage).toHaveBeenCalled());
+ const source = codex ? 'codex' as const : undefined;
+ if (codex) {
+ h.emit({ type: 'text', source, data: { text: 'Earlier commentary', isFinal: true, isFullText: true, phase: 'commentary' } });
+ }
+ h.emit({ type: 'text', source, data: { text: 'Retracted partial', phase: 'final_answer' } });
+ h.emit({ type: 'text', source, data: { text: '', isFinal: true, isFullText: true, phase: 'final_answer' } });
+ h.emit({ type: 'done', data: {} });
+ await expect(pending).resolves.toMatchObject({ resultText: undefined });
+ expect(mocks.createMessage.mock.calls.filter(([, body]) => body.role === 'assistant')).toHaveLength(0);
+ expect(JSON.stringify(notifier.notify.mock.calls)).not.toContain('Retracted partial');
+ });
+
it.each(
[true, false].flatMap((silenced) =>
['result', 'finalText'].map((field) => ({ silenced, field })),
diff --git a/apps/desktop/src/main/scheduler-host/runner.ts b/apps/desktop/src/main/scheduler-host/runner.ts
index 6d75265f2b..4ed3cf6b81 100644
--- a/apps/desktop/src/main/scheduler-host/runner.ts
+++ b/apps/desktop/src/main/scheduler-host/runner.ts
@@ -3003,6 +3003,7 @@ export class MakerScheduleRunner implements ScheduleRunner {
const sessionId = initialSession.id;
let assistantText = '';
let finalTextMatchesStream = false;
+ let lastTextWasCodexCommentary = false;
let stopped = false;
let stopListeningTurn: (() => void) | undefined;
const turnFinished = new Promise<void>((resolve, reject) => {
@@ -3102,12 +3103,20 @@ export class MakerScheduleRunner implements ScheduleRunner {
return;
}
if (ev.type === 'text') {
- const data = ev.data as { text?: string; isFinal?: boolean } | null;
+ const data = ev.data as {
+ text?: string; isFinal?: boolean; isFullText?: boolean; phase?: string;
+ } | null;
if (data && typeof data.text === 'string') {
- // Empty final items do not replace a visible transcript message.
- // Codex's done may fall back to its last nonempty commentary; keep
- // that streamed text so finalizeRun does not persist it a second time.
- if (data.isFinal && !data.text.trim()) return;
+ // Only Codex's separate empty answer after completed commentary
+ // leaves that commentary intact. Empty replacements after deltas
+ // must still retract the partial result, matching the transcript.
+ const emptyCodexAnswer = lastTextWasCodexCommentary
+ && ev.source === 'codex' && data.phase === 'final_answer'
+ && data.isFinal === true && data.isFullText === true && !data.text.trim();
+ lastTextWasCodexCommentary = ev.source === 'codex'
+ && data.phase === 'commentary' && data.isFinal === true
+ && data.isFullText === true && !!data.text.trim();
+ if (emptyCodexAnswer) return;
if (data.text.trim()) finalTextMatchesStream = true;
if (data.isFinal) assistantText = data.text;
else assistantText += data.text;