Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(voice): 语音诊断日志只记录固定错误码,不写入错误原文
Dashc430ad51c30e
diff --git a/apps/mobile/src/__tests__/mobileVoiceDiagnostics.test.ts b/apps/mobile/src/__tests__/mobileVoiceDiagnostics.test.tsindex bb66df6d4d..2f1a922546 100644--- a/apps/mobile/src/__tests__/mobileVoiceDiagnostics.test.ts+++ b/apps/mobile/src/__tests__/mobileVoiceDiagnostics.test.ts@@ -12,6 +12,8 @@ import { setMobileDebugSink } from '@/debug/mobileDebugLog';import { serializeMobileDebugRecord } from '@/debug/mobileDebugRecord';import type { StoredMobileVoiceCredential } from '@/session/mobileVoiceCredentialStore';import { createMobileVoiceControllerSession } from '@/session/mobileVoiceController';+import { ApiError } from '@/api/client';+import { classifyMobileVoiceFailure } from '@/session/mobileVoiceDiagnostics';const SPOKEN = '周五下午三点和财务对预算';const REFINED = '周五下午 3 点和财务核对预算。';@@ -194,6 +196,46 @@ describe('mobile voice diagnostics', () => {}});+ it('never logs error text that quotes a refinement response', async () => {+ const session = createMobileVoiceControllerSession({+ credential: credential(),+ initialDraft: '',+ asr: new SpeakingAsr(),+ refiner: {+ async refine(): Promise<RefinementResult> {+ // A malformed model response surfaces as an error quoting its output.+ throw new Error(`Refiner returned invalid JSON: ${REFINED}`);+ },+ },+ startAudio: startAudibleAudio,+ onDraftChanged: () => {},+ });+ await session.start();+ await session.stop();+ const refinement = messages().find((record) => record.args[0] === 'refinement latency summary')!+ .args[1]!;+ expect(refinement).toMatchObject({ outcome: 'rejected', reason: 'parse_error' });+ expect(records.join('')).not.toContain('财务');+ });++ it('classifies failures into fixed codes without echoing the message', () => {+ expect(classifyMobileVoiceFailure(new ApiError('RATE_LIMITED', 429, `限流 ${SPOKEN}`))).toBe(+ 'api_rate_limited_429',+ );+ expect(+ classifyMobileVoiceFailure(new Error('Voice refine warmup failed with status 409')),+ ).toBe('http_409');+ expect(classifyMobileVoiceFailure('语音会话不可优化、优化次数已用完,或不属于当前用户')).toBe(+ 'refine_quota_exhausted',+ );+ expect(+ classifyMobileVoiceFailure(+ new Error('Volcengine SAUC ASR connection timed out after 5000ms'),+ ),+ ).toBe('timeout');+ expect(classifyMobileVoiceFailure(new Error(SPOKEN))).toBe('other');+ });+it('logs a silent recording ending without ASR finalization', async () => {class QuietAsr extends SpeakingAsr {appendAudio(): void {}diff --git a/apps/mobile/src/session/mobileRealtimeAsrProvider.ts b/apps/mobile/src/session/mobileRealtimeAsrProvider.tsindex aaee3427c3..55dee1f3bf 100644--- a/apps/mobile/src/session/mobileRealtimeAsrProvider.ts+++ b/apps/mobile/src/session/mobileRealtimeAsrProvider.ts@@ -2,7 +2,7 @@ import { StopSoundActivity, type AsrEvent, type AsrProvider, type AudioTrace } fimport type { StoredMobileVoiceCredential } from '@/session/mobileVoiceCredentialStore';import { redactMobileVoiceCredentialText } from '@/session/mobileVoiceCredentialRedaction';import { isMobileVoiceRateLimited } from '@/session/mobileVoiceInput';-import { logMobileVoice } from '@/session/mobileVoiceDiagnostics';+import { classifyMobileVoiceFailure, logMobileVoice } from '@/session/mobileVoiceDiagnostics';import { gzip, ungzip } from 'pako';import { i18n } from '@/i18n';@@ -170,7 +170,7 @@ class MobileFallbackAsrProvider implements AsrProvider {attempt: this.candidates.indexOf(candidate) + 1,totalCandidates: this.candidates.length,rateLimited,- reason: (err instanceof Error ? err.message : String(err)).slice(0, 160),+ reason: classifyMobileVoiceFailure(err),});// Managed candidates share one account quota: the next candidate would// hit the same limit, so surface it instead of switching.diff --git a/apps/mobile/src/session/mobileVoiceController.ts b/apps/mobile/src/session/mobileVoiceController.tsindex d6bc6c2cce..15fb3f2a0b 100644--- a/apps/mobile/src/session/mobileVoiceController.ts+++ b/apps/mobile/src/session/mobileVoiceController.ts@@ -34,7 +34,12 @@ import {} from '@/session/mobileVoiceInput';import { startMobileRealtimeAudio } from '@/session/mobileRealtimeAudio';import { readCachedMobileVoiceDictionary } from '@/session/mobileVoiceDictionaryCache';-import { createMobileVoiceTimelineRecorder, logMobileVoice, shortRunId } from '@/session/mobileVoiceDiagnostics';+import {+ classifyMobileVoiceFailure,+ createMobileVoiceTimelineRecorder,+ logMobileVoice,+ shortRunId,+} from '@/session/mobileVoiceDiagnostics';type StartRealtimeAudio = (options: {sampleRate: number;@@ -157,10 +162,10 @@ export function createMobileVoiceControllerSession(}).then(() => {logMobileVoice('debug', 'refiner prompt cache warmed');}, (error) => {- logMobileVoice('warn', 'refiner warmup failed (non-fatal)', { reason: errorReason(error) });+ logMobileVoice('warn', 'refiner warmup failed (non-fatal)', { reason: classifyMobileVoiceFailure(error) });});} catch (error) {- logMobileVoice('warn', 'refiner warmup skipped', { reason: errorReason(error) });+ logMobileVoice('warn', 'refiner warmup skipped', { reason: classifyMobileVoiceFailure(error) });}};const baseDraft = options.initialDraft;@@ -757,15 +762,12 @@ function replaceInsertionText(return `${draft.slice(0, insertion.start)}${text}${draft.slice(insertion.end)}`;}-function errorReason(error: unknown): string {- return (error instanceof Error ? error.message : String(error)).slice(0, 160);-}function logMobileVoiceFailure(message: string, stage: 'microphone' | 'asr', error: unknown): void {logMobileVoice('warn', message, {stage,rateLimited: isMobileVoiceRateLimited(error),- reason: errorReason(error),+ reason: classifyMobileVoiceFailure(error),});}diff --git a/apps/mobile/src/session/mobileVoiceDiagnostics.ts b/apps/mobile/src/session/mobileVoiceDiagnostics.tsindex ac08d0e1be..2cfd0f68de 100644--- a/apps/mobile/src/session/mobileVoiceDiagnostics.ts+++ b/apps/mobile/src/session/mobileVoiceDiagnostics.ts@@ -26,8 +26,7 @@ export function logMobileVoice(log('[mobile-voice]', message, fields);}-// Refiner rejection reasons are codes; anything else is a transport/server-// message, kept short (the Debug log recorder still redacts credentials).+// Refiner rejection reasons are codes. Anything else is an error message.const REFINE_REJECTION_CODES = new Set(['empty_input','empty_output',@@ -37,7 +36,40 @@ const REFINE_REJECTION_CODES = new Set([]);function rejectionReason(reason: string): string {- return REFINE_REJECTION_CODES.has(reason) ? reason : `error: ${reason.slice(0, 160)}`;+ return REFINE_REJECTION_CODES.has(reason) ? reason : classifyMobileVoiceFailure(reason);+}++const FAILURE_PATTERNS: Array<[RegExp, string]> = [+ [/不可优化|次数已用完/, 'refine_quota_exhausted'],+ [/rate.?limit|too many|频繁|\b429\b/i, 'rate_limited'],+ [/timed? ?out|timeout|超时/i, 'timeout'],+ [/json|parse|unexpected token|malformed/i, 'parse_error'],+ [/permission|denied|权限/i, 'permission'],+ [/stopped|cancel/i, 'cancelled'],+ [/network|socket|connect|closed|连接|中断/i, 'connection'],+];++/**+ * A fixed failure code for logs. Never returns the message itself: error text+ * can quote a provider response (a malformed refinement embeds the model's+ * output), which may contain dictated words. Structured API errors keep their+ * server code and HTTP status, which are enums, not content.+ */+export function classifyMobileVoiceFailure(error: unknown): string {+ if (error && typeof error === 'object') {+ const { code, status } = error as { code?: unknown; status?: unknown };+ if (+ typeof code === 'string' &&+ /^[A-Z][A-Z0-9_]{1,40}$/.test(code) &&+ typeof status === 'number'+ ) {+ return `api_${code.toLowerCase()}_${status}`;+ }+ }+ const message = error instanceof Error ? error.message : String(error);+ const status = /\bstatus (\d{3})\b/i.exec(message)?.[1];+ if (status) return `http_${status}`;+ return FAILURE_PATTERNS.find(([pattern]) => pattern.test(message))?.[1] ?? 'other';}export function shortRunId(runId: string): string {@@ -210,13 +242,13 @@ export function createMobileVoiceTimelineRecorder(context: {logMobileVoice('warn', 'asr recovery failed', {runId,elapsedMs: Math.round(event.elapsedMs),- reason: event.reason.slice(0, 160),+ reason: classifyMobileVoiceFailure(event.reason),});return;case 'asr_stop_error_ignored':logMobileVoice('warn', 'asr error after stop ignored', {runId,- reason: event.message.slice(0, 160),+ reason: classifyMobileVoiceFailure(event.message),textChars: event.textChars,});return;@@ -229,7 +261,10 @@ export function createMobileVoiceTimelineRecorder(context: {});return;case 'error':- logMobileVoice('error', 'run failed', { runId, reason: event.message.slice(0, 160) });+ logMobileVoice('error', 'run failed', {+ runId,+ reason: classifyMobileVoiceFailure(event.message),+ });return;}};diff --git a/docs/voice-optimization-summary-2026-09-25.md b/docs/voice-optimization-summary-2026-09-25.mdindex c2365ba6be..51077d0978 100644--- a/docs/voice-optimization-summary-2026-09-25.md+++ b/docs/voice-optimization-summary-2026-09-25.md@@ -170,11 +170,17 @@ RMS≥32的轻声,或至少6毫秒RMS≥96的较明显短音,才保留为最- 结束提示音与桌面一致:同一音高、包络与“重复一声再低小三度”的形态(手机仍只在停止采集后播放)。- 润色流式片段不再显示,保持现有文字直到完整润色校验通过后一次替换,与桌面一致。+- 新增手机语音诊断:写入 Debug 日志的 `voice` 范围(开发版同时输出到 Metro),记录+ 各阶段耗时、每次录音与润色汇总、SAUC 收尾判定(原因名与桌面一致);只记阶段、耗时、+ 固定原因码与字数,识别文字、润色文字及可能引用它们的错误原文都不记录。未接入:开始提示音与系统静音(录音中经 expo-audio 播放会让 iOS 采集停止,需原生-方案)、首包 10ms 拆分(原生采集按固定缓冲回调,需改原生)、桌面分段计时日志-(手机识别层没有日志通道)。另有一项既有差异:手机 SAUC 在 socket 打开时即视为-连接就绪并开始发送音频,桌面等首个协议响应。以上仅有单测与类型检查,未在真机或模拟器上录音验证。+方案)、首包 10ms 拆分(原生采集按固定缓冲回调,需改原生)。另有一项既有差异:+手机 SAUC 在 socket 打开时即视为连接就绪并开始发送音频,桌面等首个协议响应。++验证:iOS 模拟器(iPhone Air,Global)用上述诊断日志核对了 4 次真实录音:3 次快速+收尾,停止到提交 3–5ms;1 次因停止前刚检测到声音而等待最终响应约 0.5 秒;停顿润色+在停止时被复用,每次录音只发 1 次润色请求。尚未在 iPhone 真机或 Android 上验证。详细实验:[静音对照](voice-mute-benchmark-2026-09-25.md)、