fix(config): prevent RangeError in merged schema cache key generation

Fix merged schema cache key generation for high-cardinality plugin/channel metadata by hashing incrementally instead of serializing one large aggregate string.

Includes changelog entry for the user-visible regression fix.

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Co-authored-by: Bill <gsamzn@gmail.com>
This commit is contained in:
Bill
2026-03-06 06:45:07 +08:00
committed by GitHub
parent 60d33637d9
commit a0b731e2ce
2 changed files with 20 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import crypto from "node:crypto";
import { CHANNEL_IDS } from "../channels/registry.js";
import { VERSION } from "../version.js";
import type { ConfigUiHint, ConfigUiHints } from "./schema.hints.js";
@@ -322,7 +323,24 @@ function buildMergedSchemaCacheKey(params: {
configUiHints: channel.configUiHints ?? null,
}))
.toSorted((a, b) => a.id.localeCompare(b.id));
return JSON.stringify({ plugins, channels });
// 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 {