From 0a00d5d6bcdfa054bb7254ff794bf8a27a81b36c Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:29:35 +0800 Subject: [PATCH] fix(javascript): report the analysis timeout setting on every deadline path (#11136) --- ...avaScriptAnalysisWorker.inspection.test.ts | 18 +++++--- .../analysis/JavaScriptAnalysisWorker.ts | 46 ++++++++++--------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/javascript/analysis/JavaScriptAnalysisWorker.inspection.test.ts b/src/javascript/analysis/JavaScriptAnalysisWorker.inspection.test.ts index 8236c19c92..cce2f5a83d 100644 --- a/src/javascript/analysis/JavaScriptAnalysisWorker.inspection.test.ts +++ b/src/javascript/analysis/JavaScriptAnalysisWorker.inspection.test.ts @@ -237,16 +237,20 @@ it.each(["cancelled", "physical"] as const)( const result = await worker.analyze(file, { nodes: 100, unknowns: 100 }); if (result.ok) throw new Error("Expected startup failure"); const error = primaryAnalysisError(result.error.error); - if (origin === "cancelled") - expect(error._tag).toBe("AnalysisTimeoutError"); + const deadline = { + _tag: "AnalysisTimeoutError", + limit: expect.objectContaining({ + setting: "javascript.analysis_timeout_ms", + effective_value: 20, + }), + }; + if (origin === "cancelled") expect(error).toMatchObject(deadline); else { expect(error.userCategory).not.toBe("cancelled"); expect(error.cause).toBe(physical); - expect( - error.secondaryFailures.some( - (failure) => failure._tag === "AnalysisTimeoutError", - ), - ).toBe(true); + expect(error.secondaryFailures).toContainEqual( + expect.objectContaining(deadline), + ); } expect(launcher).toHaveBeenCalledOnce(); } finally { diff --git a/src/javascript/analysis/JavaScriptAnalysisWorker.ts b/src/javascript/analysis/JavaScriptAnalysisWorker.ts index 4b3d6f4c8e..56409a4ff6 100644 --- a/src/javascript/analysis/JavaScriptAnalysisWorker.ts +++ b/src/javascript/analysis/JavaScriptAnalysisWorker.ts @@ -574,10 +574,9 @@ export class JavaScriptAnalysisWorker { deadline?.interruption === "timeout" && !(error instanceof AnalysisTimeoutError) ) + // The primary failure already carries the captured output. error.retainSecondaryFailure( - new AnalysisTimeoutError(OPERATION, deadline.timeoutMs, { - cause: deadline.signal.reason, - }), + this.#timeoutError(deadline.signal.reason, false), ); this.#lastFailure = error; // Complete checkpoints remain readable after a child crash or cancellation. @@ -1202,24 +1201,32 @@ export class JavaScriptAnalysisWorker { if (this.#primaryFailure !== undefined) return this.#projectPrimaryFailure(path); return deadline.interruption === "timeout" - ? new AnalysisTimeoutError(OPERATION, this.limits.timeoutMs, { - ...(inspectionFailure === undefined - ? {} - : { cause: inspectionFailure }), - limit: analysisSettingLimit( - "javascript.analysis_timeout_ms", - this.limits.timeoutMs, - this.limits.timeoutSource, - ), - capturedOutput: this.#captured(), - userMessage: `JavaScript source analysis reached its ${String(this.limits.timeoutMs)}ms per-source server/provider deadline (analysis_timeout_ms), not the MCP client deadline.`, - remediationAction: - "Reuse accessible partial_observation Evidence to avoid recomputation; reading it is not a prerequisite for a corrected retry. Increase analysis_timeout_ms through MCP, or use rea analyze-javascript-application --analysis-timeout-ms on the CLI. Alternatively, reduce semantic limits or select exact inventoried source_paths (CLI: --source-path on that command). Omit source_paths to analyze all sources; an empty array is invalid. detail: summary reduces response size, not analysis work. Allow execution, cleanup and delivery headroom in the MCP client tool deadline; increasing that client deadline alone does not change this server budget. Resolve any reported incomplete cleanup before retrying.", - }) + ? this.#timeoutError(inspectionFailure) : cancelledBy(OPERATION, deadline.signal, { capturedOutput: this.#captured(), }); } + /** + * The per-source deadline failure, with the setting that raises it and its + * effective value. Every path that reports this deadline uses it. + */ + #timeoutError( + cause: unknown, + withCapturedOutput = true, + ): AnalysisTimeoutError { + return new AnalysisTimeoutError(OPERATION, this.limits.timeoutMs, { + ...(cause === undefined ? {} : { cause }), + limit: analysisSettingLimit( + "javascript.analysis_timeout_ms", + this.limits.timeoutMs, + this.limits.timeoutSource, + ), + ...(withCapturedOutput ? { capturedOutput: this.#captured() } : {}), + userMessage: `JavaScript source analysis reached its ${String(this.limits.timeoutMs)}ms per-source server/provider deadline (analysis_timeout_ms), not the MCP client deadline.`, + remediationAction: + "Reuse accessible partial_observation Evidence to avoid recomputation; reading it is not a prerequisite for a corrected retry. Increase analysis_timeout_ms through MCP, or use rea analyze-javascript-application --analysis-timeout-ms on the CLI. Alternatively, reduce semantic limits or select exact inventoried source_paths (CLI: --source-path on that command). Omit source_paths to analyze all sources; an empty array is invalid. detail: summary reduces response size, not analysis work. Allow execution, cleanup and delivery headroom in the MCP client tool deadline; increasing that client deadline alone does not change this server budget. Resolve any reported incomplete cleanup before retrying.", + }); + } #workerExitFailure( path: string, failure: Extract, @@ -1374,10 +1381,7 @@ export class JavaScriptAnalysisWorker { const cancellation = processInspectionCancellationError(cause, OPERATION); if (cancellation !== undefined) return deadline?.interruption === "timeout" - ? new AnalysisTimeoutError(OPERATION, deadline.timeoutMs, { - cause, - capturedOutput: this.#captured(), - }) + ? this.#timeoutError(cause) : cancellation.capturedOutput === undefined ? cancellation.retainCapturedOutput(this.#captured()) : cancellation;