From 61ad4f2d7c39efe0fad8a65438888ead13dd0a19 Mon Sep 17 00:00:00 2001 From: 777genius Date: Mon, 11 May 2026 00:50:26 +0300 Subject: [PATCH] fix(runtime): reduce diagnostic prefix regex complexity --- .../runtime/RuntimeDiagnosticClassifier.ts | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/services/team/runtime/RuntimeDiagnosticClassifier.ts b/src/main/services/team/runtime/RuntimeDiagnosticClassifier.ts index c7f1f797..bb182c7d 100644 --- a/src/main/services/team/runtime/RuntimeDiagnosticClassifier.ts +++ b/src/main/services/team/runtime/RuntimeDiagnosticClassifier.ts @@ -147,6 +147,33 @@ const UNKNOWN_CLASSIFICATION: RuntimeDiagnosticClassification = { generic: true, }; +function stripLatestAssistantFailurePrefix(message: string): string { + const marker = ' failed with '; + const lowerMessage = message.toLowerCase(); + const markerIndex = lowerMessage.indexOf(marker); + if (!lowerMessage.startsWith('latest assistant message ') || markerIndex < 0) { + return message; + } + + const errorNameStart = markerIndex + marker.length; + const dashIndex = message.indexOf('-', errorNameStart); + const colonIndex = message.indexOf(':', errorNameStart); + const separatorIndexes = [dashIndex, colonIndex] + .filter((index) => index >= 0) + .sort((left, right) => left - right); + if (separatorIndexes.length === 0) { + return message; + } + + const separatorIndex = separatorIndexes[0]; + const errorName = message.slice(errorNameStart, separatorIndex).trim(); + if (!/^[A-Za-z][A-Za-z0-9_.]*Error$/.test(errorName)) { + return message; + } + + return message.slice(separatorIndex + 1).trimStart(); +} + export function normalizeRuntimeDiagnosticMessage( message: string | null | undefined ): string | null { @@ -154,14 +181,9 @@ export function normalizeRuntimeDiagnosticMessage( (current, pattern) => current.replace(pattern, '[redacted]'), message ?? '' ); - const normalized = scrubbed - .replace(/\s+/g, ' ') - .trim() - .replace( - /^Latest assistant message(?:\s+\S+|\s+for\s+opencode\s+session\s+\S+)?\s+failed with\s+[^-:]+Error\s*[-:]\s*/i, - '' - ) - .replace(/^APIError\s*[-:]\s*/i, ''); + const normalized = stripLatestAssistantFailurePrefix( + scrubbed.replace(/\s+/g, ' ').trim() + ).replace(/^APIError\s*[-:]\s*/i, ''); return normalized.length > 0 ? normalized : null; }