Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix(agent): retain notice on empty response cutoff
Emre Sokullu9eb77710b56e
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 5c92c9dc1..eeff1b25e 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -26277,7 +26277,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// A reply that stopped at the output limit is an error on some providers. The// side-panel answer still shows what was written, marked as cut off below.const partial = phase === 'response_only' ? cutOffPartialFromError(error) : '';- if (!partial) throw error;+ if (!partial) {+ // OpenAI Responses can spend the entire output budget on reasoning. If that+ // same call exhausted the allowance, retain its notice rather than routing+ // it through generic failure recovery, which does not preserve it.+ if (phase === 'response_only'+ && error?.costAllowanceMessage+ && ['length', 'max_tokens', 'max_output_tokens', 'max_completion_tokens'].includes(String(error?.incompleteReason))) {+ return `${RESPONSE_CUT_OFF_NOTICE.trim()}\n\n${error.costAllowanceMessage}`;+ }+ throw error;+ }result = {content: Agent._stripReasoningTags(partial),toolCalls: [],diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex e649937b4..134127e12 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -23418,7 +23418,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// A reply that stopped at the output limit is an error on some providers. The// side-panel answer still shows what was written, marked as cut off below.const partial = phase === 'response_only' ? cutOffPartialFromError(error) : '';- if (!partial) throw error;+ if (!partial) {+ // OpenAI Responses can spend the entire output budget on reasoning. If that+ // same call exhausted the allowance, retain its notice rather than routing+ // it through generic failure recovery, which does not preserve it.+ if (phase === 'response_only'+ && error?.costAllowanceMessage+ && ['length', 'max_tokens', 'max_output_tokens', 'max_completion_tokens'].includes(String(error?.incompleteReason))) {+ return `${RESPONSE_CUT_OFF_NOTICE.trim()}\n\n${error.costAllowanceMessage}`;+ }+ throw error;+ }result = {content: Agent._stripReasoningTags(partial),toolCalls: [],diff --git a/test/post-submit-model-recovery.mjs b/test/post-submit-model-recovery.mjsindex e55491463..ba9d7e6d4 100644--- a/test/post-submit-model-recovery.mjs+++ b/test/post-submit-model-recovery.mjs@@ -153,6 +153,27 @@ for (const browser of ['chrome', 'firefox']) {}});+ test(`${browser}: textless response-only cutoffs retain their allowance notice`, async () => {+ const f = fixture(); f.agent._persist = () => {};+ const notice = 'Cloud cost allowance reached: total cloud/router usage is $5.00 against the $5.00 limit.';+ f.agent._completionEvidenceMessages = (_tab, messages) => messages;+ f.agent._pruneOldImages = messages => messages;+ f.agent._providerMaxOutputTokens = () => 100;+ f.agent._chatWithCostAllowance = async () => {+ throw Object.assign(new Error('Output limit reached'), {+ incompleteReason: 'max_output_tokens',+ partialContent: '',+ costAllowanceMessage: notice,+ });+ };+ const provider = { contextWindow: 128000 };+ const answer = await f.agent._generateContextOnlyResponse(f.tab, f.messages, provider, {}, null, {+ phase: 'response_only', step: 1,+ });+ assert.match(answer, /output limit and was cut off/i);+ assert.match(answer, /cost allowance reached/i);+ });+test(`${browser}: a stopped interaction offers Retry without replaying tools or overriding publication audit`, async () => {const f = fixture(); f.agent._persist = () => {};f.agent._generateContextOnlyResponse = async () => '';