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(chat): 保留自动任务失败后的手动重试入口

Dashb72d315890c9
diff --git a/apps/desktop/src/renderer/__tests__/errorBannerCodexXaiAuth.test.tsx b/apps/desktop/src/renderer/__tests__/errorBannerCodexXaiAuth.test.tsx
index c9f5cb1306..de68a5f360 100644
--- a/apps/desktop/src/renderer/__tests__/errorBannerCodexXaiAuth.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/errorBannerCodexXaiAuth.test.tsx
@@ -1,6 +1,6 @@
// @vitest-environment jsdom
-import { cleanup, fireEvent, render, screen } from '@testing-library/react';
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { createElement } from 'react';
@@ -128,6 +128,42 @@ describe('ErrorBanner network retry guidance', () => {
describe('ErrorBanner overload guidance', () => {
const CAPACITY = 'Selected model is at capacity. Please try a different model.';
+ // Regression: a settled scheduler run drops its queue recovery to unblock the
+ // next fire. Manual continuation must still work without replaying that run.
+ it('continues a failed scheduled turn when the original retry target is gone', async () => {
+ const onRetry = vi.fn();
+ const onContinueAfterError = vi.fn(async () => {});
+ render(createElement(ErrorBanner, { error: CAPACITY, onRetry, onContinueAfterError }));
+ expect(screen.getByText('chat.errorBanner.overloadBusy')).toBeTruthy();
+ await act(async () => fireEvent.click(screen.getByTitle('chat.errorBanner.retryTitle')));
+ expect(onContinueAfterError).toHaveBeenCalledOnce();
+ expect(onRetry).not.toHaveBeenCalled();
+ });
+
+ it('keeps continuation single-flight and makes a failed send retryable again', async () => {
+ let reject!: (error: Error) => void;
+ const pending = new Promise<void>((_, no) => { reject = no; });
+ const onContinueAfterError = vi.fn(() => pending);
+ render(createElement(ErrorBanner, { error: CAPACITY, onRetry: vi.fn(), onContinueAfterError }));
+ const retry = screen.getByTitle('chat.errorBanner.retryTitle');
+ fireEvent.click(retry);
+ fireEvent.click(retry);
+ expect(onContinueAfterError).toHaveBeenCalledOnce();
+ await act(async () => reject(new Error('offline')));
+ expect(screen.getByText('chat.errorBanner.overloadBusy')).toBeTruthy();
+ expect((retry as HTMLButtonElement).disabled).toBe(false);
+ });
+
+ it.each([
+ { error: CAPACITY, isRecoverable: true },
+ { error: 'thread not found', agentKind: 'codex' as const },
+ ])('does not bypass running or configuration recovery gates: $error', (props) => {
+ render(createElement(ErrorBanner, {
+ ...props, onRetry: vi.fn(), onContinueAfterError: vi.fn(async () => {}),
+ }));
+ expect(screen.queryByTitle('chat.errorBanner.retryTitle')).toBeNull();
+ });
+
it('shows retry progress while the overload retry is still pending', () => {
render(createElement(ErrorBanner, {
error: `${CAPACITY} (auto-retry 2/4)`,
diff --git a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
index 2fc1fe09cf..5419447683 100644
--- a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
+++ b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
@@ -13,7 +13,7 @@ import { useProviders } from '@/hooks/useProviders';
* - Retry:只使用上层传入的 retryText。这里不能从 messages[] 里猜最后一条
* user,因为排队发送时 messages[] 里的 user 已经发给 agent 了;
* 猜错会把已发送内容再次塞回队列。
- * 找不到安全 retryText 时隐藏 Retry。
+ * 没有 retryText 时可由上层提供隐藏续跑入口,不猜测或重发旧消息。
* - Cancel:调用 onCancel(),让上层把 error 状态清掉(仅关掉横幅,不撤回任何东西)。
* - 远端 codex 401 / Missing bearer:识别为 auth.json 缺失,换上"同步登录态"按钮 +
* 友好文案。点击同步成功后 Retry 按钮重新出现,用户自行点击重发。
@@ -73,6 +73,8 @@ interface ErrorBannerProps {
toolLoop?: ToolLoopErrorDetails | null;
retryText?: string | null;
onRetry: (text: string) => void;
+ /** 已停止且有任务上下文,但无原始恢复记录:发送现有隐藏续跑指令。 */
+ onContinueAfterError?: () => Promise<void>;
onCancel?: () => void;
/** 仅当前可见且拥有键盘操作权的任务启用。 */
dismissOnEscape?: boolean;
@@ -137,6 +139,7 @@ export function ErrorBanner({
toolLoop,
retryText,
onRetry,
+ onContinueAfterError,
onCancel,
dismissOnEscape = false,
onSilentStopContinue,
@@ -396,9 +399,7 @@ export function ErrorBanner({
sameDay ? { timeStyle: 'short' } : { dateStyle: 'medium', timeStyle: 'short' },
).format(resumeDate);
})();
- // Retry 的显示条件与网络错误文案必须共用同一个判定。外部发起的 turn(例如
- // scheduler / goal)失败时没有安全的 recovery target,errorRetryText 会是 null;
- // 此时不能一边隐藏按钮,一边仍提示用户“点击重试”。
+ // 原始恢复记录优先;自动任务收口后可手动续跑。按钮与指引共用同一判定。
const isSilentStopExhausted = errorReason === 'silent-stop-exhausted';
const isClaudeGatewayOpusPlanMismatch = errorReason === CLAUDE_GATEWAY_OPUS_PLAN_MISMATCH_REASON;
const isClaudeSubscriptionOpusPlanMismatch =
@@ -421,6 +422,28 @@ export function ErrorBanner({
openAiReconnectRequired ||
isCodexLocalOAuthAuthMissing;
const safeRetryText = !hideRetry && retryText ? retryText : null;
+ const retryAction = safeRetryText
+ ? () => onRetry(safeRetryText)
+ : !hideRetry && !isRecoverable ? onContinueAfterError : undefined;
+ const retryInFlight = useRef(false);
+ const [retrying, setRetrying] = useState(false);
+ const handleRetry = async () => {
+ if (!retryAction || retryInFlight.current) return;
+ if (safeRetryText) {
+ onRetry(safeRetryText);
+ return;
+ }
+ retryInFlight.current = true;
+ setRetrying(true);
+ try {
+ await retryAction();
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : String(err));
+ } finally {
+ retryInFlight.current = false;
+ setRetrying(false);
+ }
+ };
const [switchingClaudeSubscription, setSwitchingClaudeSubscription] = useState(false);
useEffect(() => {
setSwitchingClaudeSubscription(false);
@@ -524,12 +547,12 @@ export function ErrorBanner({
attempt: overloadRetryProgress.attempt,
maxAttempts: overloadRetryProgress.maxAttempts,
})
- : t(safeRetryText ? 'chat.errorBanner.overloadBusy' : 'chat.errorBanner.overloadBusyNoRetry');
+ : t(retryAction ? 'chat.errorBanner.overloadBusy' : 'chat.errorBanner.overloadBusyNoRetry');
} else if (isStreamInterrupted) {
// LiteLLM / Responses 流中途空壳 500。协议客户端会写成 OpenAI API error,
// 对非 OpenAI 模型是误导。只改展示,不自动续跑。
displayError = t(
- safeRetryText
+ retryAction
? 'chat.errorBanner.streamInterrupted'
: 'chat.errorBanner.streamInterruptedNoRetry',
);
@@ -546,7 +569,7 @@ export function ErrorBanner({
})
: t('chat.errorBanner.networkAutoRetrying')
: t(
- safeRetryText
+ retryAction
? 'chat.errorBanner.networkUnreachable'
: 'chat.errorBanner.networkUnreachableNoRetry',
);
@@ -820,12 +843,13 @@ export function ErrorBanner({
{t('chat.errorBanner.usageLimitAutoContinueCancel')}
</Button>
)}
- {safeRetryText && (
+ {retryAction && (
<Button
size="sm"
compact
disabled={forkStripEncryptedRunning}
- onClick={() => onRetry(safeRetryText)}
+ loading={retrying}
+ onClick={() => void handleRetry()}
title={t('chat.errorBanner.retryTitle')}
>
<RotateCcw size={12} />
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
index e862738dc0..28066c1e7e 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
@@ -8,6 +8,7 @@ import { BotFollowUpInvitation } from '@/features/bots/BotFollowUpInvitation';
import { formatSessionDuration } from '@/lib/sessionDurationFormat';
import { shouldShowOpenPathError } from '../../../shared/openPathResult';
import { shouldShowFailedScheduleNotice } from '@cindy/maker-shared/schedule-model';
+import { canContinueFailedTurn } from '@cindy/maker-shared/synthetic-trigger';
/**
* CCAgentSessionView
* ---------------------------------------------------------------------------
@@ -4635,6 +4636,20 @@ function CCAgentSessionContent({
continueAfterSilentStop();
}, [continueAfterSilentStop]);
+ const canContinueError = canContinueFailedTurn({
+ error,
+ retryText: errorRetryText,
+ running: isAgentBusy || errorIsRecoverable || !!credentialSwitchWait || syntheticContinuationPending,
+ hasUserInput: !!error && messages.some((message) => message.role === 'user'),
+ });
+ const handleContinueAfterError = useCallback(async () => {
+ if (!sessionId || !canContinueError || isHistoryRecoveryPending()) return;
+ invalidateHistoryRecoveryNavigation();
+ await rebuildClaudeSubscriptionSessionBeforeRetry(errorReason);
+ await makerChatStore.sendUiTrigger(sessionId, CONTINUE_AFTER_ERROR_PROMPT);
+ }, [canContinueError, errorReason, invalidateHistoryRecoveryNavigation, isHistoryRecoveryPending,
+ rebuildClaudeSubscriptionSessionBeforeRetry, sessionId]);
+
// 点击 Cancel 关闭报错 banner 同样是处置(用户选择不管它了)。
const handleDismissError = useCallback(() => {
if (sessionId) ackErrorAlertHandled(sessionId);
@@ -5766,6 +5781,7 @@ function CCAgentSessionContent({
isRecoverable={errorIsRecoverable}
retryText={errorRetryText}
onRetry={handleRetry}
+ onContinueAfterError={canContinueError ? handleContinueAfterError : undefined}
onSilentStopContinue={handleSilentStopContinue}
usageLimitWait={usageLimitWait}
onCancelUsageLimitWait={cancelUsageLimitWait}
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index 1aa35f5e92..0f4a6fa9f1 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -462,6 +462,7 @@ import { canOfferCodexHistoryRecovery } from '@cindy/maker-shared/error-redactio
import {
CONTINUE_AFTER_APP_EXIT_PROMPT,
CONTINUE_AFTER_ERROR_PROMPT,
+ canContinueFailedTurn,
} from '@cindy/maker-shared/synthetic-trigger';
import {
ComposerResizeGrabber,
@@ -7987,6 +7988,26 @@ function SessionScreenContent({ beforeSessionSwitchRef, newSessionActionRef }: S
void runQueueAction(() => maker.input.retryLastError(sessionId));
};
+ const canContinueError = canContinueFailedTurn({
+ error: inputProjection.error,
+ retryText: inputProjection.errorRetryText,
+ running: isSessionStreaming || inputProjection.queueAbortPending
+ || !!inputProjection.credentialSwitchWait || inputProjection.pendingQueue.length > 0
+ || settlingItemsForRender.length > 0,
+ hasUserInput: !!inputProjection.error && messages.some((message) => message.role === 'user'),
+ });
+ const continueQueueError = () => {
+ if (!canContinueError || queueAvailabilityReason || isHistoryRecoveryPending()) return;
+ if (!currentSession || currentSession.cacheSeeded) {
+ setError(t('session.screen.sessionNotSyncedRetry'));
+ return;
+ }
+ invalidateHistoryRecoveryNavigation();
+ const queued = buildQueuedTextMessage(currentSession, CONTINUE_AFTER_ERROR_PROMPT);
+ queued.createOpts = { ...queued.createOpts, planMode: false };
+ void runQueueAction(() => maker.input.enqueue(sessionId, queued, { sendAtMs: Date.now() }));
+ };
+
const clearQueueError = () => {
if (queueAvailabilityReason) return;
void runQueueAction(() => maker.input.clearError(sessionId));
@@ -10516,6 +10537,7 @@ function SessionScreenContent({ beforeSessionSwitchRef, newSessionActionRef }: S
onCancelUsageLimitWait={cancelUsageLimitWait}
onResume={resumeQueue}
onRetryError={retryQueueError}
+ onContinueAfterError={canContinueError ? continueQueueError : undefined}
onDiagnose={canDiagnoseError ? handleDiagnoseError : undefined}
projection={inputProjection}
readOnlyReason={queueAvailabilityReason}
diff --git a/apps/mobile/src/__tests__/InlineQueueSection.test.tsx b/apps/mobile/src/__tests__/InlineQueueSection.test.tsx
index 202389b821..9ce1d18740 100644
--- a/apps/mobile/src/__tests__/InlineQueueSection.test.tsx
+++ b/apps/mobile/src/__tests__/InlineQueueSection.test.tsx
@@ -71,6 +71,23 @@ it('allows clearing an error without retry content', async () => {
await show({ projection: { ...projection, errorRetryText: null } });
expect(button('retry').disabled).toBe(true); expect(button('clearError').disabled).toBe(false);
});
+// Scheduler failures release the original recovery record. The real error UI
+// must activate the manual continuation callback while retaining its busy gate.
+it('continues a settled error without replaying its old scheduled input', async () => {
+ const onContinueAfterError = vi.fn();
+ const props = { projection: { ...projection, errorRetryText: null }, onContinueAfterError };
+ await show(props);
+ expect(button('retry').disabled).toBe(false);
+ await act(async () => button('retry').click());
+ expect(onContinueAfterError).toHaveBeenCalledOnce();
+ expect(retry).not.toHaveBeenCalled();
+ await show({ ...props, busy: true });
+ expect(button('retry').disabled).toBe(true);
+ await show({ onContinueAfterError });
+ await act(async () => button('retry').click());
+ expect(retry).toHaveBeenCalledOnce();
+ expect(onContinueAfterError).toHaveBeenCalledOnce();
+});
// Review #6347: the real error actions must announce in-flight work, separately
// from read-only disabling. Existing tests only checked activation, not VoiceOver
// state. Minimal input: busy=true with a recovery action; unit (RN props -> DOM).
diff --git a/apps/mobile/src/session/InlineQueueSection.tsx b/apps/mobile/src/session/InlineQueueSection.tsx
index 8bcbdc3785..d06081bd56 100644
--- a/apps/mobile/src/session/InlineQueueSection.tsx
+++ b/apps/mobile/src/session/InlineQueueSection.tsx
@@ -49,6 +49,8 @@ export interface InlineQueueSectionProps {
readOnlyReason?: string | null;
onResume(): void;
onRetryError(): void;
+ /** 无重发记录时,沿用隐藏续跑指令;有记录仍优先按原记录重试。 */
+ onContinueAfterError?(): void;
onClearError(): void;
/** 取消账号限额重置后的自动继续(只在投影带 usageLimitWait 时出现)。 */
onCancelUsageLimitWait?(): void;
@@ -64,6 +66,7 @@ export function InlineQueueSection({
readOnlyReason,
onResume,
onRetryError,
+ onContinueAfterError,
onClearError,
onCancelUsageLimitWait,
onDiagnose,
@@ -83,7 +86,7 @@ export function InlineQueueSection({
|| (busy ? t('message.queuePresentation.row.busy') : null);
const retryable = !requiresAgentErrorConfigurationChange(projection.error ?? '');
const retryDisabledReason = errorDisabledReason
- || (!projection.errorRetryText ? t('message.queue.noRetryContent') : null);
+ || (!projection.errorRetryText && !onContinueAfterError ? t('message.queue.noRetryContent') : null);
const localizedAgentError = localizeAgentError(
projection.errorReason,
projection.toolLoop ?? null,
@@ -129,7 +132,7 @@ export function InlineQueueSection({
busy={busy}
hint={retryDisabledReason ?? undefined}
label={t('message.queue.retrySend')}
- onPress={onRetryError}
+ onPress={projection.errorRetryText ? onRetryError : (onContinueAfterError ?? onRetryError)}
testID="queue.inline.retryButton"
/> : null}
{onRecoverHistory ? <ReadableHistoryRecovery onRecover={onRecoverHistory} busy={busy} disabled={controlsDisabled} /> : null}
diff --git a/docs/product-rules/core-product-principles.md b/docs/product-rules/core-product-principles.md
index f4759c514b..1c822779a1 100644
--- a/docs/product-rules/core-product-principles.md
+++ b/docs/product-rules/core-product-principles.md
@@ -130,6 +130,12 @@ Cindy 应让用户方便地接入、选择和使用不同 Agent 与模型,同
归档不代表暂停自动任务,也不应仅因归档而另建替代任务;停止后续运行应使用自动任务的暂停入口。
删除目标以及伙伴、协作工作任务的服务侧生命周期仍遵循各自规则。
+自动任务失败后的调度收口,不应取消用户手动继续原任务的入口。原恢复记录已释放、
+任务已停止且有对话上下文时,桌面与手机复用隐藏续跑指令,从失败处继续;不重放旧
+调度、不阻塞下一次定时触发。认证或配置错误仍使用各自的恢复入口,续跑发送失败保留
+错误与重试操作。共同判据见 `packages/maker-shared/src/syntheticTrigger.ts` 的
+`canContinueFailedTurn`。
+
#### 目标模式与补充消息
目标运行期间,普通补充、问进度、排队消息与同轮插话优先处理,结束后继续原目标。
diff --git a/packages/maker-shared/src/__tests__/syntheticTrigger.test.ts b/packages/maker-shared/src/__tests__/syntheticTrigger.test.ts
index a8c84a6d9d..25b0ac5f39 100644
--- a/packages/maker-shared/src/__tests__/syntheticTrigger.test.ts
+++ b/packages/maker-shared/src/__tests__/syntheticTrigger.test.ts
@@ -6,9 +6,19 @@ import {
isSyntheticTriggerText,
isContinuationMessage,
syntheticTriggerKind,
+ canContinueFailedTurn,
} from '../syntheticTrigger.js';
describe('synthetic trigger detection', () => {
+ // Both clients must offer manual continuation for a settled scheduler error,
+ // but never race ongoing work or fabricate context for a rejected first send.
+ it('offers continuation only for a stopped error with conversation context and no retry record', () => {
+ const input = { error: 'Selected model is at capacity', retryText: null, running: false, hasUserInput: true };
+ expect(canContinueFailedTurn(input)).toBe(true);
+ for (const patch of [{ error: null }, { retryText: 'original' }, { running: true }, { hasUserInput: false }]) {
+ expect(canContinueFailedTurn({ ...input, ...patch })).toBe(false);
+ }
+ });
it('recognizes recovery in raw and hidden projections without treating every trigger as recovery', () => {
for (const content of [CONTINUE_AFTER_ERROR_PROMPT, { text: CONTINUE_AFTER_ERROR_PROMPT }]) {
expect(isContinuationMessage({ role: 'user', content })).toBe(true);
diff --git a/packages/maker-shared/src/syntheticTrigger.ts b/packages/maker-shared/src/syntheticTrigger.ts
index d59298f11c..367161b08c 100644
--- a/packages/maker-shared/src/syntheticTrigger.ts
+++ b/packages/maker-shared/src/syntheticTrigger.ts
@@ -16,6 +16,18 @@ export const UI_ACTION_TRIGGER_PREFIX = '[UI_ACTION_TRIGGER]';
*/
export const APP_EXIT_INTERRUPTED_REASON = 'app-exit-interrupted';
+/** A settled turn can continue from its conversation even after a scheduler
+ * releases its retry record. This is a new manual input, never a replay of the
+ * old scheduled run. The error UI still applies its auth/configuration gates. */
+export function canContinueFailedTurn(input: {
+ error: string | null;
+ retryText: string | null;
+ running: boolean;
+ hasUserInput: boolean;
+}): boolean {
+ return Boolean(input.error && !input.retryText && !input.running && input.hasUserInput);
+}
+
/** 已解析出的 user 文本是否是合成 UI 指令(所有面向用户的文本消费的统一判定)。 */
export function isSyntheticTriggerText(text: string): boolean {
return text.startsWith(UI_ACTION_TRIGGER_PREFIX);