From d2d4242d5b2c388803481dec1dde56360c81c32c Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Thu, 5 Mar 2026 16:32:10 -0600 Subject: [PATCH] fix(config): stream merged schema cache key hashing --- src/config/schema.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/config/schema.ts b/src/config/schema.ts index 13883f91289..406d61dce77 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -323,10 +323,24 @@ function buildMergedSchemaCacheKey(params: { configUiHints: channel.configUiHints ?? null, })) .toSorted((a, b) => a.id.localeCompare(b.id)); - // Hash the serialized key to avoid RangeError with many plugins/channels - // (JSON.stringify can exceed V8 string limits with 16+ channel schemas). - const raw = JSON.stringify({ plugins, channels }); - return crypto.createHash("sha256").update(raw).digest("hex"); + // Build the hash incrementally so we never materialize one giant JSON string. + const hash = crypto.createHash("sha256"); + hash.update('{"plugins":['); + plugins.forEach((plugin, index) => { + if (index > 0) { + hash.update(","); + } + hash.update(JSON.stringify(plugin)); + }); + hash.update('],"channels":['); + channels.forEach((channel, index) => { + if (index > 0) { + hash.update(","); + } + hash.update(JSON.stringify(channel)); + }); + hash.update("]}"); + return hash.digest("hex"); } function setMergedSchemaCache(key: string, value: ConfigSchemaResponse): void {