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
Stop after an accepted hand-off cancels the restart and returns its corrections
Claudecfcd994982f6
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 31fa16c63..69d0399b7 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -7563,6 +7563,8 @@ export class Agent extends LoopDetector {_finishSteeringRun(tabId) {const run = this._steeringRuns.get(tabId);this._steeringRuns.delete(tabId);+ // Stop pressed after a hand-off was accepted cancels its restart.+ if (this._checkAbort(tabId)) this._pendingModeEscalations.delete(tabId);// A routed turn that handed itself to an action mode passes its// corrections, applied or pending, to the run that replaces it. They stay// journaled under the same request, so a background restart in between@@ -7579,10 +7581,13 @@ export class Agent extends LoopDetector {if (carried.some(item => !checked.has(item.id))) this._pendingModeEscalations.get(tabId).reroute = true;void this._steeringJournal.forget(tabId, [...carriedIds]);for (const item of carried) void this._steeringJournal.accept(tabId, run.requestId, item);- } else if (run?.messages.length) {+ } else {// After Stop nothing may start on its own: the panel keeps these- // corrections queued for an explicit send instead of draining them.- run.onUpdate('steering_queued', { messages: run.messages, ...(this._checkAbort(tabId) ? { stopped: true } : {}) });+ // corrections queued for an explicit send instead of draining them. A+ // hand-off stopped before its restart also returns the corrections it+ // had applied, since the restored turn no longer holds them.+ const handedBack = [...(run?.handoffApplied || []), ...(run?.messages || [])];+ if (handedBack.length) run.onUpdate('steering_queued', { messages: handedBack, ...(this._checkAbort(tabId) ? { stopped: true } : {}) });}// Applied or just handed back: the journal no longer owns what this run// accepted. Entries it never restored stay for the panel to reclaim.diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex b122d07dc..d7802498f 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -7104,6 +7104,8 @@ export class Agent extends LoopDetector {_finishSteeringRun(tabId) {const run = this._steeringRuns.get(tabId);this._steeringRuns.delete(tabId);+ // Stop pressed after a hand-off was accepted cancels its restart.+ if (this._checkAbort(tabId)) this._pendingModeEscalations.delete(tabId);// A routed turn that handed itself to an action mode passes its// corrections, applied or pending, to the run that replaces it. They stay// journaled under the same request, so a background restart in between@@ -7120,10 +7122,13 @@ export class Agent extends LoopDetector {if (carried.some(item => !checked.has(item.id))) this._pendingModeEscalations.get(tabId).reroute = true;void this._steeringJournal.forget(tabId, [...carriedIds]);for (const item of carried) void this._steeringJournal.accept(tabId, run.requestId, item);- } else if (run?.messages.length) {+ } else {// After Stop nothing may start on its own: the panel keeps these- // corrections queued for an explicit send instead of draining them.- run.onUpdate('steering_queued', { messages: run.messages, ...(this._checkAbort(tabId) ? { stopped: true } : {}) });+ // corrections queued for an explicit send instead of draining them. A+ // hand-off stopped before its restart also returns the corrections it+ // had applied, since the restored turn no longer holds them.+ const handedBack = [...(run?.handoffApplied || []), ...(run?.messages || [])];+ if (handedBack.length) run.onUpdate('steering_queued', { messages: handedBack, ...(this._checkAbort(tabId) ? { stopped: true } : {}) });}// Applied or just handed back: the journal no longer owns what this run// accepted. Entries it never restored stay for the panel to reclaim.diff --git a/test/auto-mode.mjs b/test/auto-mode.mjsindex abb91438d..8aaf5e6ed 100644--- a/test/auto-mode.mjs+++ b/test/auto-mode.mjs@@ -479,6 +479,30 @@ for (const build of BUILDS) {assert.deepEqual(f.agent.takeModeEscalation(f.tab), { mode: 'dev', evidence: 'first inspect the console errors' });});+ test(`${build}: Stop during an accepted hand-off cancels the restart and returns every correction to the composer`, async () => {+ const f = fixture(Agent, {+ decide: (_q, options) => (options.mainModel === false ? { choice: null, source: 'unavailable' } : { choice: 'act', source: 'main_model' }),+ replies: [() => {+ f.agent.conversations.get(f.tab).push({ role: 'user', content: 'use the 10 am slot',+ webbrainSteering: { requestId: `auto-${f.tab}`, messageId: 's12', revision: 1 } });+ return handoff('act', 'book the 9 am slot');+ }],+ });+ // The user sends one more correction, then presses Stop, while the hand-off is saved.+ f.agent._persistNow = async () => {+ f.agent._steeringRuns.get(f.tab)?.messages.push({ id: 's13', text: 'and add a note' });+ f.agent.abort(f.tab);+ };+ await f.run('Please book the 9 am slot for me.');+ f.agent._persistNow = async () => null;+ const queued = f.updates.filter(update => update.type === 'steering_queued');+ assert.equal(queued.length, 1);+ assert.deepEqual(queued[0].data.messages.map(item => item.id), ['s12', 's13'], 'the applied correction comes back too');+ assert.equal(queued[0].data.stopped, true);+ assert.equal(f.agent.takeModeEscalation(f.tab), null, 'nothing restarts after Stop');+ assert.equal(f.agent._modeEscalationSteering.has(f.tab), false);+ });+test(`${build}: a restart rerouted too often ends read-only and still applies the corrections`, async () => {const f = fixture(Agent, { decide: () => { throw new Error('a read-only restart asks no route'); } });f.agent._modeEscalationSteering.set(f.tab, [{ id: 's11', text: 'instead inspect the console errors' }]);