Skip to content

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

fix(research): retain model text before local search rewrites

Emre Sokullu51400eb84ccc
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 903884cee..e3fec1249 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -41224,6 +41224,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
break;
}
+ // Keep provider text before local-search rewrites or display repairs.
+ const rawProviderContent = String(result.content ?? '');
+
// LFM can emit native Google/Wikipedia search markup even though this
// profile advertises no tools. Treat it as a request to search the
// installed archive, never as permission to use the browser or network.
@@ -41609,8 +41612,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
onUpdate('warning', { message: finalResponse });
break;
}
- // Preserve provider text before display repairs and local notices.
- shareRawResponse = String(result.content ?? '');
+ shareRawResponse = rawProviderContent;
const repairedFinalContent = repairAssistantDisplayText(result.content);
finalResponse = result.costAllowanceMessage
? `${repairedFinalContent}\n\n${result.costAllowanceMessage}`
@@ -42286,6 +42288,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
this._throwIfAborted(streamOpts.signal);
fullText = Agent._stripReasoningTags(fullText);
+ // Capture the completion before local-search or presentation rewrites.
+ const rawProviderContent = fullText;
const streamedToolCalls = hasToolCalls ? Object.values(toolCallsAccumulator) : [];
const outputDiagnostics = modelOutputDiagnostics({
content: fullText,
@@ -42648,8 +42652,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
closeTraceStep({ ok: false, code: 'EMPTY_RESPONSE' });
return finish(incompleteFailure, 'incomplete_output');
}
- // Streaming text is still the provider's raw completion at this point.
- shareRawResponse = fullText;
+ shareRawResponse = rawProviderContent;
const repairedFullText = repairAssistantDisplayText(fullText);
if (repairedFullText !== fullText) {
fullText = repairedFullText;
diff --git a/test/run.js b/test/run.js
index f5afeaf42..1599c05b5 100644
--- a/test/run.js
+++ b/test/run.js
@@ -69066,6 +69066,44 @@ test('shared completions retain provider text before terminal display repairs',
}
});
+test('shared WebGPU completions retain repeated search markup before local replacement', async () => {
+ for (const streaming of [false, true]) {
+ const responses = [
+ "<|tool_call_start|>[google(query='Ada Lovelace')]<|tool_call_end|>",
+ "<|tool_call_start|>[google(query='Ada Lovelace birth date')]<|tool_call_end|>",
+ ];
+ let calls = 0;
+ const provider = {
+ supportsTools: false, supportsVision: false, promptTier: 'full', contextWindow: 128000,
+ model: 'test-webgpu', name: 'WebGPU',
+ async chat() { return { content: responses[calls++], toolCalls: [] }; },
+ async *chatStream() { yield { type: 'text', content: responses[calls++] }; yield { type: 'done' }; },
+ };
+ const agent = new AgentCh({ getActive: () => provider, getProvider: () => provider, getVisionProvider: async () => null });
+ const tabId = 4096;
+ configurePlanOnlyGuardAgent(agent, tabId);
+ agent._startTraceRun = async () => null;
+ agent._applyStandaloneWikipediaRag = async () => ({ attempted: true, status: 'matched', matchCount: 1 });
+ let searches = 0;
+ agent._applyStandaloneWikipediaModelSearch = async () => {
+ searches++;
+ return { attempted: true, status: 'matched', matchCount: 1 };
+ };
+ let capture;
+ agent._endTraceRun = async (_tabId, _runId, status, content, options) => { capture = { status, content, ...options }; };
+ const runOptions = { standaloneChat: true, providerId: 'webgpu' };
+ const final = streaming
+ ? await agent.processMessageStream(tabId, 'When was Ada Lovelace born?', () => {}, 'ask', runOptions)
+ : await agent.processMessage(tabId, 'When was Ada Lovelace born?', () => {}, 'ask', [], runOptions);
+ assert.equal(calls, 2, `streaming=${streaming}: did not exercise the repeated-search terminal path`);
+ assert.equal(searches, 1, 'local search retry must remain bounded');
+ assert.match(final, /could not turn them into a reliable answer/);
+ assert.equal(capture.status, 'done');
+ assert.equal(capture.hadProviderCompletion, true);
+ assert.equal(capture.shareResponse, responses[1], `streaming=${streaming}: local replacement entered the research response`);
+ }
+});
+
test('terminal display repair normalizes JSON-quoted page title lines', async () => {
const title = 'Example Domain';
const malformed = `Verification:\n- Page title: ${JSON.stringify(title)}\n- Timestamp: 3:39 PM`;