Skip to content

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

Keep the text of a side-panel continuation that OpenAI Responses cuts off

Claude7b3866a0bc6a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7342b8b26..765700c9d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,7 @@ This changelog was generated from the repository Git history and release tags. V
## [Unreleased]
### Changed
-- Selecting text on a page now shows a small bar, **Translate | Explain | Proofread | More…**, instead of the single `?` button. Translate, Explain and Proofread answer in a card next to the selection: Translate shows the detected source language, the original text and a target-language picker, and every card has an "Ask a follow-up" box that, once the answer is there, continues in the side panel with the card's answer as context. **More…** opens the same popup the `?` button opened (Summarize, Quiz me, Humanize, a question box and Hide this; Translate, Explain and Proofread are on the bar, so they are not repeated there). A card sends the selected text to your configured model provider, like any other selection action; selections over 4,000 characters go to the side panel instead of a card. A card answer that reaches the model's output limit says it was cut off and offers to continue in the side panel, which picks up from the unfinished text instead of starting over (a side-panel reply that is cut off again says so), and closing or redoing a card cancels the request it no longer needs. Chrome and Firefox.
+- Selecting text on a page now shows a small bar, **Translate | Explain | Proofread | More…**, instead of the single `?` button. Translate, Explain and Proofread answer in a card next to the selection: Translate shows the detected source language, the original text and a target-language picker, and every card has an "Ask a follow-up" box that, once the answer is there, continues in the side panel with the card's answer as context. **More…** opens the same popup the `?` button opened (Summarize, Quiz me, Humanize, a question box and Hide this; Translate, Explain and Proofread are on the bar, so they are not repeated there). A card sends the selected text to your configured model provider, like any other selection action; selections over 4,000 characters go to the side panel instead of a card. A card answer that reaches the model's output limit says it was cut off and offers to continue in the side panel, which picks up from the unfinished text instead of starting over (a side-panel reply that is cut off again says so, including when an OpenAI Responses model reports the limit as an error, in which case the text it wrote is kept), and closing or redoing a card cancels the request it no longer needs. Chrome and Firefox.
### Fixed
- Chrome: sending a follow-up or a selection action to WebBrain while the side panel is already open no longer closes it. Each side panel now tells the background whether it is on screen, and the background skips re-opening a panel that is already showing and hands it the prompt directly.
diff --git a/docs/architecture.md b/docs/architecture.md
index 986e778f0..b93c9aae7 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -530,9 +530,10 @@ of passing a cut-off translation off as complete. Continue sends the unfinished
`continueFrom`; the background wraps it inside the selection's untrusted block (keeping its
end) with a trusted request to resume from where it stops, because running the action again
would meet the same output limit. A side-panel reply that is cut off again says so (the
-response-only path appends a notice when the provider reports a length finish or WebGPU
-reports `outputTruncated`), so a long remainder never passes as complete and can be
-continued by asking. Each call carries a job id, and a card
+response-only path appends a notice when the provider reports a length finish, WebGPU
+reports `outputTruncated`, or OpenAI Responses raises the limit as an error carrying
+`partialContent`, whose text is then shown), so a long remainder never passes as complete
+and can be continued by asking. Each call carries a job id, and a card
that is closed, retried or retargeted sends `WB_SELECTION_SHORTCUT_INLINE_CANCEL` so the
background aborts the paid request it no longer needs (for the in-browser WebGPU models the
provider also sends `webgpu-chat-cancel`, and the offscreen worker interrupts the running
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index f8d8bc967..6ba64e8dd 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -162,7 +162,7 @@ import { generateImage, readMediaConfig } from './generative-media.js';
import { GENERATIVE_MEDIA_SETUP_NOTE, isImageGenConfigured, mediaPermissionUrl, validateMediaConfig } from './media-config.js';
import { extractFirstJsonObject } from './json-extract.js';
import { repairAssistantDisplayText, repairClarifyText, sanitizeText as sanitizePlannerText } from './text-sanitize.js';
-import { RESPONSE_CUT_OFF_NOTICE, emptyOutputFailureMessage, modelOutputDiagnostics, outputWasCutOff } from './model-output-diagnostics.js';
+import { RESPONSE_CUT_OFF_NOTICE, cutOffPartialFromError, emptyOutputFailureMessage, modelOutputDiagnostics, outputWasCutOff } from './model-output-diagnostics.js';
import { stepLimitUserMessage, terminalGuardUserMessage } from './terminal-messages.js';
import { buildCustomSkillsPrompt, buildSkillLoaderDefinition, buildSkillToolDefinitions, buildSkillToolRegistry, getEligibleCustomSkills, getEligibleSkillCatalog, normalizeCustomSkills } from './skills.js';
import { OTP_EMAIL_PROVIDER_IDS, OTP_EMAIL_SKILL_ID, OTP_EMAIL_TOOL_NAME, otpEmailCandidates, otpEmailProviderForUrl, otpEmailUrlLooksLikeMessage, otpOpenMessageRootRef, otpRedactRefs, otpServiceDisplay, otpServiceKey, otpVerificationMessageExcerpt, selectOtpMailboxTab, selectUniqueOtpCandidateByPreview } from './otp-email-tool.js';
@@ -26049,13 +26049,26 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} catch {}
}
const startedAt = Date.now();
- const result = await this._chatWithCostAllowance(
- provider,
- prunedMessages,
- chatOpts,
- costState,
- { tabId, generationName: phase },
- );
+ let result;
+ try {
+ result = await this._chatWithCostAllowance(
+ provider,
+ prunedMessages,
+ chatOpts,
+ costState,
+ { tabId, generationName: phase },
+ );
+ } catch (error) {
+ // 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;
+ result = {
+ content: Agent._stripReasoningTags(partial),
+ toolCalls: [],
+ finishReason: String(error.incompleteReason),
+ };
+ }
const latencyMs = Date.now() - startedAt;
this._logDebug({
type: `${phase}_response`,
diff --git a/src/chrome/src/agent/model-output-diagnostics.js b/src/chrome/src/agent/model-output-diagnostics.js
index bcfce7a1b..21c8f85be 100644
--- a/src/chrome/src/agent/model-output-diagnostics.js
+++ b/src/chrome/src/agent/model-output-diagnostics.js
@@ -124,7 +124,7 @@ export function modelOutputDiagnostics(result, { requestedMaxTokens = null, reco
}
// A finish reason that means the reply stopped because it ran out of output budget.
-const CUT_OFF_FINISH_RE = /^(?:length|max_tokens|max_output_tokens|output_limit)$/i;
+const CUT_OFF_FINISH_RE = /^(?:length|max_tokens|max_output_tokens|max_completion_tokens|output_limit)$/i;
export const RESPONSE_CUT_OFF_NOTICE = '\n\n[This reply reached the model\'s output limit and was cut off. Ask WebBrain to continue to get the rest.]';
@@ -135,6 +135,14 @@ export function outputWasCutOff(result) {
return CUT_OFF_FINISH_RE.test(finishReasonFor(result));
}
+// Some providers (OpenAI Responses) report the output limit as an error rather than a
+// result, with what the model wrote attached. Returns that text, or '' when the error
+// is not a cut-off or carries nothing to show.
+export function cutOffPartialFromError(error) {
+ if (!CUT_OFF_FINISH_RE.test(String(error?.incompleteReason ?? '').trim())) return '';
+ return String(error?.partialContent ?? '').trim();
+}
+
export function emptyOutputFailureMessage(diagnostics = {}) {
switch (diagnostics.emptyReason) {
case 'output_limit':
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index b4bb899e7..20cc3b9ac 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -154,7 +154,7 @@ import { generateImage, readMediaConfig } from './generative-media.js';
import { GENERATIVE_MEDIA_SETUP_NOTE, isImageGenConfigured, mediaPermissionUrl, validateMediaConfig } from './media-config.js';
import { extractFirstJsonObject } from './json-extract.js';
import { repairAssistantDisplayText, repairClarifyText, sanitizeText as sanitizePlannerText } from './text-sanitize.js';
-import { RESPONSE_CUT_OFF_NOTICE, emptyOutputFailureMessage, modelOutputDiagnostics, outputWasCutOff } from './model-output-diagnostics.js';
+import { RESPONSE_CUT_OFF_NOTICE, cutOffPartialFromError, emptyOutputFailureMessage, modelOutputDiagnostics, outputWasCutOff } from './model-output-diagnostics.js';
import { stepLimitUserMessage, terminalGuardUserMessage } from './terminal-messages.js';
import { buildCustomSkillsPrompt, buildSkillLoaderDefinition, buildSkillToolDefinitions, buildSkillToolRegistry, getEligibleCustomSkills, getEligibleSkillCatalog, normalizeCustomSkills } from './skills.js';
import { OTP_EMAIL_PROVIDER_IDS, OTP_EMAIL_SKILL_ID, OTP_EMAIL_TOOL_NAME, otpEmailCandidates, otpEmailProviderForUrl, otpEmailUrlLooksLikeMessage, otpOpenMessageRootRef, otpRedactRefs, otpServiceDisplay, otpServiceKey, otpVerificationMessageExcerpt, selectOtpMailboxTab, selectUniqueOtpCandidateByPreview } from './otp-email-tool.js';
@@ -23204,13 +23204,26 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} catch {}
}
const startedAt = Date.now();
- const result = await this._chatWithCostAllowance(
- provider,
- prunedMessages,
- chatOpts,
- costState,
- { tabId, generationName: phase },
- );
+ let result;
+ try {
+ result = await this._chatWithCostAllowance(
+ provider,
+ prunedMessages,
+ chatOpts,
+ costState,
+ { tabId, generationName: phase },
+ );
+ } catch (error) {
+ // 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;
+ result = {
+ content: Agent._stripReasoningTags(partial),
+ toolCalls: [],
+ finishReason: String(error.incompleteReason),
+ };
+ }
const latencyMs = Date.now() - startedAt;
this._logDebug({
type: `${phase}_response`,
diff --git a/src/firefox/src/agent/model-output-diagnostics.js b/src/firefox/src/agent/model-output-diagnostics.js
index bcfce7a1b..21c8f85be 100644
--- a/src/firefox/src/agent/model-output-diagnostics.js
+++ b/src/firefox/src/agent/model-output-diagnostics.js
@@ -124,7 +124,7 @@ export function modelOutputDiagnostics(result, { requestedMaxTokens = null, reco
}
// A finish reason that means the reply stopped because it ran out of output budget.
-const CUT_OFF_FINISH_RE = /^(?:length|max_tokens|max_output_tokens|output_limit)$/i;
+const CUT_OFF_FINISH_RE = /^(?:length|max_tokens|max_output_tokens|max_completion_tokens|output_limit)$/i;
export const RESPONSE_CUT_OFF_NOTICE = '\n\n[This reply reached the model\'s output limit and was cut off. Ask WebBrain to continue to get the rest.]';
@@ -135,6 +135,14 @@ export function outputWasCutOff(result) {
return CUT_OFF_FINISH_RE.test(finishReasonFor(result));
}
+// Some providers (OpenAI Responses) report the output limit as an error rather than a
+// result, with what the model wrote attached. Returns that text, or '' when the error
+// is not a cut-off or carries nothing to show.
+export function cutOffPartialFromError(error) {
+ if (!CUT_OFF_FINISH_RE.test(String(error?.incompleteReason ?? '').trim())) return '';
+ return String(error?.partialContent ?? '').trim();
+}
+
export function emptyOutputFailureMessage(diagnostics = {}) {
switch (diagnostics.emptyReason) {
case 'output_limit':
diff --git a/test/run.js b/test/run.js
index 099e687e5..602425a5e 100644
--- a/test/run.js
+++ b/test/run.js
@@ -53754,6 +53754,55 @@ test('a response-only reply that hit the output limit says so instead of reading
}
});
+test('a response-only reply cut off as a Responses error keeps its text and says so', async () => {
+ const { cutOffPartialFromError: partialCh, RESPONSE_CUT_OFF_NOTICE: noticeCh } = await import(
+ pathToFileURL(path.join(ROOT, 'src/chrome/src/agent/model-output-diagnostics.js')).href
+ );
+ const { cutOffPartialFromError: partialFx } = await import(
+ pathToFileURL(path.join(ROOT, 'src/firefox/src/agent/model-output-diagnostics.js')).href
+ );
+ for (const cutOffPartial of [partialCh, partialFx]) {
+ assert.equal(cutOffPartial({ incompleteReason: 'max_output_tokens', partialContent: ' Half ' }), 'Half');
+ assert.equal(cutOffPartial({ incompleteReason: 'MAX_OUTPUT_TOKENS', partialContent: 'Half' }), 'Half');
+ assert.equal(cutOffPartial({ incompleteReason: 'max_completion_tokens', partialContent: 'Half' }), 'Half');
+ assert.equal(cutOffPartial({ incompleteReason: 'max_output_tokens' }), '', 'no text, nothing to show');
+ assert.equal(cutOffPartial({ incompleteReason: 'content_filter', partialContent: 'Half' }), '', 'a filter is a failure');
+ assert.equal(cutOffPartial({ incompleteReason: 'missing_response_completed', partialContent: 'Half' }), '');
+ assert.equal(cutOffPartial(new Error('network')), '');
+ assert.equal(cutOffPartial(null), '');
+ }
+
+ for (const [label, AgentClass, Provider] of [['chrome', AgentCh, OpenAIProviderCh], ['firefox', AgentFx, OpenAIProviderFx]]) {
+ const responses = new Provider({
+ category: 'cloud', providerName: 'openai', baseUrl: 'https://api.openai.com/v1', model: 'gpt-5.6-terra',
+ });
+ const incomplete = (reason, text) => ({
+ status: 'incomplete',
+ incomplete_details: { reason },
+ output: text == null ? [{ type: 'reasoning', summary: [] }] : [{ type: 'message', content: [{ type: 'output_text', text }] }],
+ });
+ const run = async (data, phase = 'response_only') => {
+ const provider = {
+ supportsTools: false, supportsVision: false, promptTier: 'full', contextWindow: 128000,
+ model: 'test-model', name: 'test-provider',
+ chat: async () => responses._parseResponsesData(data),
+ };
+ const agent = new AgentClass({ getActive: () => provider, getVisionProvider: async () => null });
+ agent._checkCostAllowance = async () => null;
+ agent._recordCostUsage = async () => null;
+ return agent._generateContextOnlyResponse(
+ 1, [{ role: 'system', content: 'rules' }, { role: 'user', content: 'Translate it.' }],
+ provider, agent._newCostRunState(), null, { phase, step: 1 },
+ );
+ };
+ assert.equal(await run(incomplete('max_output_tokens', 'Second half of the ')),
+ `Second half of the${noticeCh}`, `${label}: the remainder that hit the limit is shown with the notice`);
+ await assert.rejects(run(incomplete('max_output_tokens', null)), /Responses incomplete/, `${label}: a limit spent before any text is still an error`);
+ await assert.rejects(run(incomplete('content_filter', 'Half')), /Responses incomplete/, `${label}: a content filter is still an error`);
+ await assert.rejects(run(incomplete('max_output_tokens', 'Half'), 'terminal_recovery'), /Responses incomplete/, `${label}: only the response-only phase keeps a partial`);
+ }
+});
+
test('ordinary attachments leave selection grounding and remain usable', async () => {
for (const [label, AgentClass, buildSelectionPrompt, sourceGrounding] of [
['chrome', AgentCh, buildSelectionPromptCh, SELECTION_ONLY_SOURCE_GROUNDING_CH],