diff --git a/src/agents/provider-local-service.ts b/src/agents/provider-local-service.ts index 4b5c6f2da119..bcfc8e353d30 100644 --- a/src/agents/provider-local-service.ts +++ b/src/agents/provider-local-service.ts @@ -3,6 +3,7 @@ * keep shared services alive while requests run and stop them after idle. */ import { spawn, type ChildProcess } from "node:child_process"; +import { createHash } from "node:crypto"; import path from "node:path"; import { clampPositiveTimerTimeoutMs, @@ -235,18 +236,16 @@ function localServiceKey( command: service.command, args: service.args ?? [], cwd: service.cwd ?? "", - env: sortedStringRecord(service.env), + envHash: hashStringRecord(service.env), healthUrl, }); } -function sortedStringRecord(record: Record | undefined): Record { - if (!record) { - return {}; - } - return Object.fromEntries( - Object.entries(record).toSorted(([left], [right]) => left.localeCompare(right)), +function hashStringRecord(record: Record | undefined): string { + const sorted = Object.entries(record ?? {}).toSorted(([left], [right]) => + left.localeCompare(right), ); + return createHash("sha256").update(JSON.stringify(sorted)).digest("hex"); } function buildHealthProbeHeaders(