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): show attachment access recovery before error details

elfcv95f23d74a165
diff --git a/apps/desktop/scripts/fixtures/attachment-access-error/attachment-access-error-fixture.tsx b/apps/desktop/scripts/fixtures/attachment-access-error/attachment-access-error-fixture.tsx
index 63c98e8977..068817709d 100644
--- a/apps/desktop/scripts/fixtures/attachment-access-error/attachment-access-error-fixture.tsx
+++ b/apps/desktop/scripts/fixtures/attachment-access-error/attachment-access-error-fixture.tsx
@@ -1,10 +1,17 @@
import { ErrorMessageCard } from '../../../src/renderer/components/chat/ErrorMessageCard';
+import { ErrorBanner } from '../../../src/renderer/components/chat/ErrorBanner';
+import { ErrorTailErrorBanner } from '../../../src/renderer/components/chat/InterruptedTurnBanner';
import { mountPage } from '../../ui-page/harness';
+const error = '[DEVICE_LINK_MEDIA_ACCESS_DENIED] Cannot read the source attachment.';
void mountPage({
- render: () => (
+ render: (ctx) => (
<div className="p-4">
- <ErrorMessageCard message="[DEVICE_LINK_MEDIA_ACCESS_DENIED] Cannot read the source attachment." />
+ {ctx.case.startsWith('live')
+ ? <ErrorBanner error={error} onRetry={() => {}} />
+ : ctx.case.startsWith('tail')
+ ? <ErrorTailErrorBanner errorText={error} onContinue={() => {}} onDismiss={() => {}} />
+ : <ErrorMessageCard message={error} />}
</div>
),
});
diff --git a/apps/desktop/scripts/fixtures/attachment-access-error/ui-page.mjs b/apps/desktop/scripts/fixtures/attachment-access-error/ui-page.mjs
index a615626b17..8812357902 100644
--- a/apps/desktop/scripts/fixtures/attachment-access-error/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/attachment-access-error/ui-page.mjs
@@ -4,14 +4,20 @@ export default {
name: 'attachment-access-error',
entry: './attachment-access-error-fixture.tsx',
viewport: { width: 560, height: 400 },
- real: 'ErrorMessageCard, error-code decoding, ErrorNotice and localized attachment recovery guidance',
+ real: 'ErrorBanner, ErrorTailErrorBanner, ErrorMessageCard, error-code decoding, ErrorNotice and localized attachment recovery guidance',
notCovered: 'macOS WeChat permissions, file I/O and cross-device sending; transport behavior is covered by targeted unit tests',
cases: {
default: { about: '#6530: source permission denial explains how to reattach a readable copy' },
+ live: { about: '#6530: live send failure exposes recovery without expanding details' },
+ 'live-narrow': { about: 'Live recovery at narrow width', viewport: { width: 320, height: 480 } },
+ tail: { about: '#6530: tail banner exposes recovery without expanding details' },
+ 'tail-narrow': { about: 'Tail recovery at narrow width', viewport: { width: 320, height: 480 } },
narrow: { about: 'Recovery text wraps at a narrow message width', viewport: { width: 320, height: 480 } },
},
async check(page, ui) {
- assert.ok(await page.getByText(await ui.t('chat.remoteError.DEVICE_LINK_MEDIA_ACCESS_DENIED'), { exact: true }).isVisible());
+ assert.ok(await page.getByText(await ui.t('chat.errorBanner.attachmentAccessDeniedRecovery'), { exact: true }).isVisible());
+ assert.ok(await page.getByText(await ui.t('chat.errorBanner.attachmentAccessDeniedTitle'), { exact: true }).isVisible());
+ assert.equal(await page.getByRole('button', { name: await ui.t('chat.errorBanner.networkShowRaw'), exact: true }).getAttribute('aria-expanded'), 'false');
assert.equal(await page.getByText(await ui.t('chat.errorBanner.replyFailed'), { exact: true }).count(), 0);
},
};
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
index efe1d42708..1eb2869f25 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
@@ -5665,6 +5665,10 @@ describe('makerChatStore text delta batching', () => {
await flushPromises();
expect(enqueueAttempts).toBe(2);
+ // #6530 real-device regression: keep the code until the visible banner localizes it.
+ if (failure.includes('DEVICE_LINK_MEDIA_ACCESS_DENIED')) {
+ expect(makerChatStore.getSnapshot(SESSION_ID).error).toContain('[DEVICE_LINK_MEDIA_ACCESS_DENIED]');
+ }
expect(onRemoteOptimisticFailure).toHaveBeenCalledWith(queued?.clientId, expect.any(Error));
expect(onRemoteOptimisticFailure.mock.invocationCallOrder[0]).toBeLessThan(
vi.mocked(setRemoteOptimisticAttachmentUrls).mock.invocationCallOrder[
diff --git a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
index 1faf77c8cb..6863e37c4c 100644
--- a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
+++ b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
@@ -359,6 +359,7 @@ export function ErrorBanner({
? t(errorReasonI18nKey)
: undefined;
const remoteErrorCode = parseAgentErrorCode(error)?.code;
+ const isAttachmentAccessDenied = remoteErrorCode === 'DEVICE_LINK_MEDIA_ACCESS_DENIED';
const remoteErrorKey = remoteAgentLimitErrorKey(error) ?? chatRemoteErrorGuidanceKey(remoteErrorCode, sessionSource);
const remoteGuidance = remoteErrorKey && i18n.exists(remoteErrorKey) ? t(remoteErrorKey) : undefined;
const terminalRateLimitRetryProgress = parseTerminalRateLimitRetryProgress(error, errorReason);
@@ -672,11 +673,13 @@ export function ErrorBanner({
ref={bannerRef}
className={cn('mx-auto', className)}
style={style}
- message={displayError}
+ message={isAttachmentAccessDenied ? t('chat.errorBanner.attachmentAccessDeniedTitle') : displayError}
description={
- (showHistoryRecovery || showInvalidEncryptedContentRecovery) && onForkStripEncrypted
- ? t('chat.errorBanner.readableHistoryRecoveryDescription')
- : undefined
+ isAttachmentAccessDenied
+ ? t('chat.errorBanner.attachmentAccessDeniedRecovery')
+ : (showHistoryRecovery || showInvalidEncryptedContentRecovery) && onForkStripEncrypted
+ ? t('chat.errorBanner.readableHistoryRecoveryDescription')
+ : undefined
}
details={canShowErrorDetails ? error : undefined}
onDiagnose={
diff --git a/apps/desktop/src/renderer/components/chat/ErrorMessageCard.tsx b/apps/desktop/src/renderer/components/chat/ErrorMessageCard.tsx
index 9af0f8bc79..75eefa2589 100644
--- a/apps/desktop/src/renderer/components/chat/ErrorMessageCard.tsx
+++ b/apps/desktop/src/renderer/components/chat/ErrorMessageCard.tsx
@@ -53,6 +53,8 @@ export function ErrorMessageCard({
const remoteKey = parsedRemoteKey === 'chat.remoteError.AUTO_REVIEW_UNAVAILABLE'
? chatRemoteErrorGuidanceKey('AUTO_REVIEW_UNAVAILABLE', sessionSource)
: parsedRemoteKey;
+ const isAttachmentAccessDenied = kind === 'reply-error'
+ && remoteKey === 'chat.remoteError.DEVICE_LINK_MEDIA_ACCESS_DENIED';
const remoteGuidance = remoteKey && i18n.exists(remoteKey) ? t(remoteKey) : undefined;
const i18nKey = reason ? ERROR_REASON_I18N_KEYS[reason] : undefined;
const isStreamInterrupted = isStreamInterruptedErrorMessage(message, reason);
@@ -83,7 +85,8 @@ export function ErrorMessageCard({
return (
<ErrorNotice
key={`${reason ?? ''}:${kind}`}
- message={text}
+ message={isAttachmentAccessDenied ? t('chat.errorBanner.attachmentAccessDeniedTitle') : text}
+ description={isAttachmentAccessDenied ? t('chat.errorBanner.attachmentAccessDeniedRecovery') : undefined}
details={showRawToggle ? message : undefined}
data-testid="error-message-card"
/>
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx
index 1d7f10dc45..8efbd3506c 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx
+++ b/apps/desktop/src/renderer/components/chat/__tests__/ErrorLocalization.test.tsx
@@ -91,7 +91,8 @@ describe.each(SUPPORTED_LOCALES)('error presentation in %s', locale => {
render(<I18nextProvider i18n={i18n}><ErrorMessageCard message={message} /></I18nextProvider>);
const expected = locales[locale].chat.remoteError[code as keyof typeof en.chat.remoteError];
expect(typeof expected).toBe('string');
- expect(screen.getByText(expected)).toBeTruthy();
+ expect(screen.getByText(code === 'DEVICE_LINK_MEDIA_ACCESS_DENIED'
+ ? i18n.t('chat.errorBanner.attachmentAccessDeniedRecovery') : expected)).toBeTruthy();
expect(screen.queryByText(i18n.t('chat.errorBanner.replyFailed'))).toBeNull();
expect(screen.queryByText(/upstream fallback/)).toBeNull();
fireEvent.click(screen.getByText(i18n.t('chat.errorBanner.networkShowRaw')));
@@ -99,10 +100,28 @@ describe.each(SUPPORTED_LOCALES)('error presentation in %s', locale => {
expect(screen.queryByText(/private-test-value/)).toBeNull();
const next = locale === 'en' ? 'ja' : 'en';
await act(async () => { await i18n.changeLanguage(next); });
- expect(screen.getByText(i18n.t(`chat.remoteError.${code}`))).toBeTruthy();
+ expect(screen.getByText(i18n.t(code === 'DEVICE_LINK_MEDIA_ACCESS_DENIED'
+ ? 'chat.errorBanner.attachmentAccessDeniedRecovery' : `chat.remoteError.${code}`))).toBeTruthy();
expect(screen.queryByText(locales[locale].chat.remoteError[code as keyof typeof en.chat.remoteError])).toBeNull();
});
+ // #6530 real-device gap: recovery must be visible before expanding details on every desktop surface.
+ it.each(['live', 'tail', 'history'] as const)('shows attachment recovery outside details on %s', async surface => {
+ const i18n = createInstance();
+ await i18n.init({ lng: locale, fallbackLng: 'en', resources: Object.fromEntries(Object.entries(locales).map(([lng, common]) => [lng, { translation: common }])) });
+ const error = '[DEVICE_LINK_MEDIA_ACCESS_DENIED] Cannot read the source attachment.';
+ render(<I18nextProvider i18n={i18n}>{surface === 'live'
+ ? <ErrorBanner error={error} onRetry={vi.fn()} />
+ : surface === 'tail'
+ ? <ErrorTailErrorBanner errorText={error} onContinue={vi.fn()} onDismiss={vi.fn()} />
+ : <ErrorMessageCard message={error} />}</I18nextProvider>);
+ expect(screen.getByText(i18n.t('chat.errorBanner.attachmentAccessDeniedTitle'))).toBeTruthy();
+ expect(screen.getByText(i18n.t('chat.errorBanner.attachmentAccessDeniedRecovery'))).toBeTruthy();
+ expect(screen.getByText(i18n.t('chat.errorBanner.networkShowRaw')).getAttribute('aria-expanded')).toBe('false');
+ expect(screen.queryByText(i18n.t('chat.errorBanner.replyFailed'))).toBeNull();
+ expect(screen.queryByText(error)).toBeNull();
+ });
+
it.each(['live', 'tail'] as const)('keeps known remote recovery guidance in the %s banner across language changes', async surface => {
const i18n = createInstance();
await i18n.init({ lng: locale, fallbackLng: 'en', resources: Object.fromEntries(Object.entries(locales).map(([lng, common]) => [lng, { translation: common }])) });
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 691fd3700a..aba355602a 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -11329,6 +11329,8 @@
"errorBanner": {
"requestFormatError": "The app sent an invalid request, so this reply could not be completed.",
"replyFailed": "Could not complete the reply",
+ "attachmentAccessDeniedTitle": "Cindy cannot read the source attachment; the message was not sent.",
+ "attachmentAccessDeniedRecovery": "Save a copy to Downloads or another accessible folder, remove the original attachment, and add the copy using the attachment button before sending again.",
"retryTitle": "Resend the last message",
"cancelTitle": "Dismiss error",
"retry": "Retry",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index e3100149a8..96cdf7e0ca 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -11285,6 +11285,8 @@
"errorBanner": {
"requestFormatError": "アプリが送信したリクエストの形式に問題があり、返信を完了できませんでした。",
"replyFailed": "返信を完了できませんでした",
+ "attachmentAccessDeniedTitle": "Cindy が元の添付ファイルを読み取れないため、メッセージは送信されていません。",
+ "attachmentAccessDeniedRecovery": "「ダウンロード」などアクセス可能なフォルダーにコピーを保存し、元の添付ファイルを削除してから、添付ボタンでコピーを追加し、再送信してください。",
"retryTitle": "最後のメッセージを再送信",
"cancelTitle": "エラーを閉じる",
"retry": "再試行",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 04cc3bf633..7e71b3792a 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -11285,6 +11285,8 @@
"errorBanner": {
"requestFormatError": "앱이 보낸 요청 형식에 문제가 있어 답변을 완료하지 못했습니다.",
"replyFailed": "답변을 완료하지 못했습니다",
+ "attachmentAccessDeniedTitle": "Cindy가 원본 첨부 파일을 읽을 수 없어 메시지가 전송되지 않았습니다.",
+ "attachmentAccessDeniedRecovery": "다운로드 등 접근 가능한 폴더에 사본을 저장하고, 원본 첨부 파일을 제거한 뒤 첨부 버튼으로 사본을 추가하여 다시 전송하세요.",
"retryTitle": "마지막 메시지 다시 보내기",
"cancelTitle": "오류 알림 닫기",
"retry": "다시 시도",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index bf90b50618..8016472641 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -11285,6 +11285,8 @@
"errorBanner": {
"requestFormatError": "应用发送的请求格式有误,本次回复未能完成。",
"replyFailed": "回复未完成",
+ "attachmentAccessDeniedTitle": "Cindy 无法读取源附件,消息未发送。",
+ "attachmentAccessDeniedRecovery": "请将文件另存到“下载”或其他可访问的文件夹,移除原附件,再用附件按钮添加副本后发送。",
"retryTitle": "重新发送最后一条消息",
"cancelTitle": "关闭错误提示",
"retry": "重试",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index f6a2899aab..66747c4090 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -11284,6 +11284,8 @@
"errorBanner": {
"requestFormatError": "應用程式送出的請求格式有誤,本次回覆未能完成。",
"replyFailed": "回覆未完成",
+ "attachmentAccessDeniedTitle": "Cindy 無法讀取來源附件,訊息未傳送。",
+ "attachmentAccessDeniedRecovery": "請將檔案另存到「下載」或其他可存取的資料夾,移除原附件,再用附件按鈕加入副本後傳送。",
"retryTitle": "重新傳送最後一條訊息",
"cancelTitle": "關閉錯誤提示",
"retry": "重試",
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 2a3b3ca3b3..c59133fbe4 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -11327,7 +11327,8 @@ function settleRemoteOptimisticFailure(sessionId: string, clientId: string, erro
),
...(error !== undefined
? {
- error: decodeRemoteErrorMessage(error instanceof Error ? error.message : String(error)),
+ // Keep the code so the banner can expose recovery guidance in its active locale.
+ error: remoteErrorMessageForBanner(error instanceof Error ? error.message : String(error)),
usageLimitRecovery: null,
errorReason: null,
toolLoop: null,
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 59d1016e16..ea87411660 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -636,7 +636,9 @@ warn/warning 状态检查项、等待或处理中的检查项和 warning issue
非聊天调用方也不会收到原始读取错误。Desktop 的待发消息在该错误下直接恢复草稿,
不因后续远端查询离线而延迟或重试;该错误发生于派发前,不属于投递结果不确定。
Desktop 与 Mobile 的错误展示
-提供五语“另存到可访问文件夹、移除旧附件、用附件按钮重选”指引。
+提供五语“另存到可访问文件夹、移除旧附件、用附件按钮重选”指引。Desktop 待发失败状态
+保留已知错误码至展示边界,避免提前翻译后退回通用错误;附件拒读标题与恢复步骤直接显示,
+技术详情保持折叠。
不新增 channel、relay 字段或权限。生成该错误的是桌面控制端,不要求目标设备升级;
旧客户端遇到历史里的未知错误仍走原通用提示。SSH 的远端文件读取流程不变。
这不授予 macOS 文件权限,也不证明微信拖入的系统授权生命周期已修复。