Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Clear stale auto-window provenance upon explicit context window changes

Emre Sokullu766451c4fa16
diff --git a/src/chrome/src/providers/manager.js b/src/chrome/src/providers/manager.js
index 243b3bf02..5ac4f7b91 100644
--- a/src/chrome/src/providers/manager.js
+++ b/src/chrome/src/providers/manager.js
@@ -2025,6 +2025,18 @@ export class ProviderManager {
...updates,
configured: !WEBBRAIN_CLOUD_PROVIDER_IDS.has(id) && (markConfigured || current.configured === true),
};
+ if (Object.hasOwn(updates, 'contextWindow')) {
+ if (!Number.isFinite(Number(current.contextWindow))
+ || Number(updates.contextWindow) !== Number(current.contextWindow)
+ || Number(updates.contextWindow) !== Number(current.autoContextWindow)) {
+ delete merged.autoContextWindow;
+ }
+ } else if (Number.isFinite(Number(current.autoContextWindow)) && Number(merged.contextWindow) !== Number(current.autoContextWindow)) {
+ delete merged.autoContextWindow;
+ }
+ if (Object.hasOwn(updates, 'autoContextWindow') && updates.autoContextWindow == null) {
+ delete merged.autoContextWindow;
+ }
if (id === 'webgpu' && Object.hasOwn(updates, 'model')) {
merged.model = normalizeWebgpuModelId(merged.model);
const preset = webgpuModelPreset(merged.model);
@@ -2678,7 +2690,8 @@ export class ProviderManager {
_replaceableContextWindows(id, config) {
if (this._providerDefinitionId(id, config) !== 'local_openai_proxy') return [];
const auto = Number(config?.autoContextWindow);
- return [LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, ...(Number.isFinite(auto) && auto > 0 ? [auto] : [])];
+ const matchesCurrent = Number(config?.contextWindow) === auto;
+ return [LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, ...(Number.isFinite(auto) && auto > 0 && matchesCurrent ? [auto] : [])];
}
_detectedContextWindowFields(id, config, contextWindow) {
diff --git a/src/firefox/src/providers/manager.js b/src/firefox/src/providers/manager.js
index cdabd531a..bdbbdb37e 100644
--- a/src/firefox/src/providers/manager.js
+++ b/src/firefox/src/providers/manager.js
@@ -1606,6 +1606,18 @@ export class ProviderManager {
...updates,
configured: !WEBBRAIN_CLOUD_PROVIDER_IDS.has(id) && (markConfigured || current.configured === true),
};
+ if (Object.hasOwn(updates, 'contextWindow')) {
+ if (!Number.isFinite(Number(current.contextWindow))
+ || Number(updates.contextWindow) !== Number(current.contextWindow)
+ || Number(updates.contextWindow) !== Number(current.autoContextWindow)) {
+ delete merged.autoContextWindow;
+ }
+ } else if (Number.isFinite(Number(current.autoContextWindow)) && Number(merged.contextWindow) !== Number(current.autoContextWindow)) {
+ delete merged.autoContextWindow;
+ }
+ if (Object.hasOwn(updates, 'autoContextWindow') && updates.autoContextWindow == null) {
+ delete merged.autoContextWindow;
+ }
if (this._providerDefinitionId(id, current) === 'ollama') {
merged.visionMode = OLLAMA_VISION_MODES.has(merged.visionMode) ? merged.visionMode : 'auto';
delete merged.supportsVision;
@@ -2217,7 +2229,8 @@ export class ProviderManager {
_replaceableContextWindows(id, config) {
if (this._providerDefinitionId(id, config) !== 'local_openai_proxy') return [];
const auto = Number(config?.autoContextWindow);
- return [LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, ...(Number.isFinite(auto) && auto > 0 ? [auto] : [])];
+ const matchesCurrent = Number(config?.contextWindow) === auto;
+ return [LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, ...(Number.isFinite(auto) && auto > 0 && matchesCurrent ? [auto] : [])];
}
_detectedContextWindowFields(id, config, contextWindow) {
diff --git a/test/run.js b/test/run.js
index 350fda637..cb8eed851 100644
--- a/test/run.js
+++ b/test/run.js
@@ -73003,6 +73003,23 @@ test('Local OpenAI-compatible Proxy context window: model card, live props, mode
assert.equal(config().contextWindow, 65536);
}
+ // 5b. Stale auto provenance is cleared when Settings explicitly changes the context window.
+ // (auto 128k → manual 32k → manual 128k: the manual 128k must not be replaced by 64k)
+ {
+ const { mgr, config } = setup(async () => new Response('missing', { status: 404 }), {
+ model: 'house-model', contextWindow: 128000, autoContextWindow: 128000,
+ });
+ await mgr.updateProvider('local_openai_proxy', { contextWindow: 32768 });
+ assert.equal(config().contextWindow, 32768);
+ assert.equal(config().autoContextWindow, undefined, `${label}: manual edit clears autoContextWindow`);
+ await mgr.updateProvider('local_openai_proxy', { contextWindow: 128000 });
+ assert.equal(config().contextWindow, 128000);
+ assert.equal(config().autoContextWindow, undefined, `${label}: returning to 128k remains manual`);
+ const result = await mgr.detectProviderContextWindow('local_openai_proxy', 'house-model');
+ assert.equal(result.contextWindow, undefined, `${label}: manual 128k override is kept`);
+ assert.equal(config().contextWindow, 128000);
+ }
+
// 6. A manual override is never enlarged by a name or the fallback...
{
const { mgr, config } = setup(async () => new Response('missing', { status: 404 }), {