diff --git a/src/session.ts b/src/session.ts index 33d3e6ea6c..4579408751 100644 --- a/src/session.ts +++ b/src/session.ts @@ -4,8 +4,9 @@ import { log as loggerLog } from "./logger.js"; import { getStore, effectiveFileStorageMode } from "./persist.js"; import { VERSION } from "./version.js"; import { maxSessions as knobMaxSessions, sessionWarmMax, sessionWarmMaxBytes, sessionResidentMaxBytes } from "./knobs.js"; -import { configFileEpoch, loadConfigFile } from "./config.js"; +import { configFileEpoch, loadConfigFile, loadNamedProviders } from "./config.js"; import { applyCompressSettings, hasCompressSettings, resolveContextLimitValue } from "./compress-settings.js"; +import { agentProviderRecipes } from "./agent-providers.js"; import { durableMessageToolPaths, withDurableProtection } from "./durable-message-guards.js"; import type { AnonymousProvenance } from "./anon-provenance.js"; import type { WireProtocol } from "./util.js"; @@ -820,12 +821,18 @@ function staleEffectiveStamp(session: Session | undefined): boolean { * Config without file settings, so returning it naked would drop every file * knob between the edit and the session's next wire request. Provider/model * cascade levels need the request URL and are deliberately NOT re-resolved - * here — the next wire request re-stamps the full cascade. */ + * here — the next wire request re-stamps the full cascade. The named-provider + * recipe table IS resolved from the same live sources the request path feeds + * resolveRequestConfig (agent-registry layer under file recipes — see + * server/handle.ts): applyCompressSettings expands global-level + * externalSummary "provider/model" references against that table at resolve + * time, so an empty table disables every valid chain for the whole stale + * window (#5912). */ function liveFileOverlayConfig(base: Config): Config { const compress = loadConfigFile().compress; if (!compress || !hasCompressSettings(compress)) return base; const limit = resolveContextLimitValue(compress.modelContextLimit, base.modelContextLimit); - return applyCompressSettings(base, limit, compress, {}); + return applyCompressSettings(base, limit, compress, { ...agentProviderRecipes(), ...loadNamedProviders() }); } export function effectiveConfig(session: Session | undefined, fallback: Config): Config { diff --git a/tests/config-epoch.test.ts b/tests/config-epoch.test.ts index 3398fe1f04..1d61d0887b 100644 --- a/tests/config-epoch.test.ts +++ b/tests/config-epoch.test.ts @@ -84,6 +84,31 @@ test("config epoch: a retired externalSummary chain cannot ride a stale stamp (t } }); +test("config epoch: a live externalSummary chain survives the stale window with its provider recipes (#5912)", () => { + const dir = mkdtempSync(path.join(tmpdir(), "bili-epoch-ext-live-")); + const file = pinnedConfigFile(dir); + const providers = { sumprov: { baseUrl: "https://sum.example", api: "openai", apiKeyEnv: "SUM_KEY", models: { summodel: {} } } }; + writeFileSync(file, JSON.stringify({ providers, compress: { externalSummary: { enabled: true, targets: ["sumprov/summodel"] } } })); + process.env.BILI_CONFIG_FILE = file; + try { + const session = makeSession(); + const stamped = defaultConfig(200_000) as Config & { externalSummary?: { enabled: boolean } }; + stamped.externalSummary = { enabled: true }; + storeEffectiveConfig(session, stamped); + assert.equal(externalSummaryEnabled(effectiveConfig(session, defaultConfig(200_000))), true, "precondition: chain on while the file still declares it"); + // Any other edit moves the epoch into the stale-overlay window; the + // provider table and the chain itself are untouched. + writeFileSync(file, JSON.stringify({ providers, compress: { externalSummary: { enabled: true, targets: ["sumprov/summodel"] }, nudgeGrowthTokens: 512 } })); + const read = effectiveConfig(session, defaultConfig(200_000)) as Config & { externalSummary?: { enabled?: boolean; targets?: Array<{ model?: string; credentialRef?: string }> } }; + assert.equal(externalSummaryEnabled(read), true, "the stale window must not disable a valid chain"); + assert.equal(read.externalSummary?.targets?.[0]?.model, "summodel", "the target expands against the live named-provider table"); + assert.equal(read.externalSummary?.targets?.[0]?.credentialRef, "env:SUM_KEY", "the credential reference rides the expanded target"); + } finally { + delete process.env.BILI_CONFIG_FILE; + rmSync(dir, { recursive: true, force: true }); + } +}); + test("config epoch: byte-identical files at different paths are the same source (cross-lane stamps validate)", () => { const dirA = mkdtempSync(path.join(tmpdir(), "bili-epoch-laneA-")); const dirB = mkdtempSync(path.join(tmpdir(), "bili-epoch-laneB-"));