Merge PR 2989 into release/v3.8.8

fix(sse): remove duplicate const settings in handleChatCore (release-blocker)
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-05-31 09:03:51 -03:00
committed by GitHub
3 changed files with 33 additions and 1 deletions

View File

@@ -59,6 +59,12 @@
### Fixed
- **sse/chatCore:** remove a duplicate `const settings` declaration in
`handleChatCore` (introduced alongside the per-key stream-default-mode
feature). The same-scope redeclaration made esbuild/tsx fail with
"The symbol 'settings' has already been declared", which turned every unit
test that imports chatCore red and broke the production build. The earlier
consolidated `settings` const is now reused.
- **db/migrations:** resolve a `077` migration version collision
(`077_api_key_stream_default_mode.sql` vs `077_quota_pools.sql`) that made
`getMigrationFiles()` throw and blocked `getDbInstance()` at startup (app would

View File

@@ -2151,7 +2151,10 @@ export async function handleChatCore({
userAgent: streamUserAgent,
streamDefaultMode: apiKeyInfo?.streamDefaultMode,
});
const settings = cachedSettings ?? (await getCachedSettings());
// `settings` is already consolidated once near the top of handleChatCore
// (the "fetch once, reuse" const). A second `const settings` here was a
// duplicate same-scope declaration that broke the esbuild/tsx transform
// ("settings has already been declared") and the production build. Reuse it.
credentials = applyCodexGlobalFastServiceTier(provider, credentials, settings, {
model: requestedModel,
body: body && typeof body === "object" ? (body as Record<string, unknown>) : null,

View File

@@ -0,0 +1,23 @@
/**
* Regression guard: `open-sse/handlers/chatCore.ts` must transform/compile.
*
* `handleChatCore` declared `const settings` twice in the same function scope
* (a "fetch once, reuse" const near the top + a duplicate added by the per-key
* stream-default-mode feature). esbuild/tsx rejected it with
* "The symbol 'settings' has already been declared", which turned EVERY test
* that imports chatCore red and broke the production build.
*
* Importing the module forces the transform; if the duplicate declaration
* returns, this import throws and the test fails loudly.
*/
import test from "node:test";
import assert from "node:assert/strict";
test("chatCore.ts imports without a duplicate-declaration transform error", async () => {
const mod = await import("../../open-sse/handlers/chatCore.ts");
assert.equal(
typeof mod.handleChatCore,
"function",
"handleChatCore must be importable (no duplicate `const settings` in scope)"
);
});