Skip to content

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

Do not mark untouched context window defaults as manual before detection

Emre Sokullubfb5c7e755d5
diff --git a/src/chrome/src/providers/manager.js b/src/chrome/src/providers/manager.js
index 640e9b8dd..a5136be0a 100644
--- a/src/chrome/src/providers/manager.js
+++ b/src/chrome/src/providers/manager.js
@@ -2025,8 +2025,21 @@ export class ProviderManager {
...updates,
configured: !WEBBRAIN_CLOUD_PROVIDER_IDS.has(id) && (markConfigured || current.configured === true),
};
+ if (Object.hasOwn(updates, 'manualContextWindow')) {
+ if (updates.manualContextWindow === true) {
+ merged.manualContextWindow = true;
+ } else {
+ delete merged.manualContextWindow;
+ }
+ } else if (Object.hasOwn(updates, 'contextWindow')) {
+ const updateKeys = Object.keys(updates);
+ const isTargetedContextUpdate = updateKeys.length === 1 && updateKeys[0] === 'contextWindow';
+ const isContextChanged = Number(updates.contextWindow) !== Number(current.contextWindow);
+ if (isTargetedContextUpdate || isContextChanged || current.manualContextWindow === true) {
+ merged.manualContextWindow = true;
+ }
+ }
if (Object.hasOwn(updates, 'contextWindow')) {
- merged.manualContextWindow = true;
if (!Number.isFinite(Number(current.contextWindow))
|| Number(updates.contextWindow) !== Number(current.contextWindow)
|| Number(updates.contextWindow) !== Number(current.autoContextWindow)) {
diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.js
index 496211667..e50695e37 100644
--- a/src/chrome/src/ui/settings.js
+++ b/src/chrome/src/ui/settings.js
@@ -3798,10 +3798,11 @@ function renderProviders() {
const minAttr = field.min != null ? ` min="${escapeHtml(field.min)}"` : '';
const stepAttr = field.step != null ? ` step="${escapeHtml(field.step)}"` : '';
const value = config[field.key] ?? '';
+ const manualAttr = (field.key === 'contextWindow' && config.manualContextWindow === true) ? ' data-manually-edited="true"' : '';
fieldHTML += `
<div class="field">
<label>${escapeHtml(label)}${apiKeyLink}</label>
- <input type="${field.type}" data-provider="${id}" data-key="${field.key}" data-type="${field.type}" ${listAttr}${minAttr}${stepAttr}
+ <input type="${field.type}" data-provider="${id}" data-key="${field.key}" data-type="${field.type}" ${listAttr}${minAttr}${stepAttr}${manualAttr}
value="${escapeHtml(value)}" placeholder="${escapeHtml(placeholder)}">
${datalistHTML}
${loadBtnHTML}
@@ -3926,7 +3927,12 @@ function renderProviders() {
});
document.querySelectorAll('input[data-provider], select[data-provider], textarea[data-provider]').forEach(input => {
const eventName = input.tagName === 'SELECT' ? 'change' : 'input';
- input.addEventListener(eventName, () => markProviderDirty(input.dataset.provider));
+ input.addEventListener(eventName, () => {
+ markProviderDirty(input.dataset.provider);
+ if (input.dataset.key === 'contextWindow') {
+ input.dataset.manuallyEdited = 'true';
+ }
+ });
});
document.querySelectorAll('input[data-key="shareQueriesForResearch"]').forEach(input => {
input.addEventListener('click', (event) => {
@@ -4253,9 +4259,15 @@ function applyProviderBaseUrl(id, baseUrl) {
function applyProviderContextWindow(id, contextWindow) {
const n = Number(contextWindow);
if (!Number.isFinite(n) || n <= 0) return;
- if (providersData[id]) providersData[id].contextWindow = n;
+ if (providersData[id]) {
+ providersData[id].contextWindow = n;
+ providersData[id].manualContextWindow = false;
+ }
const input = document.querySelector(`input[data-provider="${id}"][data-key="contextWindow"]`);
- if (input && input.value !== String(n)) input.value = String(n);
+ if (input) {
+ if (input.value !== String(n)) input.value = String(n);
+ input.dataset.manuallyEdited = 'false';
+ }
}
async function detectProviderContextWindowForModel(id, model) {
@@ -4384,6 +4396,9 @@ async function saveProvider(id, { showFlash = true, markConfigured = true } = {}
? parseProviderExtraBodyJson(input.value)
: providerInputValue(input);
setProviderConfigValue(config, input.dataset.key, value);
+ if (input.dataset.key === 'contextWindow') {
+ config.manualContextWindow = input.dataset.manuallyEdited === 'true';
+ }
});
if (typeof config.label === 'string') config.label = config.label.trim();
apiKeyWarning = providerApiKeyWarning(id, config);
@@ -4528,6 +4543,9 @@ function syncInputsIntoProvidersData() {
return;
}
setProviderConfigValue(providersData[id], key, providerInputValue(input));
+ if (key === 'contextWindow') {
+ providersData[id].manualContextWindow = input.dataset.manuallyEdited === 'true';
+ }
});
}
diff --git a/src/firefox/src/providers/manager.js b/src/firefox/src/providers/manager.js
index c561feffa..0ccf0384e 100644
--- a/src/firefox/src/providers/manager.js
+++ b/src/firefox/src/providers/manager.js
@@ -1606,8 +1606,21 @@ export class ProviderManager {
...updates,
configured: !WEBBRAIN_CLOUD_PROVIDER_IDS.has(id) && (markConfigured || current.configured === true),
};
+ if (Object.hasOwn(updates, 'manualContextWindow')) {
+ if (updates.manualContextWindow === true) {
+ merged.manualContextWindow = true;
+ } else {
+ delete merged.manualContextWindow;
+ }
+ } else if (Object.hasOwn(updates, 'contextWindow')) {
+ const updateKeys = Object.keys(updates);
+ const isTargetedContextUpdate = updateKeys.length === 1 && updateKeys[0] === 'contextWindow';
+ const isContextChanged = Number(updates.contextWindow) !== Number(current.contextWindow);
+ if (isTargetedContextUpdate || isContextChanged || current.manualContextWindow === true) {
+ merged.manualContextWindow = true;
+ }
+ }
if (Object.hasOwn(updates, 'contextWindow')) {
- merged.manualContextWindow = true;
if (!Number.isFinite(Number(current.contextWindow))
|| Number(updates.contextWindow) !== Number(current.contextWindow)
|| Number(updates.contextWindow) !== Number(current.autoContextWindow)) {
diff --git a/src/firefox/src/ui/settings.js b/src/firefox/src/ui/settings.js
index d59709755..0dc7f63a5 100644
--- a/src/firefox/src/ui/settings.js
+++ b/src/firefox/src/ui/settings.js
@@ -3302,10 +3302,11 @@ function renderProviders() {
const minAttr = field.min != null ? ` min="${escapeHtml(field.min)}"` : '';
const stepAttr = field.step != null ? ` step="${escapeHtml(field.step)}"` : '';
const value = config[field.key] ?? '';
+ const manualAttr = (field.key === 'contextWindow' && config.manualContextWindow === true) ? ' data-manually-edited="true"' : '';
fieldHTML += `
<div class="field">
<label>${escapeHtml(label)}${apiKeyLink}</label>
- <input type="${field.type}" data-provider="${id}" data-key="${field.key}" data-type="${field.type}" ${listAttr}${minAttr}${stepAttr}
+ <input type="${field.type}" data-provider="${id}" data-key="${field.key}" data-type="${field.type}" ${listAttr}${minAttr}${stepAttr}${manualAttr}
value="${escapeHtml(value)}" placeholder="${escapeHtml(placeholder)}">
${datalistHTML}
${loadBtnHTML}
@@ -3421,7 +3422,12 @@ function renderProviders() {
});
document.querySelectorAll('input[data-provider], select[data-provider], textarea[data-provider]').forEach(input => {
const eventName = input.tagName === 'SELECT' ? 'change' : 'input';
- input.addEventListener(eventName, () => markProviderDirty(input.dataset.provider));
+ input.addEventListener(eventName, () => {
+ markProviderDirty(input.dataset.provider);
+ if (input.dataset.key === 'contextWindow') {
+ input.dataset.manuallyEdited = 'true';
+ }
+ });
});
document.querySelectorAll('input[data-key="shareQueriesForResearch"]').forEach(input => {
input.addEventListener('click', confirmResearchSharing);
@@ -3717,9 +3723,15 @@ function applyProviderBaseUrl(id, baseUrl) {
function applyProviderContextWindow(id, contextWindow) {
const n = Number(contextWindow);
if (!Number.isFinite(n) || n <= 0) return;
- if (providersData[id]) providersData[id].contextWindow = n;
+ if (providersData[id]) {
+ providersData[id].contextWindow = n;
+ providersData[id].manualContextWindow = false;
+ }
const input = document.querySelector(`input[data-provider="${id}"][data-key="contextWindow"]`);
- if (input && input.value !== String(n)) input.value = String(n);
+ if (input) {
+ if (input.value !== String(n)) input.value = String(n);
+ input.dataset.manuallyEdited = 'false';
+ }
}
async function detectProviderContextWindowForModel(id, model) {
@@ -3846,6 +3858,9 @@ async function saveProvider(id, { showFlash = true, markConfigured = true } = {}
? parseProviderExtraBodyJson(input.value)
: providerInputValue(input);
setProviderConfigValue(config, input.dataset.key, value);
+ if (input.dataset.key === 'contextWindow') {
+ config.manualContextWindow = input.dataset.manuallyEdited === 'true';
+ }
});
if (typeof config.label === 'string') config.label = config.label.trim();
apiKeyWarning = providerApiKeyWarning(id, config);
@@ -3952,6 +3967,9 @@ function syncInputsIntoProvidersData() {
return;
}
setProviderConfigValue(providersData[id], key, providerInputValue(input));
+ if (key === 'contextWindow') {
+ providersData[id].manualContextWindow = input.dataset.manuallyEdited === 'true';
+ }
});
}
diff --git a/test/run.js b/test/run.js
index 3423cc25d..46f035dee 100644
--- a/test/run.js
+++ b/test/run.js
@@ -73035,6 +73035,43 @@ test('Local OpenAI-compatible Proxy context window: model card, live props, mode
assert.equal(config().contextWindow, 65536);
}
+ // 5d. An untouched 64k default saved before detection (e.g. from Settings serialization)
+ // is not marked manual and can be enlarged by detection.
+ {
+ const { mgr, config } = setup(async () => new Response('missing', { status: 404 }), {
+ model: '', contextWindow: 65536,
+ });
+ await mgr.updateProvider('local_openai_proxy', {
+ baseUrl: 'http://127.0.0.1:8317/v1',
+ model: 'claude-sonnet-4-5',
+ contextWindow: 65536,
+ manualContextWindow: false,
+ });
+ assert.equal(config().contextWindow, 65536);
+ assert.equal(config().manualContextWindow, undefined, `${label}: untouched 64k has no manualContextWindow`);
+ const result = await mgr.detectProviderContextWindow('local_openai_proxy', 'claude-sonnet-4-5');
+ assert.equal(result.contextWindow, 128000, `${label}: untouched 64k is enlarged to 128k by name inference`);
+ assert.equal(config().contextWindow, 128000);
+ }
+
+ // 5e. An untargeted multi-field save that includes unchanged 64k without manualContextWindow
+ // does not turn untouched default into manual override.
+ {
+ const { mgr, config } = setup(async () => new Response('missing', { status: 404 }), {
+ model: '', contextWindow: 65536,
+ });
+ await mgr.updateProvider('local_openai_proxy', {
+ baseUrl: 'http://127.0.0.1:8317/v1',
+ model: 'claude-sonnet-4-5',
+ contextWindow: 65536,
+ });
+ assert.equal(config().contextWindow, 65536);
+ assert.equal(config().manualContextWindow, undefined, `${label}: unchanged 64k in full save is not manual`);
+ const result = await mgr.detectProviderContextWindow('local_openai_proxy', 'claude-sonnet-4-5');
+ assert.equal(result.contextWindow, 128000, `${label}: unchanged 64k can be enlarged`);
+ 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 }), {