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 /btw fork orphaned tools, reload reset, and prompt loss
Codex release-state test5da37a9c5ee9
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 9a96d3130..338bf99e2 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -6130,10 +6130,26 @@ export class Agent extends LoopDetector {if (this._runningTabs.has(forkId)) throw new Error('Fork conversation is already running');await this._hydrate(sourceId);+ await this._hydrate(forkId);+ const existingFork = this.conversations.get(forkId);+ if (Array.isArray(existingFork) && existingFork.length) {+ // Reloading a /btw window reuses its popup tab id. Keep the side+ // conversation instead of resetting it to a fresh source snapshot.+ if (!this.conversationIds.get(forkId)) {+ this.conversationIds.set(forkId, `conv_${forkId}_${Date.now()}_${secureRandomBase36Token(12)}`);+ await this._persistNow(forkId);+ }+ return { conversationId: this.conversationIds.get(forkId), resumed: true };+ }+const sourceMessages = this.conversations.get(sourceId) || [];- const messages = sourceMessages.length+ let messages = sourceMessages.length? JSON.parse(JSON.stringify(sourceMessages)): [{ role: 'system', content: this._buildSystemPrompt('ask', forkId) }];+ // A fork taken mid-run can copy an assistant `tool_calls` turn before its+ // `tool` results are appended. Providers reject orphaned `tool_calls`+ // with a 400, so drop the trailing incomplete batch.+ messages = this._trimIncompleteToolTail(messages);if (messages[0]?.role === 'system') {messages[0].content = this._buildSystemPrompt('ask', forkId);} else {@@ -6158,6 +6174,45 @@ export class Agent extends LoopDetector {return { conversationId: this.conversationIds.get(forkId) };}+ _trimIncompleteToolTail(messages) {+ let end = messages.length;+ // Never drop the leading system prompt.+ while (end > 1) {+ const last = messages[end - 1];+ if (last?.role === 'assistant' && Array.isArray(last.tool_calls) && last.tool_calls.length) {+ // Assistant tool request with no following results in the slice is mid-run.+ end -= 1;+ continue;+ }+ if (last?.role === 'tool' && last.tool_call_id != null) {+ let parentIndex = -1;+ for (let i = end - 2; i >= 0; i--) {+ const m = messages[i];+ if (m?.role === 'assistant' && Array.isArray(m.tool_calls) && m.tool_calls.some((tc) => tc?.id === last.tool_call_id)) {+ parentIndex = i;+ break;+ }+ }+ if (parentIndex === -1) {+ end -= 1;+ continue;+ }+ const requested = messages[parentIndex].tool_calls.map((tc) => tc?.id).filter(Boolean);+ const answered = new Set();+ for (let i = parentIndex + 1; i < end; i++) {+ const m = messages[i];+ if (m?.role === 'tool' && m.tool_call_id != null) answered.add(m.tool_call_id);+ }+ if (requested.every((id) => answered.has(id))) break;+ // Incomplete batch — drop the parent request and its partial results.+ end = parentIndex;+ continue;+ }+ break;+ }+ return messages.slice(0, end);+ }+_rememberWorkflowDraftFromCapture(tabId, capture) {if (!capture?.run || capture.run.status !== 'done') return false;const conversationId = this.conversationIds.get(tabId) || null;diff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex 1ea7dd06d..a77797687 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -3235,8 +3235,10 @@ async function handleMessage(msg, sender) {throw new Error('No source or fork tab ID');}const fork = await agent.forkConversation(sourceTabId, forkTabId);- const sourceChat = await tabChatHandoff.load(sourceTabId, { waitForHandoff: true });- if (sourceChat?.found) await tabChatHandoff.save(forkTabId, sourceChat.html);+ if (!fork?.resumed) {+ const sourceChat = await tabChatHandoff.load(sourceTabId, { waitForHandoff: true });+ if (sourceChat?.found) await tabChatHandoff.save(forkTabId, sourceChat.html);+ }return { ok: true, ...fork };}diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.jsindex 2708580d3..d884738bc 100644--- a/src/chrome/src/ui/sidepanel.js+++ b/src/chrome/src/ui/sidepanel.js@@ -89,6 +89,15 @@ const _btwParams = new URLSearchParams(window.location.search);const isBtwWindow = _btwParams.get('btw') === '1';const btwSourceTabId = isBtwWindow ? (Number(_btwParams.get('forkFromTabId')) || null) : null;const btwInitialPrompt = isBtwWindow ? (_btwParams.get('prompt') || '') : '';+let _btwReadyResolve = null;+let _btwReadySettled = false;+const btwReady = new Promise((resolve) => { _btwReadyResolve = resolve; });+if (!isBtwWindow && _btwReadyResolve) { _btwReadySettled = true; _btwReadyResolve(); }+function markBtwReady() {+ if (_btwReadySettled) return;+ _btwReadySettled = true;+ _btwReadyResolve?.();+}// Hydrate the theme from chrome.storage.local (the inline <head> bootstrap// only sees localStorage; if the user changes the theme on another device@@ -4658,10 +4667,14 @@ async function init() {let initialTabId = tab?.id;if (isBtwWindow && btwSourceTabId != null && initialTabId != null) {- await sendToBackground('fork_standalone_conversation', {- sourceTabId: btwSourceTabId,- forkTabId: initialTabId,- });+ try {+ await sendToBackground('fork_standalone_conversation', {+ sourceTabId: btwSourceTabId,+ forkTabId: initialTabId,+ });+ } catch {+ // Degrade to an empty standalone window rather than aborting init.+ }} else {try {const state = await sendToBackground('agent_run_state', { tabId: initialTabId });@@ -4790,9 +4803,9 @@ async function init() {});if (isBtwWindow) {+ markBtwReady();// Auto-send the initial prompt if provided.if (btwInitialPrompt) {- await new Promise(r => setTimeout(r, 300));await sendBtwPrompt(btwInitialPrompt);}await consumePendingBtwPrompt();@@ -14694,7 +14707,11 @@ async function openBtwWindow(tabId, prompt = '') {if (win) {await chrome.windows.update(existing.windowId, { focused: true });if (prompt) {- await setBtwWindowState(tabId, { ...existing, pendingPrompt: prompt });+ const queued = Array.isArray(existing.pendingPrompts)+ ? existing.pendingPrompts.filter((p) => typeof p === 'string' && p)+ : (typeof existing.pendingPrompt === 'string' && existing.pendingPrompt ? [existing.pendingPrompt] : []);+ queued.push(prompt);+ await setBtwWindowState(tabId, { ...existing, pendingPrompt: prompt, pendingPrompts: queued });const target = win.tabs?.[0];if (target?.id != null) {await chrome.tabs.sendMessage(target.id, { action: 'btw_prompt', prompt }).catch(() => {});@@ -14725,18 +14742,25 @@ async function sendBtwPrompt(prompt) {await sendMessage();}-async function consumePendingBtwPrompt() {+async function consumePendingBtwPrompt(directPrompt = '') {if (!isBtwWindow || btwSourceTabId == null) return;+ await btwReady;const state = await getBtwWindowState(btwSourceTabId);- const prompt = String(state?.pendingPrompt || '');- if (!prompt) return;- await setBtwWindowState(btwSourceTabId, { ...state, pendingPrompt: '' });- await sendBtwPrompt(prompt);+ let prompts = Array.isArray(state?.pendingPrompts)+ ? state.pendingPrompts.filter((p) => typeof p === 'string' && p)+ : (typeof state?.pendingPrompt === 'string' && state.pendingPrompt ? [state.pendingPrompt] : []);+ const direct = String(directPrompt || '');+ if (direct && prompts[prompts.length - 1] !== direct) prompts.push(direct);+ if (!prompts.length) return;+ await setBtwWindowState(btwSourceTabId, { ...state, pendingPrompt: '', pendingPrompts: [] });+ for (const p of prompts) {+ await sendBtwPrompt(p);+ }}chrome.runtime.onMessage.addListener((msg) => {if (!isBtwWindow || msg?.action !== 'btw_prompt') return;- void consumePendingBtwPrompt().catch(() => {});+ void consumePendingBtwPrompt(msg?.prompt).catch(() => {});});if (expandBtn) {diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 3c983412f..b3f40d88b 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -6250,10 +6250,26 @@ export class Agent extends LoopDetector {if (this._runningTabs.has(forkId)) throw new Error('Fork conversation is already running');await this._hydrate(sourceId);+ await this._hydrate(forkId);+ const existingFork = this.conversations.get(forkId);+ if (Array.isArray(existingFork) && existingFork.length) {+ // Reloading a /btw window reuses its popup tab id. Keep the side+ // conversation instead of resetting it to a fresh source snapshot.+ if (!this.conversationIds.get(forkId)) {+ this.conversationIds.set(forkId, `conv_${forkId}_${Date.now()}_${secureRandomBase36Token(12)}`);+ await this._persistNow(forkId);+ }+ return { conversationId: this.conversationIds.get(forkId), resumed: true };+ }+const sourceMessages = this.conversations.get(sourceId) || [];- const messages = sourceMessages.length+ let messages = sourceMessages.length? JSON.parse(JSON.stringify(sourceMessages)): [{ role: 'system', content: this._buildSystemPrompt('ask', forkId) }];+ // A fork taken mid-run can copy an assistant `tool_calls` turn before its+ // `tool` results are appended. Providers reject orphaned `tool_calls`+ // with a 400, so drop the trailing incomplete batch.+ messages = this._trimIncompleteToolTail(messages);if (messages[0]?.role === 'system') {messages[0].content = this._buildSystemPrompt('ask', forkId);} else {@@ -6278,6 +6294,45 @@ export class Agent extends LoopDetector {return { conversationId: this.conversationIds.get(forkId) };}+ _trimIncompleteToolTail(messages) {+ let end = messages.length;+ // Never drop the leading system prompt.+ while (end > 1) {+ const last = messages[end - 1];+ if (last?.role === 'assistant' && Array.isArray(last.tool_calls) && last.tool_calls.length) {+ // Assistant tool request with no following results in the slice is mid-run.+ end -= 1;+ continue;+ }+ if (last?.role === 'tool' && last.tool_call_id != null) {+ let parentIndex = -1;+ for (let i = end - 2; i >= 0; i--) {+ const m = messages[i];+ if (m?.role === 'assistant' && Array.isArray(m.tool_calls) && m.tool_calls.some((tc) => tc?.id === last.tool_call_id)) {+ parentIndex = i;+ break;+ }+ }+ if (parentIndex === -1) {+ end -= 1;+ continue;+ }+ const requested = messages[parentIndex].tool_calls.map((tc) => tc?.id).filter(Boolean);+ const answered = new Set();+ for (let i = parentIndex + 1; i < end; i++) {+ const m = messages[i];+ if (m?.role === 'tool' && m.tool_call_id != null) answered.add(m.tool_call_id);+ }+ if (requested.every((id) => answered.has(id))) break;+ // Incomplete batch — drop the parent request and its partial results.+ end = parentIndex;+ continue;+ }+ break;+ }+ return messages.slice(0, end);+ }+/*** Snapshot the effective runtime settings for a run. Anything we cannot* observe is omitted rather than guessed: an absent field reads as "unknown"diff --git a/src/firefox/src/background.js b/src/firefox/src/background.jsindex adacbc22f..a8384ba79 100644--- a/src/firefox/src/background.js+++ b/src/firefox/src/background.js@@ -2750,8 +2750,10 @@ async function handleMessage(msg, sender) {throw new Error('No source or fork tab ID');}const fork = await agent.forkConversation(sourceTabId, forkTabId);- const sourceChat = await tabChatHandoff.load(sourceTabId, { waitForHandoff: true });- if (sourceChat?.found) await tabChatHandoff.save(forkTabId, sourceChat.html);+ if (!fork?.resumed) {+ const sourceChat = await tabChatHandoff.load(sourceTabId, { waitForHandoff: true });+ if (sourceChat?.found) await tabChatHandoff.save(forkTabId, sourceChat.html);+ }return { ok: true, ...fork };}diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.jsindex 78b3a8cb6..1e43773b2 100644--- a/src/firefox/src/ui/sidepanel.js+++ b/src/firefox/src/ui/sidepanel.js@@ -95,6 +95,15 @@ const _btwParams = new URLSearchParams(window.location.search);const isBtwWindow = _btwParams.get('btw') === '1';const btwSourceTabId = isBtwWindow ? (Number(_btwParams.get('forkFromTabId')) || null) : null;const btwInitialPrompt = isBtwWindow ? (_btwParams.get('prompt') || '') : '';+let _btwReadyResolve = null;+let _btwReadySettled = false;+const btwReady = new Promise((resolve) => { _btwReadyResolve = resolve; });+if (!isBtwWindow && _btwReadyResolve) { _btwReadySettled = true; _btwReadyResolve(); }+function markBtwReady() {+ if (_btwReadySettled) return;+ _btwReadySettled = true;+ _btwReadyResolve?.();+}// Hydrate the theme from browser.storage.local (the inline <head> bootstrap// only sees localStorage; if the user changes the theme on another device@@ -4521,10 +4530,14 @@ async function init() {let initialTabId = tab?.id;if (isBtwWindow && btwSourceTabId != null && initialTabId != null) {- await sendToBackground('fork_standalone_conversation', {- sourceTabId: btwSourceTabId,- forkTabId: initialTabId,- });+ try {+ await sendToBackground('fork_standalone_conversation', {+ sourceTabId: btwSourceTabId,+ forkTabId: initialTabId,+ });+ } catch {+ // Degrade to an empty standalone window rather than aborting init.+ }} else {try {const state = await sendToBackground('agent_run_state', { tabId: initialTabId });@@ -4645,9 +4658,9 @@ async function init() {});if (isBtwWindow) {+ markBtwReady();// Auto-send the initial prompt if provided.if (btwInitialPrompt) {- await new Promise(r => setTimeout(r, 300));await sendBtwPrompt(btwInitialPrompt);}await consumePendingBtwPrompt();@@ -14192,7 +14205,11 @@ async function openBtwWindow(tabId, prompt = '') {if (win) {await browser.windows.update(win.id, { focused: true });if (prompt) {- await setBtwWindowState(tabId, { ...existing, pendingPrompt: prompt });+ const queued = Array.isArray(existing.pendingPrompts)+ ? existing.pendingPrompts.filter((p) => typeof p === 'string' && p)+ : (typeof existing.pendingPrompt === 'string' && existing.pendingPrompt ? [existing.pendingPrompt] : []);+ queued.push(prompt);+ await setBtwWindowState(tabId, { ...existing, pendingPrompt: prompt, pendingPrompts: queued });const target = win.tabs?.[0];if (target?.id != null) {await browser.tabs.sendMessage(target.id, { action: 'btw_prompt', prompt }).catch(() => {});@@ -14220,18 +14237,25 @@ async function sendBtwPrompt(prompt) {await sendMessage();}-async function consumePendingBtwPrompt() {+async function consumePendingBtwPrompt(directPrompt = '') {if (!isBtwWindow || btwSourceTabId == null) return;+ await btwReady;const state = await getBtwWindowState(btwSourceTabId);- const prompt = String(state?.pendingPrompt || '');- if (!prompt) return;- await setBtwWindowState(btwSourceTabId, { ...state, pendingPrompt: '' });- await sendBtwPrompt(prompt);+ let prompts = Array.isArray(state?.pendingPrompts)+ ? state.pendingPrompts.filter((p) => typeof p === 'string' && p)+ : (typeof state?.pendingPrompt === 'string' && state.pendingPrompt ? [state.pendingPrompt] : []);+ const direct = String(directPrompt || '');+ if (direct && prompts[prompts.length - 1] !== direct) prompts.push(direct);+ if (!prompts.length) return;+ await setBtwWindowState(btwSourceTabId, { ...state, pendingPrompt: '', pendingPrompts: [] });+ for (const p of prompts) {+ await sendBtwPrompt(p);+ }}browser.runtime.onMessage.addListener((msg) => {if (!isBtwWindow || msg?.action !== 'btw_prompt') return;- void consumePendingBtwPrompt().catch(() => {});+ void consumePendingBtwPrompt(msg?.prompt).catch(() => {});});if (expandBtn) {diff --git a/test/run.js b/test/run.jsindex f290cb43a..d961030b9 100644--- a/test/run.js+++ b/test/run.js@@ -47797,11 +47797,18 @@ test('chrome sidepanel serializes tab-chat storage writes with clears and reads'assert.match(panel, /if \(isBtwWindow && btwSourceTabId != null && initialTabId != null\) \{[\s\S]*?sendToBackground\('fork_standalone_conversation', \{[\s\S]*?sourceTabId: btwSourceTabId,[\s\S]*?forkTabId: initialTabId,/, 'chrome: /btw must use its popup tab as an independent fork scope');assert.match(panel, /async function openBtwWindow\(tabId, prompt = ''\) \{[\s\S]*?const existing = await getBtwWindowState\(tabId\);[\s\S]*?forkFromTabId=\$\{tabId\}/, 'chrome: /btw should only reuse a popup for the same source tab');assert.match(panel, /async function openBtwWindow\(tabId, prompt = ''\) \{[\s\S]*?pendingPrompt: prompt[\s\S]*?chrome\.tabs\.sendMessage\(target\.id, \{ action: 'btw_prompt', prompt \}\)\.catch\(\(\) => \{\}\);/, 'chrome: /btw should retain a prompt until its same-tab window receives it');- assert.match(panel, /async function consumePendingBtwPrompt\(\) \{[\s\S]*?pendingPrompt: ''[\s\S]*?await sendBtwPrompt\(prompt\);/, 'chrome: a /btw window should consume retained forwarded prompts');+ assert.match(panel, /async function consumePendingBtwPrompt\(directPrompt = ''\) \{[\s\S]*?await btwReady;[\s\S]*?pendingPrompts: \[\][\s\S]*?for \(const p of prompts\) \{[\s\S]*?await sendBtwPrompt\(p\);/, 'chrome: a /btw window should drain queued forwarded prompts after readiness');+ assert.match(panel, /void consumePendingBtwPrompt\(msg\?\.prompt\)/, 'chrome: /btw prompt listener should forward the message payload instead of dropping it');+ assert.match(panel, /pendingPrompts: queued/, 'chrome: /btw should queue concurrent prompts instead of overwriting a single slot');+ assert.match(panel, /markBtwReady\(\);[\s\S]*?await sendBtwPrompt\(btwInitialPrompt\)/, 'chrome: /btw auto-send should run after readiness without a fixed delay');+ assert.match(panel, /try \{\s*await sendToBackground\('fork_standalone_conversation'/, 'chrome: /btw fork bootstrap must not abort panel init on failure');const chromeBackground = fs.readFileSync(path.join(ROOT, 'src/chrome/src/background.js'), 'utf8');const chromeAgent = fs.readFileSync(path.join(ROOT, 'src/chrome/src/agent/agent.js'), 'utf8');assert.match(chromeBackground, /case 'fork_standalone_conversation':[\s\S]*?agent\.forkConversation\(sourceTabId, forkTabId\);[\s\S]*?tabChatHandoff\.save\(forkTabId, sourceChat\.html\)/, 'chrome: /btw fork bootstrap must copy history and transcript into the popup scope');+ assert.match(chromeBackground, /if \(!fork\?\.resumed\)/, 'chrome: /btw reload should keep the side conversation instead of re-forking');assert.match(chromeAgent, /async forkConversation\(sourceTabId, forkTabId\) \{[\s\S]*?this\.conversationModes\.set\(forkId, 'ask'\);[\s\S]*?this\.conversationIds\.set\(forkId, `conv_\$\{forkId\}_\$\{Date\.now\(\)\}_\$\{secureRandomBase36Token\(12\)\}`\);/, 'chrome: /btw forks must mint a distinct Ask-only conversation identity');+ assert.match(chromeAgent, /_trimIncompleteToolTail\(messages\)/, 'chrome: /btw fork should drop a trailing incomplete tool batch');+ assert.match(chromeAgent, /resumed: true/, 'chrome: /btw fork should report a resumed side conversation on reload');assert.match(panel, /const payload = \{[\s\S]*?handoffOwnerId: tabChatHandoffOwnerId,[\s\S]*?handoffGeneration[\s\S]*?return enqueueTabChatOperation\(tabId, async \(numericTabId\) => \{[\s\S]*?sendToBackground\('persist_tab_chat', payload\);/, 'chrome: visible tab-chat persistence should carry its owner generation through the shared background queue');assert.match(panel, /document\.visibilityState === 'hidden' && allowHidden[\s\S]*?sendToBackground\('persist_tab_chat', payload\);/, 'chrome: hidden handoff must bypass the document-local queue and enter the shared queue immediately');const clearStart = panel.indexOf('function clearCachedTabChat(tabId) {');@@ -47832,11 +47839,18 @@ test('firefox sidepanel serializes tab-chat storage writes with clears and readsassert.match(panel, /if \(isBtwWindow && btwSourceTabId != null && initialTabId != null\) \{[\s\S]*?sendToBackground\('fork_standalone_conversation', \{[\s\S]*?sourceTabId: btwSourceTabId,[\s\S]*?forkTabId: initialTabId,/, 'firefox: /btw must use its popup tab as an independent fork scope');assert.match(panel, /async function openBtwWindow\(tabId, prompt = ''\) \{[\s\S]*?const existing = await getBtwWindowState\(tabId\);[\s\S]*?forkFromTabId=\$\{tabId\}/, 'firefox: /btw should only reuse a popup for the same source tab');assert.match(panel, /async function openBtwWindow\(tabId, prompt = ''\) \{[\s\S]*?pendingPrompt: prompt[\s\S]*?browser\.tabs\.sendMessage\(target\.id, \{ action: 'btw_prompt', prompt \}\)\.catch\(\(\) => \{\}\);/, 'firefox: /btw should retain a prompt until its same-tab window receives it');- assert.match(panel, /async function consumePendingBtwPrompt\(\) \{[\s\S]*?pendingPrompt: ''[\s\S]*?await sendBtwPrompt\(prompt\);/, 'firefox: a /btw window should consume retained forwarded prompts');+ assert.match(panel, /async function consumePendingBtwPrompt\(directPrompt = ''\) \{[\s\S]*?await btwReady;[\s\S]*?pendingPrompts: \[\][\s\S]*?for \(const p of prompts\) \{[\s\S]*?await sendBtwPrompt\(p\);/, 'firefox: a /btw window should drain queued forwarded prompts after readiness');+ assert.match(panel, /void consumePendingBtwPrompt\(msg\?\.prompt\)/, 'firefox: /btw prompt listener should forward the message payload instead of dropping it');+ assert.match(panel, /pendingPrompts: queued/, 'firefox: /btw should queue concurrent prompts instead of overwriting a single slot');+ assert.match(panel, /markBtwReady\(\);[\s\S]*?await sendBtwPrompt\(btwInitialPrompt\)/, 'firefox: /btw auto-send should run after readiness without a fixed delay');+ assert.match(panel, /try \{\s*await sendToBackground\('fork_standalone_conversation'/, 'firefox: /btw fork bootstrap must not abort panel init on failure');const firefoxBackground = fs.readFileSync(path.join(ROOT, 'src/firefox/src/background.js'), 'utf8');const firefoxAgent = fs.readFileSync(path.join(ROOT, 'src/firefox/src/agent/agent.js'), 'utf8');assert.match(firefoxBackground, /case 'fork_standalone_conversation':[\s\S]*?agent\.forkConversation\(sourceTabId, forkTabId\);[\s\S]*?tabChatHandoff\.save\(forkTabId, sourceChat\.html\)/, 'firefox: /btw fork bootstrap must copy history and transcript into the popup scope');+ assert.match(firefoxBackground, /if \(!fork\?\.resumed\)/, 'firefox: /btw reload should keep the side conversation instead of re-forking');assert.match(firefoxAgent, /async forkConversation\(sourceTabId, forkTabId\) \{[\s\S]*?this\.conversationModes\.set\(forkId, 'ask'\);[\s\S]*?this\.conversationIds\.set\(forkId, `conv_\$\{forkId\}_\$\{Date\.now\(\)\}_\$\{secureRandomBase36Token\(12\)\}`\);/, 'firefox: /btw forks must mint a distinct Ask-only conversation identity');+ assert.match(firefoxAgent, /_trimIncompleteToolTail\(messages\)/, 'firefox: /btw fork should drop a trailing incomplete tool batch');+ assert.match(firefoxAgent, /resumed: true/, 'firefox: /btw fork should report a resumed side conversation on reload');assert.match(panel, /const payload = \{[\s\S]*?handoffOwnerId: tabChatHandoffOwnerId,[\s\S]*?handoffGeneration[\s\S]*?return enqueueTabChatOperation\(tabId, async \(numericTabId\) => \{[\s\S]*?sendToBackground\('persist_tab_chat', payload\);/, 'firefox: visible tab-chat persistence should carry its owner generation through the shared background queue');assert.match(panel, /document\.visibilityState === 'hidden' && allowHidden[\s\S]*?sendToBackground\('persist_tab_chat', payload\);/, 'firefox: hidden handoff must bypass the document-local queue and enter the shared queue immediately');const clearStart = panel.indexOf('function clearCachedTabChat(tabId) {');