From 9945d6c2ce2c55ce29581809c5d5250498f210d3 Mon Sep 17 00:00:00 2001 From: "mux-bot[bot]" <264182336+mux-bot[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 20:37:33 +0000 Subject: [PATCH] refactor: extract isErrorWithName guard in WorkflowRunner Dedupe the three identical 'error instanceof Error && error.name === X' sentinel-error predicates (isForegroundWaitBackgroundedError, isAgentReportWaitTimeoutError, isWorkflowAgentHardTimeoutError) into a single isErrorWithName(error, name) helper. Behavior-preserving local refactor; each guard returns the same boolean as before. --- src/node/services/workflows/WorkflowRunner.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/node/services/workflows/WorkflowRunner.ts b/src/node/services/workflows/WorkflowRunner.ts index c19d8a77df..b0eec54e26 100644 --- a/src/node/services/workflows/WorkflowRunner.ts +++ b/src/node/services/workflows/WorkflowRunner.ts @@ -236,8 +236,16 @@ const WORKFLOW_AGENT_MAX_ATTEMPTS = 3; const WORKFLOW_RUNTIME_TIMEOUT_MS = 24 * 60 * 60 * 1000; +// Shared shape for the `.name`-tagged sentinel errors used throughout this runner +// (foreground-backgrounded, agent-report timeout, hard timeout). Keeps the +// `instanceof Error && error.name === ...` guard in one place so the individual +// predicates can't drift in how they recognize a tagged error. +function isErrorWithName(error: unknown, name: string): boolean { + return error instanceof Error && error.name === name; +} + function isForegroundWaitBackgroundedError(error: unknown): boolean { - return error instanceof Error && error.name === "ForegroundWaitBackgroundedError"; + return isErrorWithName(error, "ForegroundWaitBackgroundedError"); } function createForegroundWaitBackgroundedError(): Error { @@ -276,7 +284,7 @@ function parseParallelAgentsOptions(raw: unknown): { maxParallel?: number } { } function isAgentReportWaitTimeoutError(error: unknown): boolean { - return error instanceof Error && error.name === "AgentReportWaitTimeoutError"; + return isErrorWithName(error, "AgentReportWaitTimeoutError"); } function buildWorkflowAgentTimeoutFinalizationToken( @@ -294,7 +302,7 @@ function createWorkflowAgentHardTimeoutError(message: string): Error { } function isWorkflowAgentHardTimeoutError(error: unknown): boolean { - return error instanceof Error && error.name === "WorkflowAgentHardTimeoutError"; + return isErrorWithName(error, "WorkflowAgentHardTimeoutError"); } function shouldRestartUnrecoverableStartedTask(error: unknown): boolean {