Skip to content

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

Do not reserve the user's tab for a URL task that runs in its own helper

Claude56113f19604a
diff --git a/src/chrome/src/agent/scheduler.js b/src/chrome/src/agent/scheduler.js
index 0ec014a45..4ae933121 100644
--- a/src/chrome/src/agent/scheduler.js
+++ b/src/chrome/src/agent/scheduler.js
@@ -2222,9 +2222,14 @@ export class ScheduledJobManager {
}
};
try {
+ // A URL task created from the user's tab does not run there (see
+ // _resolveTab), so that tab is not reserved up front: the user's own run
+ // in it must not defer a task that opens its own helper. The tab the run
+ // really uses is reserved below, once it is known.
+ const ownsTargetTab = job.target?.type !== 'url' || job.source === 'watch' || job.target?.helperTab === true;
const candidateTabId = job.kind === 'resume' || job.target?.type === 'current_tab'
? (job.tabId || job.target?.tabId)
- : job.target?.tabId;
+ : ownsTargetTab ? job.target?.tabId : null;
await reserveTab(candidateTabId);
if (execution.cancelled) { releaseReservation(); return; }
tabId = await this._resolveTab(job, execution);
diff --git a/src/firefox/src/agent/scheduler.js b/src/firefox/src/agent/scheduler.js
index 90f6a0441..dadce56f6 100644
--- a/src/firefox/src/agent/scheduler.js
+++ b/src/firefox/src/agent/scheduler.js
@@ -2198,9 +2198,14 @@ export class ScheduledJobManager {
}
};
try {
+ // A URL task created from the user's tab does not run there (see
+ // _resolveTab), so that tab is not reserved up front: the user's own run
+ // in it must not defer a task that opens its own helper. The tab the run
+ // really uses is reserved below, once it is known.
+ const ownsTargetTab = job.target?.type !== 'url' || job.source === 'watch' || job.target?.helperTab === true;
const candidateTabId = job.kind === 'resume' || job.target?.type === 'current_tab'
? (job.tabId || job.target?.tabId)
- : job.target?.tabId;
+ : ownsTargetTab ? job.target?.tabId : null;
await reserveTab(candidateTabId);
if (execution.cancelled) { releaseReservation(); return; }
tabId = await this._resolveTab(job, execution);
diff --git a/test/agent-lifecycle.mjs b/test/agent-lifecycle.mjs
index eb5881a10..18b8bc62c 100644
--- a/test/agent-lifecycle.mjs
+++ b/test/agent-lifecycle.mjs
@@ -1217,6 +1217,28 @@ for (const [browser, Agent, Scheduler] of schedulingVariants) {
assert.equal(created.length, 1); assert.deepEqual(runs, [1902, 1902]);
} finally { await f.close(); }
});
+ test(`${browser}: a busy tab the URL task was created from does not defer the task's own helper tab`, async () => {
+ const f = await schedulingFixture(Agent, Scheduler);
+ const created = [], runs = [];
+ api.tabs.get = async id => id === 1903 ? { id, url: 'https://owned.example/inspection', title: 'Owned helper' } : { id, url: 'https://example.com/', title: 'The page the user is on' };
+ api.tabs.create = async args => { created.push(structuredClone(args)); return { id: 1903, ...args }; };
+ api.tabs.update = async (id, args) => ({ id, ...args });
+ f.agent.processMessage = async (id) => { runs.push(id); return 'The owned page was read.'; };
+ try {
+ const result = await f.manager.createTaskJob({ tabId: f.tabId, conversationId: 'manual', source: 'ui', currentUrl: 'https://example.com/',
+ args: { ...schedulingArgs('schedule_task'), schedule: { type: 'recurring', after_seconds: 90, interval_minutes: 5 },
+ target: { type: 'url', url: 'https://owned.example/inspection' } } });
+ assert.equal(result.success, true);
+ f.agent._finishSteeringRun(f.tabId); f.agent._releaseRunEntry(f.tabId);
+ // The user is running something in the tab the task was created from.
+ f.manager._runningTabs.add(f.tabId);
+ await f.manager.handleAlarm([...f.alarms.keys()][0]);
+ assert.deepEqual(runs, [1903], 'the task ran in its own helper tab');
+ assert.equal(created.length, 1);
+ assert.notEqual(f.jobs()[0].status, 'queued', 'the user\'s busy tab did not requeue the task');
+ assert.ok(f.manager._runningTabs.has(f.tabId), 'the user\'s run is untouched');
+ } finally { await f.close(); }
+ });
}
for (const [browser, Agent, Scheduler] of schedulingVariants) {