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: 取消提问卡片录音时结束提交等待

Dash566225d68c9a
diff --git a/apps/desktop/src/renderer/__tests__/useAskUserDictation.test.tsx b/apps/desktop/src/renderer/__tests__/useAskUserDictation.test.tsx
index 5918234ac1..7de9aef369 100644
--- a/apps/desktop/src/renderer/__tests__/useAskUserDictation.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/useAskUserDictation.test.tsx
@@ -44,7 +44,8 @@ describe('useAskUserDictation', () => {
// Unit: real hook, delayed readiness/IPC. Existing coverage only delivered
// transcripts after startup; it missed lost opening words and late captures
- // continuing after Escape/unmount in the question answer field.
+ // continuing after Escape/unmount in the question answer field. PR #7438:
+ // submitting before startup settles must also unlock when cancelled.
it.each(['cancel', 'unmount'] as const)('captures before readiness and ignores a late service start after %s', async (action) => {
let onEvent: ((event: VoiceInputRendererEvent) => void) | undefined;
let check!: (value: Awaited<ReturnType<typeof resolveVoiceInputStartGuards>>) => void;
@@ -73,6 +74,9 @@ describe('useAskUserDictation', () => {
expect(start).toHaveBeenCalledOnce();
act(() => onEvent?.({ type: 'draft', runId: 'late-run', text: '未提交语音', source: 'partial' } as VoiceInputRendererEvent));
expect(hook.result.current.liveText).toBe('已有未提交语音回答');
+ let stopped: boolean | undefined;
+ await act(async () => { void hook.result.current.stop().then((ok) => { stopped = ok; }); });
+ expect(stopped).toBeUndefined();
if (action === 'cancel') {
await act(async () => { await hook.result.current.cancel(); });
expect(hook.result.current.isBusy).toBe(false);
@@ -80,6 +84,8 @@ describe('useAskUserDictation', () => {
} else {
hook.unmount();
}
+ await act(async () => {});
+ expect(stopped).toBe(false);
await act(async () => { connected({ ok: true, runId: 'late-run' }); });
act(() => onEvent?.({ type: 'submitted', runId: 'late-run', text: '迟到的结果' } as VoiceInputRendererEvent));
expect(cancel).toHaveBeenCalledWith({ runId: 'late-run' });
diff --git a/apps/desktop/src/renderer/components/new-chat/useAskUserDictation.ts b/apps/desktop/src/renderer/components/new-chat/useAskUserDictation.ts
index bb0283d503..f1e48354bb 100644
--- a/apps/desktop/src/renderer/components/new-chat/useAskUserDictation.ts
+++ b/apps/desktop/src/renderer/components/new-chat/useAskUserDictation.ts
@@ -418,12 +418,14 @@ export function useAskUserDictation(
setVoiceState('submitting');
const stopping = (async () => {
try {
+ const completion = completionRef.current;
// Capture may already be live while the service is connecting. Stop it
// before awaiting startup so post-press speech is not included.
await stopEngine();
- await startReadyRef.current;
+ // Cancellation/unmount settles completion even if startup IPC has not
+ // returned. Release the submitter now; startup still cancels a late run.
+ await (completion ? Promise.race([startReadyRef.current, completion.promise]) : startReadyRef.current);
if (attemptRef.current !== attempt) return false;
- const completion = completionRef.current;
const settings = getVoiceInputSettings();
if (settings.playInteractionSound) playVoiceInputEndCue();
// Also release an engine whose startup finished after the first stop.