fix: drop bare Error: from error guard — too broad for monitoring prose

Only match specific named JS exception types (TypeError, RangeError,
SyntaxError, ReferenceError). Bare "Error:" is ambiguous — legitimate
monitoring crons can start output with "Error: API latency exceeded
threshold" which should not be suppressed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sergio 2026-03-15 17:52:35 -05:00
parent 085a6988c1
commit 92ab31fb78
2 changed files with 7 additions and 3 deletions

View File

@ -134,11 +134,15 @@ describe("isLikelyRawErrorOutput", () => {
it("detects JS runtime exceptions", () => {
expect(isLikelyRawErrorOutput("TypeError: Cannot read properties of undefined")).toBe(true);
expect(isLikelyRawErrorOutput("RangeError: Maximum call stack size exceeded")).toBe(true);
expect(isLikelyRawErrorOutput("Error: ECONNREFUSED")).toBe(true);
expect(isLikelyRawErrorOutput("SyntaxError: Unexpected token")).toBe(true);
expect(isLikelyRawErrorOutput("ReferenceError: x is not defined")).toBe(true);
});
it("does not flag bare Error: prefix (could be legitimate monitoring prose)", () => {
expect(isLikelyRawErrorOutput("Error: ECONNREFUSED")).toBe(false);
expect(isLikelyRawErrorOutput("Error: API latency exceeded threshold")).toBe(false);
});
it("detects common provider error messages in JSON", () => {
const error = `{"message":"An error occurred while processing your request. You can retry your request."}`;
expect(isLikelyRawErrorOutput(error)).toBe(true);
@ -248,7 +252,7 @@ describe("dispatchCronDelivery — error output guard", () => {
});
it("preserves summary and outputText in the returned state even when skipping", async () => {
const errorText = "Error: ECONNREFUSED 127.0.0.1:18789";
const errorText = "TypeError: Cannot read properties of undefined (reading 'send')";
const params = makeBaseParams({ synthesizedText: errorText });
const state = await dispatchCronDelivery(params);

View File

@ -289,7 +289,7 @@ async function retryTransientDirectCronDelivery<T>(params: {
*/
const RAW_ERROR_OUTPUT_PATTERNS: readonly RegExp[] = [
/^\s*\{[\s\S]*"(?:type|error|code)":\s*"(?:error|server_error|invalid_request)/,
/^\s*(?:Error|TypeError|RangeError|SyntaxError|ReferenceError):/,
/^\s*(?:TypeError|RangeError|SyntaxError|ReferenceError):/,
/^\s*\{[\s\S]*"(?:message|error)":\s*"An error occurred/,
/\berror"?:\s*\{[\s\S]*"(?:type|code)":\s*"(?:server_error|invalid_request|rate_limit)/,
];