From 29c2fa9deaf0e251b49930b9281f5babd2a9379c Mon Sep 17 00:00:00 2001 From: pro3958 Date: Thu, 16 Jul 2026 19:38:39 -0700 Subject: [PATCH] refactor(queue): consolidate bounded-concurrency helpers onto mapWithConcurrency focus-manifest-loader's mapWithConcurrencyLimit and patchless-secret-scan's mapPatchLessSecretScanFilesWithConcurrency each re-implemented the same worker-pool loop that src/queue/map-with-concurrency.ts already exports. Both now delegate to the canonical mapWithConcurrency, keeping their exported names and (items, limit, mapper) signatures so every existing call site compiles and behaves unchanged. No public behavior change; the two hand-duplicated loops that could silently drift are gone. Fixes #6602 --- src/queue/patchless-secret-scan.ts | 13 ++----------- src/signals/focus-manifest-loader.ts | 13 ++----------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/queue/patchless-secret-scan.ts b/src/queue/patchless-secret-scan.ts index 0916c04dd8..14485f025a 100644 --- a/src/queue/patchless-secret-scan.ts +++ b/src/queue/patchless-secret-scan.ts @@ -1,5 +1,6 @@ import type { FileFetcher } from "../review/review-grounding"; import type { AdvisoryFinding, PullRequestFileRecord } from "../types"; +import { mapWithConcurrency } from "./map-with-concurrency"; /** Per-file cap when synthesizing a patch for GitHub's patch-less (binary/large) PR files. */ export const SECRET_SCAN_PATCH_FALLBACK_MAX_CHARS = 512_000; @@ -159,17 +160,7 @@ async function mapPatchLessSecretScanFilesWithConcurrency( limit: number, mapper: (item: T) => Promise, ): Promise { - const results: R[] = new Array(items.length); - let nextIndex = 0; - const workers = Array.from({ length: Math.min(limit, items.length) }, async () => { - while (nextIndex < items.length) { - const index = nextIndex; - nextIndex += 1; - results[index] = await mapper(items[index]!); - } - }); - await Promise.all(workers); - return results; + return mapWithConcurrency(items, limit, mapper); } /** When GitHub omits inline `patch` (binary/large files), fetch post-change content and synthesize `+` lines so diff --git a/src/signals/focus-manifest-loader.ts b/src/signals/focus-manifest-loader.ts index 64f76e0a64..afa8515b8e 100644 --- a/src/signals/focus-manifest-loader.ts +++ b/src/signals/focus-manifest-loader.ts @@ -3,6 +3,7 @@ import type { JsonValue } from "../types"; import { nowIso } from "../utils/json"; import { contentLaneConfigToJson, experimentalConfigToJson, featuresConfigToJson, gateConfigToJson, MAX_FOCUS_MANIFEST_BYTES, parseFocusManifest, parseFocusManifestContent, repoDocGenerationConfigToJson, reviewConfigToJson, reviewRecapConfigToJson, maintainerRecapConfigToJson, opsConfigToJson, publicStatsConfigToJson, draftFlowConfigToJson, upstreamDriftIssuesConfigToJson, sweepWatchdogConfigToJson, prReconciliationConfigToJson, federatedIntelligenceConfigToJson, settingsOverrideToJson, type FocusManifest, type FocusManifestSource, type RepoReviewContext } from "./focus-manifest"; import { LOOPOVER_REPO_FOCUS_MANIFEST_YAML, resolveLoopOverSelfRepoFullName } from "../config/loopover-repo-focus-manifest"; +import { mapWithConcurrency } from "../queue/map-with-concurrency"; import type { LocalManifestLoadResult } from "../selfhost/private-config"; export const REPO_FOCUS_MANIFEST_SIGNAL = "repo-focus-manifest"; @@ -237,17 +238,7 @@ async function readBoundedResponseText(response: Response): Promise(items: T[], limit: number, mapper: (item: T) => Promise): Promise { - const results: U[] = new Array(items.length); - let nextIndex = 0; - const workers = Array.from({ length: Math.min(limit, items.length) }, async () => { - while (nextIndex < items.length) { - const index = nextIndex; - nextIndex += 1; - results[index] = await mapper(items[index]!); - } - }); - await Promise.all(workers); - return results; + return mapWithConcurrency(items, limit, mapper); } /**