Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions tests/config-epoch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-"));
Expand Down
Loading