Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 修复 Lead 错误恢复按钮被只读规则禁用 (#4325)
Dash0568ff4d6ce6
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsxindex 4d74ef5b21..cb305efcc1 100644--- a/apps/mobile/app/sessions/[sessionId].tsx+++ b/apps/mobile/app/sessions/[sessionId].tsx@@ -2331,10 +2331,13 @@ export default function SessionScreen() {// 会话参数未就绪(缓存种入 / 新建在途)时队列行仍只读:取消 / 编辑 / 插队都是打到// 被控端队列的 RPC,会话在那边可能还不存在。暂时断线则与 Desktop 一致继续允许// 尝试,失败由 runQueueAction 报错,不把连接恢复职责转嫁给用户。- const queueInlineReadOnlyReason = collaborationReadOnlyReason- ?? cacheSeededReason+ const queueAvailabilityReason = cacheSeededReason?? pendingCreationReason?? (sessionOperationLayout.showQueue ? null : composerDisabledReason);+ const queueInlineReadOnlyReason = collaborationReadOnlyReason ?? queueAvailabilityReason;+ // 重试/清错属于输入恢复:Lead 能发消息,也应能恢复失败输入。+ // 队列编辑和恢复整组队列仍沿用协作编排只读规则。+ const errorRecoveryReadOnlyReason = composerReadOnlyReason ?? queueAvailabilityReason;const showMessageHistory = sessionOperationLayout.messageHistoryMode === 'visible'|| (sessionOperationLayout.messageHistoryMode === 'collapsed' && pendingHistoryExpanded);// 冷开即出壳:session 元信息还没回来,但不是真正不可用(离线/被撤销,看 remoteUnavailableReason)——@@ -7277,10 +7280,12 @@ export default function SessionScreen() {}, [cancelQueueEdit, inputProjection.pendingQueue, queueEditing]);const retryQueueError = () => {+ if (errorRecoveryReadOnlyReason || !inputProjection.errorRetryText) return;void runQueueAction(() => maker.input.retryLastError(sessionId));};const clearQueueError = () => {+ if (errorRecoveryReadOnlyReason) return;void runQueueAction(() => maker.input.clearError(sessionId));};@@ -9316,6 +9321,7 @@ export default function SessionScreen() {不在这里,它们是消息流里的 pending_send 项。 */}<InlineQueueSectionbusy={queueBusy}+ errorRecoveryReadOnlyReason={errorRecoveryReadOnlyReason}onClearError={clearQueueError}onResume={resumeQueue}onRetryError={retryQueueError}diff --git a/apps/mobile/src/__tests__/InlineQueueSection.test.tsx b/apps/mobile/src/__tests__/InlineQueueSection.test.tsxnew file mode 100644index 0000000000..64f542ea9c--- /dev/null+++ b/apps/mobile/src/__tests__/InlineQueueSection.test.tsx@@ -0,0 +1,85 @@+// @vitest-environment jsdom+import { act, type ReactNode } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';+import { readFileSync } from 'node:fs';+import { InlineQueueSection, type InlineQueueSectionProps } from '@/session/InlineQueueSection';+import { sessionCollaborationComposerReadOnlyReason, sessionCollaborationReadOnlyReason } from '@/session/collaboration';+import type { InputProjection } from '@/session/types';++vi.mock('react-native', async () => {+ const { createElement } = await import('react');+ const view = (tag: string) => ({ children, onPress, disabled, testID, accessibilityHint }: {+ children?: ReactNode; onPress?: () => void; disabled?: boolean; testID?: string; accessibilityHint?: string;+ }) => createElement(tag, { onClick: onPress, disabled, 'data-testid': testID, title: accessibilityHint }, children);+ return { View: view('div'), Text: view('span'), Pressable: view('button'), ActivityIndicator: () => null,+ StyleSheet: { create: (s: unknown) => s, hairlineWidth: 1 } };+});+vi.mock('@/components/AppText', async () => ({ Text: (await import('react-native')).Text }));+vi.mock('lucide-react-native', () => ({ Pause: () => null, Play: () => null }));+vi.mock('react-i18next', async (importOriginal) => ({+ ...await importOriginal<typeof import('react-i18next')>(),+ useTranslation: () => ({ t: (key: string) => key }),+}));+vi.mock('@/theme', async () => {+ const tokens = await import('@/theme/tokens');+ return { ...tokens, useTheme: () => ({ colors: tokens.lightColors }),+ useThemedStyles: (make: (colors: typeof tokens.lightColors) => unknown) => make(tokens.lightColors) };+});++let root: Root;+let host: HTMLDivElement;+const retry = vi.fn();+const clear = vi.fn();+const resume = vi.fn();+beforeEach(() => {+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });+ vi.clearAllMocks();+ host = document.createElement('div'); root = createRoot(host);+});+afterEach(() => act(() => root.unmount()));+const projection = { error: 'Usage limit', errorRetryText: 'Try again', queuePaused: true } as InputProjection;+async function show(role: string | null, props: Partial<InlineQueueSectionProps> = {}) {+ await act(async () => root.render(<InlineQueueSection+ projection={projection}+ readOnlyReason={sessionCollaborationReadOnlyReason({ orcaRole: role })}+ errorRecoveryReadOnlyReason={sessionCollaborationComposerReadOnlyReason({ orcaRole: role })}+ onRetryError={retry} onClearError={clear} onResume={resume} {...props}+ />));+}+const button = (action: string) => host.querySelector<HTMLButtonElement>(`[data-testid="queue.inline.${action}Button"]`)!;++it.each(['lead', null])('lets %s retry and clear an error', async (role) => {+ await show(role);+ expect(button('retry').disabled).toBe(false);+ expect(button('clearError').disabled).toBe(false);+ expect(button('resume').disabled).toBe(role === 'lead');+ await act(async () => { button('retry').click(); button('clearError').click(); });+ expect(retry).toHaveBeenCalledOnce(); expect(clear).toHaveBeenCalledOnce();+});+it.each(['worker', 'reviewer'])('keeps %s read-only and explains why', async (role) => {+ await show(role);+ expect(button('retry').disabled).toBe(true);+ expect(button('clearError').disabled).toBe(true);+ expect(host.querySelector('[data-testid="queue.inline.errorDisabledReason"]')?.textContent).toBe(button('retry').title);+ await act(async () => { button('retry').click(); button('clearError').click(); });+ expect(retry).not.toHaveBeenCalled(); expect(clear).not.toHaveBeenCalled();+});+it('keeps readiness and in-flight gates, then re-enables recovery', async () => {+ await show('lead', { errorRecoveryReadOnlyReason: 'Syncing' });+ expect(button('retry').disabled).toBe(true); expect(button('clearError').title).toBe('Syncing');+ await show('lead', { busy: true });+ expect(button('retry').disabled).toBe(true); expect(button('clearError').disabled).toBe(true);+ expect(host.textContent).toContain('message.queuePresentation.row.busy');+ await show('lead'); expect(button('retry').disabled).toBe(false);+});+it('allows clearing an error without retry content', async () => {+ await show('lead', { projection: { ...projection, errorRetryText: null } });+ expect(button('retry').disabled).toBe(true); expect(button('clearError').disabled).toBe(false);+});+it('wires the route recovery gate independently from the orchestration gate', () => {+ const source = readFileSync('app/sessions/[sessionId].tsx', 'utf8');+ expect(source).toContain('errorRecoveryReadOnlyReason = composerReadOnlyReason ?? queueAvailabilityReason');+ expect(source).toContain('errorRecoveryReadOnlyReason={errorRecoveryReadOnlyReason}');+ expect(source).toContain('queueInlineReadOnlyReason = collaborationReadOnlyReason ?? queueAvailabilityReason');+});diff --git a/apps/mobile/src/__tests__/optimisticSessionComposer.test.ts b/apps/mobile/src/__tests__/optimisticSessionComposer.test.tsindex ebc782869b..32be6c29bc 100644--- a/apps/mobile/src/__tests__/optimisticSessionComposer.test.ts+++ b/apps/mobile/src/__tests__/optimisticSessionComposer.test.ts@@ -31,7 +31,9 @@ describe('mobile optimistic composer while session is not ready', () => {expect(source).toContain('remoteUnavailableReason: composerRemoteUnavailableReason,');expect(source).toContain('describeRemoteComposerBlockingError(connectionError)');// 会话尚未在被控端建成时,队列行(取消 / 编辑 / 插队)仍然只读。- expect(source).toContain('const queueInlineReadOnlyReason = collaborationReadOnlyReason\n ?? cacheSeededReason\n ?? pendingCreationReason');+ expect(source).toContain('const queueAvailabilityReason = cacheSeededReason\n ?? pendingCreationReason');+ expect(source).toContain('const queueInlineReadOnlyReason = collaborationReadOnlyReason ?? queueAvailabilityReason');+ expect(source).toContain('const errorRecoveryReadOnlyReason = composerReadOnlyReason ?? queueAvailabilityReason');});it('matches Desktop control behavior during a transient disconnect', () => {diff --git a/apps/mobile/src/__tests__/sessionMainLayerDesktopFirst.test.ts b/apps/mobile/src/__tests__/sessionMainLayerDesktopFirst.test.tsindex dc2ac4dec8..f7f3dddb85 100644--- a/apps/mobile/src/__tests__/sessionMainLayerDesktopFirst.test.ts+++ b/apps/mobile/src/__tests__/sessionMainLayerDesktopFirst.test.ts@@ -88,7 +88,9 @@ describe('mobile session main layer desktop-first noise budget', () => {// 输入框换成只读卡片,而它们只表示还不能 enqueue。composer 保持可用,发送改走 outbox// 排队(见 optimisticSessionComposer.test.ts),这两条理由只留给队列行操作。expect(source).toContain(' readOnlyReason: composerReadOnlyReason,\n');- expect(source).toContain('const queueInlineReadOnlyReason = collaborationReadOnlyReason\n ?? cacheSeededReason\n ?? pendingCreationReason');+ expect(source).toContain('const queueAvailabilityReason = cacheSeededReason\n ?? pendingCreationReason');+ expect(source).toContain('const queueInlineReadOnlyReason = collaborationReadOnlyReason ?? queueAvailabilityReason');+ expect(source).toContain('const errorRecoveryReadOnlyReason = composerReadOnlyReason ?? queueAvailabilityReason');expect(source).toContain('readOnlyReason={composerReadOnlyReason}');// header notice:协作会话(可聊天的 Lead)显示协作标签而非"只读模式"。expect(source).toContain('const collaborationLabel = sessionCollaborationLabel(session);');diff --git a/apps/mobile/src/i18n/locales/en/message.json b/apps/mobile/src/i18n/locales/en/message.jsonindex 21ca3998b1..06ec8051b9 100644--- a/apps/mobile/src/i18n/locales/en/message.json+++ b/apps/mobile/src/i18n/locales/en/message.json@@ -153,6 +153,7 @@"systemInstruction": "System instruction","retrySend": "Retry Send","clearError": "Clear Error",+ "noRetryContent": "No content is available to resend. Clear the error and enter your input again.","piImageInputUnsupported": "Image input is not enabled for the current Pi model. Switch to a model that supports images. For a custom model, enable “Supports image input” in provider settings, then start a new Pi task.","codexResumeNotReady": "Codex can't resume this task right now. Try again in a little while.","credentialSwitchWait": "Waiting for another Codex task to finish; it will send automatically once done",diff --git a/apps/mobile/src/i18n/locales/ja/message.json b/apps/mobile/src/i18n/locales/ja/message.jsonindex d3aa78056b..9e3fff786d 100644--- a/apps/mobile/src/i18n/locales/ja/message.json+++ b/apps/mobile/src/i18n/locales/ja/message.json@@ -153,6 +153,7 @@"systemInstruction": "システム指令","retrySend": "送信を再試行","clearError": "エラーをクリア",+ "noRetryContent": "再送信できる内容がありません。エラーをクリアして、もう一度入力してください。","piImageInputUnsupported": "現在の Pi モデルでは画像入力が有効になっていません。画像に対応するモデルへ切り替えてください。カスタムモデルの場合は、プロバイダー設定で「画像入力に対応」を有効にしてから、新しい Pi タスクを開始してください。","codexResumeNotReady": "Codex は現在このタスクを再開できません。しばらくしてからもう一度お試しください。","credentialSwitchWait": "他の Codex タスクの終了を待っています。終了後に自動で送信します",diff --git a/apps/mobile/src/i18n/locales/ko/message.json b/apps/mobile/src/i18n/locales/ko/message.jsonindex 2e57143763..e3bed8bf7b 100644--- a/apps/mobile/src/i18n/locales/ko/message.json+++ b/apps/mobile/src/i18n/locales/ko/message.json@@ -153,6 +153,7 @@"systemInstruction": "시스템 지시","retrySend": "전송 재시도","clearError": "오류 지우기",+ "noRetryContent": "다시 보낼 내용이 없습니다. 오류를 지운 후 다시 입력해 주세요.","piImageInputUnsupported": "현재 Pi 모델에는 이미지 입력이 활성화되어 있지 않습니다. 이미지를 지원하는 모델로 전환하세요. 사용자 지정 모델이라면 제공자 설정에서 ‘이미지 입력 지원’을 켠 다음 새 Pi 작업을 시작하세요.","codexResumeNotReady": "Codex에서 현재 이 작업을 재개할 수 없습니다. 잠시 후 다시 시도해 주세요.","credentialSwitchWait": "다른 Codex 작업이 끝나기를 기다리는 중입니다. 끝나면 자동으로 전송합니다",diff --git a/apps/mobile/src/i18n/locales/zh-CN/message.json b/apps/mobile/src/i18n/locales/zh-CN/message.jsonindex d05c4343b5..17530004f0 100644--- a/apps/mobile/src/i18n/locales/zh-CN/message.json+++ b/apps/mobile/src/i18n/locales/zh-CN/message.json@@ -153,6 +153,7 @@"systemInstruction": "系统指令","retrySend": "重试发送","clearError": "清除错误",+ "noRetryContent": "没有可重发的内容,请清除错误后重新输入。","piImageInputUnsupported": "当前 Pi 模型未启用图片输入。请切换到支持图片的模型;如果这是自定义模型,请在供应商设置中开启“支持图片输入”,然后新建 Pi 任务。","codexResumeNotReady": "Codex 暂时无法恢复这个任务,请稍后重试","credentialSwitchWait": "正在等待其它 Codex 任务结束,结束后自动发送",diff --git a/apps/mobile/src/i18n/locales/zh-TW/message.json b/apps/mobile/src/i18n/locales/zh-TW/message.jsonindex f0bdb7f71a..b2fa972a1b 100644--- a/apps/mobile/src/i18n/locales/zh-TW/message.json+++ b/apps/mobile/src/i18n/locales/zh-TW/message.json@@ -153,6 +153,7 @@"systemInstruction": "系統指令","retrySend": "重試傳送","clearError": "清除錯誤",+ "noRetryContent": "沒有可重新傳送的內容,請清除錯誤後重新輸入。","piImageInputUnsupported": "當前 Pi 模型未啟用圖片輸入。請切換到支援圖片的模型;如果這是自定義模型,請在供應商設定中開啟“支援圖片輸入”,然後新建 Pi 任務。","codexResumeNotReady": "Codex 暫時無法恢復這個任務,請稍後重試","credentialSwitchWait": "正在等待其它 Codex 任務結束,結束後自動傳送",diff --git a/apps/mobile/src/session/InlineQueueSection.tsx b/apps/mobile/src/session/InlineQueueSection.tsxindex 39b3a67c08..56ddde2573 100644--- a/apps/mobile/src/session/InlineQueueSection.tsx+++ b/apps/mobile/src/session/InlineQueueSection.tsx@@ -41,6 +41,7 @@ export interface InlineQueueSectionProps {projection: InputProjection;busy?: boolean;readOnlyReason?: string | null;+ errorRecoveryReadOnlyReason: string | null;onResume(): void;onRetryError(): void;onClearError(): void;@@ -50,6 +51,7 @@ export function InlineQueueSection({projection,busy,readOnlyReason,+ errorRecoveryReadOnlyReason,onResume,onRetryError,onClearError,@@ -65,6 +67,10 @@ export function InlineQueueSection({if (!hasBanner) return null;const controlsDisabled = busy || !!readOnlyReason;+ const errorDisabledReason = errorRecoveryReadOnlyReason+ || (busy ? t('message.queuePresentation.row.busy') : null);+ const retryDisabledReason = errorDisabledReason+ || (!projection.errorRetryText ? t('message.queue.noRetryContent') : null);const localizedAgentError = localizeAgentError(projection.errorReason,projection.toolLoop ?? null,@@ -88,19 +94,26 @@ export function InlineQueueSection({<View style={styles.errorActions}><ActionPillbusy={busy}- disabled={controlsDisabled || !projection.errorRetryText}+ disabled={!!retryDisabledReason}+ disabledReason={retryDisabledReason}label={t('message.queue.retrySend')}onPress={onRetryError}testID="queue.inline.retryButton"/><ActionPillbusy={busy}- disabled={controlsDisabled}+ disabled={!!errorDisabledReason}+ disabledReason={errorDisabledReason}label={t('message.queue.clearError')}onPress={onClearError}testID="queue.inline.clearErrorButton"/></View>+ {retryDisabledReason ? (+ <Text style={styles.disabledHint} testID="queue.inline.errorDisabledReason">+ {retryDisabledReason}+ </Text>+ ) : null}</View>) : null}@@ -250,6 +263,7 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({padding: spacing.md,},errorText: { color: colors.errorText, fontSize: typeScale.caption, lineHeight: lineHeight.caption },+ disabledHint: { color: colors.textSecondary, fontSize: typeScale.caption, lineHeight: lineHeight.caption },errorActions: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },actionPill: {alignItems: 'center',