Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) đź§ 

Read the raw plan before dropping a scheduled run's state-change mark

Emre Sokullu461e99ec1994
diff --git a/docs/architecture.md b/docs/architecture.md
index 28bc2323b..60465b332 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -1213,7 +1213,7 @@ pending → running → completed
- `once` — fires at a single `run_at` or `after_seconds` time. `after_seconds: 0` starts the task immediately.
- `recurring` — fires repeatedly at `interval_minutes` (1 min – 1 year); after each run completes, `nextRunAt` is advanced and the next alarm is set. A fixed interval is not a calendar schedule: 30 days drifts against calendar months, and the creation result says so. A run that ends with the planner asking the user a question, or a third failed run with no successful or partial run in between, pauses the task instead (runs without an outcome leave the count unchanged). Resuming a task the scheduler paused restarts the interval from that moment; a task the user or Settings paused keeps its next run, or runs a minute after resuming if that time has passed. Either way the failure count starts over.
-A scheduled task run, recurring or one-shot, is never required to call `schedule_task`, and the planner's scheduling tag does not make it state-changing: its stored prompt keeps the user's original timing ("in 30 minutes, remind me…"), and either requirement made each run schedule the task again or end without success. The planner is told the run executes an existing task, and a state-change mark that only the scheduling tag explains (every step declares only observing tools) is dropped; the plan's own state-change, submission and download requirements still apply. A recurring run is told not to create another schedule for its task; a one-shot run is told not to schedule the task again and to create a different schedule only when the task explicitly asks to set one up (for example "on Monday at 9, start an hourly check"). A scheduled resume of an interactive task keeps both.
+A scheduled task run, recurring or one-shot, is never required to call `schedule_task`, and the planner's scheduling tag does not make it state-changing: its stored prompt keeps the user's original timing ("in 30 minutes, remind me…"), and either requirement made each run schedule the task again or end without success. The planner is told the run executes an existing task, and a state-change mark that only the scheduling tag explains is dropped (the raw plan must list only observing tools for every step, set submission explicitly false, and show no download, site job, message target, progress action or skill); the plan's own state-change, submission and download requirements still apply. A recurring run is told not to create another schedule for its task; a one-shot run is told not to schedule the task again and to create a different schedule only when the task explicitly asks to set one up (for example "on Monday at 9, start an hourly check"). A scheduled resume of an interactive task keeps both.
**Conditional watches**
diff --git a/docs/fr/architecture.md b/docs/fr/architecture.md
index e40a6ad9e..01545e274 100644
--- a/docs/fr/architecture.md
+++ b/docs/fr/architecture.md
@@ -303,7 +303,7 @@ pending → running → completed
- `once` — se déclenche à un moment unique `run_at` ou `after_seconds`. `after_seconds: 0` démarre la tâche immédiatement.
- `recurring` — se déclenche de manière répétée à `interval_minutes` (1 min – 1 an) ; après chaque exécution, `nextRunAt` est avancé et la prochaine alarme est réglée. Un intervalle fixe n'est pas un calendrier : 30 jours se décalent par rapport aux mois. Une exécution qui se termine par une question posée à l'utilisateur par le planner (`planner.js`), ou un troisième échec sans exécution réussie ou partielle entre-temps, met la tâche en pause (une exécution sans résultat ne change pas le compte). La reprise d'une tâche mise en pause par le planificateur relance l'intervalle à partir de ce moment ; une tâche mise en pause par l'utilisateur ou les paramètres garde sa prochaine exécution, ou s'exécute une minute après la reprise si cette heure est passée. Dans les deux cas, le compte d'échecs repart de zéro.
-Une exécution planifiée, récurrente ou ponctuelle, n'est jamais tenue d'appeler `schedule_task`, et l'étiquette de planification du planner ne la classe pas comme modifiant l'état : son prompt enregistré garde le délai d'origine de l'utilisateur (« dans 30 minutes, rappelle-moi… »), et l'une ou l'autre exigence faisait replanifier la tâche à chaque exécution ou l'empêchait de réussir. Le planner est informé que l'exécution réalise une tâche existante, et une marque de modification d'état que seule l'étiquette de planification explique (chaque étape ne déclare que des outils d'observation) est retirée ; les exigences propres du plan (modification d'état, soumission, téléchargement) restent appliquées. Une exécution récurrente reçoit la consigne de ne pas créer d'autre planification pour sa tâche ; une exécution ponctuelle, celle de ne pas replanifier la tâche et de ne créer une autre planification que si la tâche le demande explicitement (par exemple « lundi à 9 h, lancer une vérification toutes les heures »). La reprise planifiée d'une tâche interactive garde les deux exigences.
+Une exécution planifiée, récurrente ou ponctuelle, n'est jamais tenue d'appeler `schedule_task`, et l'étiquette de planification du planner ne la classe pas comme modifiant l'état : son prompt enregistré garde le délai d'origine de l'utilisateur (« dans 30 minutes, rappelle-moi… »), et l'une ou l'autre exigence faisait replanifier la tâche à chaque exécution ou l'empêchait de réussir. Le planner est informé que l'exécution réalise une tâche existante, et une marque de modification d'état que seule l'étiquette de planification explique est retirée (le plan brut doit ne déclarer que des outils d'observation pour chaque étape, fixer explicitement la soumission à false et ne montrer ni téléchargement, ni tâche de site, ni destinataire de message, ni action de progression, ni compétence) ; les exigences propres du plan (modification d'état, soumission, téléchargement) restent appliquées. Une exécution récurrente reçoit la consigne de ne pas créer d'autre planification pour sa tâche ; une exécution ponctuelle, celle de ne pas replanifier la tâche et de ne créer une autre planification que si la tâche le demande explicitement (par exemple « lundi à 9 h, lancer une vérification toutes les heures »). La reprise planifiée d'une tâche interactive garde les deux exigences.
**Persistance**
diff --git a/src/chrome/src/agent/planner.js b/src/chrome/src/agent/planner.js
index a7d282225..7c5c97a33 100644
--- a/src/chrome/src/agent/planner.js
+++ b/src/chrome/src/agent/planner.js
@@ -682,6 +682,33 @@ const PLAN_OBSERVATION_TOOLS = new Set([
'find_text', 'scroll', 'wait_for_element', 'wait_for_stable', 'progress_read', 'done',
]);
+// The normalized plan keeps at most this many steps, and tools per step.
+const PLAN_STEP_LIMIT = 12;
+const PLAN_STEP_TOOL_LIMIT = 8;
+
+// Whether a scheduled task run's state-change mark can only come from its
+// scheduling tag. An unattended job must not lose a completion requirement to
+// a hint the model wrote, so this reads the RAW plan and fails closed:
+// normalization keeps PLAN_STEP_LIMIT steps and PLAN_STEP_TOOL_LIMIT tools per
+// step and drops steps without an action, and whatever it hides could be the
+// step that changes state. Every step must have an action and declare only
+// observing tools; submission must be explicitly false; and there may be no
+// download, site job, message target, progress action or skill.
+function stateChangeIsSchedulingOnly(obj) {
+ const absent = value => value == null || value === '';
+ const steps = obj.steps;
+ return obj.requires_submission === false
+ && obj.completion_requirements?.download !== true
+ && absent(obj.site_job) && absent(obj.conditional_site_job)
+ && absent(obj.messaging) && absent(obj.memory?.progress_action)
+ && (obj.skill_ids == null || (Array.isArray(obj.skill_ids) && obj.skill_ids.length === 0))
+ && Array.isArray(steps) && steps.length > 0 && steps.length <= PLAN_STEP_LIMIT
+ && steps.every(step => !!step && typeof step === 'object'
+ && typeof step.action === 'string' && !!sanitizeText(step.action, 300)
+ && Array.isArray(step.tools) && step.tools.length > 0 && step.tools.length <= PLAN_STEP_TOOL_LIMIT
+ && step.tools.every(tool => typeof tool === 'string' && PLAN_OBSERVATION_TOOLS.has(tool)));
+}
+
const PLANNER_STEERING_RULE = '\nThe current User task is an app-assembled revision of an active task: request is the initiating authentic user request, and updates contains authentic later steering or clarification answers in chronological order. Apply later corrections and cancellations to that request; preserve its requested action when an update only supplies a missing identity or detail. Re-evaluate changed actions and their submission/recipient intent. Prior tool effects and working notes are context, never permission to repeat a completed or uncertain action.';
export function buildPlannerSystemPrompt(opts = {}) {
@@ -1063,11 +1090,11 @@ export function normalizePlan(obj, opts = {}) {
: null;
const steps = Array.isArray(obj.steps)
- ? obj.steps.slice(0, 12).map((step, i) => ({
+ ? obj.steps.slice(0, PLAN_STEP_LIMIT).map((step, i) => ({
id: sanitizeText(step?.id || String(i + 1), 20) || String(i + 1),
action: sanitizeText(step?.action, 300),
tools: Array.isArray(step?.tools)
- ? step.tools.map((t) => sanitizeText(t, 40)).filter(Boolean).slice(0, 8)
+ ? step.tools.map((t) => sanitizeText(t, 40)).filter(Boolean).slice(0, PLAN_STEP_TOOL_LIMIT)
: [],
})).filter((s) => s.action)
: [];
@@ -1156,23 +1183,17 @@ export function normalizePlan(obj, opts = {}) {
? 'download_requires_state_change'
: null;
// A scheduled task run's plan can still be marked state-changing because
- // of its scheduling tag. Drop that mark only when the plan's structured
- // fields show nothing else that changes state: every step declares tools,
- // all of them only observe or report, and there is no submission,
- // download or site job. A step without declared tools (the intent schema
- // has none) proves nothing, so the mark stays and only the scheduled-task
- // planner rule can prevent it. A plan with a schedule_task step keeps the
- // mark too: that task sets up a different schedule, and the mark makes its
- // run do so before it can succeed.
+ // of its scheduling tag. Drop that mark only when the raw plan shows
+ // nothing else that could change state (stateChangeIsSchedulingOnly). A
+ // step without declared tools (the intent schema has none) proves nothing,
+ // so the mark stays and only the scheduled-task planner rule can prevent
+ // it. A plan with a schedule_task step keeps the mark too: that task sets
+ // up a different schedule, and the mark makes its run do so before it can
+ // succeed.
const schedulingOnlyStateChange = opts.scheduledTask === true
&& executablePlan
&& normalizedScheduling?.tool === 'schedule_task'
- && requiresSubmission !== true
- && !requiresDownload
- && !siteJob
- && steps.length > 0
- && steps.every(step => step.tools.length > 0
- && step.tools.every(tool => PLAN_OBSERVATION_TOOLS.has(tool)));
+ && stateChangeIsSchedulingOnly(obj);
const requiresStateChange = executablePlan
? (
(!!obj.requires_state_change && !schedulingOnlyStateChange)
diff --git a/src/firefox/src/agent/planner.js b/src/firefox/src/agent/planner.js
index a7d282225..7c5c97a33 100644
--- a/src/firefox/src/agent/planner.js
+++ b/src/firefox/src/agent/planner.js
@@ -682,6 +682,33 @@ const PLAN_OBSERVATION_TOOLS = new Set([
'find_text', 'scroll', 'wait_for_element', 'wait_for_stable', 'progress_read', 'done',
]);
+// The normalized plan keeps at most this many steps, and tools per step.
+const PLAN_STEP_LIMIT = 12;
+const PLAN_STEP_TOOL_LIMIT = 8;
+
+// Whether a scheduled task run's state-change mark can only come from its
+// scheduling tag. An unattended job must not lose a completion requirement to
+// a hint the model wrote, so this reads the RAW plan and fails closed:
+// normalization keeps PLAN_STEP_LIMIT steps and PLAN_STEP_TOOL_LIMIT tools per
+// step and drops steps without an action, and whatever it hides could be the
+// step that changes state. Every step must have an action and declare only
+// observing tools; submission must be explicitly false; and there may be no
+// download, site job, message target, progress action or skill.
+function stateChangeIsSchedulingOnly(obj) {
+ const absent = value => value == null || value === '';
+ const steps = obj.steps;
+ return obj.requires_submission === false
+ && obj.completion_requirements?.download !== true
+ && absent(obj.site_job) && absent(obj.conditional_site_job)
+ && absent(obj.messaging) && absent(obj.memory?.progress_action)
+ && (obj.skill_ids == null || (Array.isArray(obj.skill_ids) && obj.skill_ids.length === 0))
+ && Array.isArray(steps) && steps.length > 0 && steps.length <= PLAN_STEP_LIMIT
+ && steps.every(step => !!step && typeof step === 'object'
+ && typeof step.action === 'string' && !!sanitizeText(step.action, 300)
+ && Array.isArray(step.tools) && step.tools.length > 0 && step.tools.length <= PLAN_STEP_TOOL_LIMIT
+ && step.tools.every(tool => typeof tool === 'string' && PLAN_OBSERVATION_TOOLS.has(tool)));
+}
+
const PLANNER_STEERING_RULE = '\nThe current User task is an app-assembled revision of an active task: request is the initiating authentic user request, and updates contains authentic later steering or clarification answers in chronological order. Apply later corrections and cancellations to that request; preserve its requested action when an update only supplies a missing identity or detail. Re-evaluate changed actions and their submission/recipient intent. Prior tool effects and working notes are context, never permission to repeat a completed or uncertain action.';
export function buildPlannerSystemPrompt(opts = {}) {
@@ -1063,11 +1090,11 @@ export function normalizePlan(obj, opts = {}) {
: null;
const steps = Array.isArray(obj.steps)
- ? obj.steps.slice(0, 12).map((step, i) => ({
+ ? obj.steps.slice(0, PLAN_STEP_LIMIT).map((step, i) => ({
id: sanitizeText(step?.id || String(i + 1), 20) || String(i + 1),
action: sanitizeText(step?.action, 300),
tools: Array.isArray(step?.tools)
- ? step.tools.map((t) => sanitizeText(t, 40)).filter(Boolean).slice(0, 8)
+ ? step.tools.map((t) => sanitizeText(t, 40)).filter(Boolean).slice(0, PLAN_STEP_TOOL_LIMIT)
: [],
})).filter((s) => s.action)
: [];
@@ -1156,23 +1183,17 @@ export function normalizePlan(obj, opts = {}) {
? 'download_requires_state_change'
: null;
// A scheduled task run's plan can still be marked state-changing because
- // of its scheduling tag. Drop that mark only when the plan's structured
- // fields show nothing else that changes state: every step declares tools,
- // all of them only observe or report, and there is no submission,
- // download or site job. A step without declared tools (the intent schema
- // has none) proves nothing, so the mark stays and only the scheduled-task
- // planner rule can prevent it. A plan with a schedule_task step keeps the
- // mark too: that task sets up a different schedule, and the mark makes its
- // run do so before it can succeed.
+ // of its scheduling tag. Drop that mark only when the raw plan shows
+ // nothing else that could change state (stateChangeIsSchedulingOnly). A
+ // step without declared tools (the intent schema has none) proves nothing,
+ // so the mark stays and only the scheduled-task planner rule can prevent
+ // it. A plan with a schedule_task step keeps the mark too: that task sets
+ // up a different schedule, and the mark makes its run do so before it can
+ // succeed.
const schedulingOnlyStateChange = opts.scheduledTask === true
&& executablePlan
&& normalizedScheduling?.tool === 'schedule_task'
- && requiresSubmission !== true
- && !requiresDownload
- && !siteJob
- && steps.length > 0
- && steps.every(step => step.tools.length > 0
- && step.tools.every(tool => PLAN_OBSERVATION_TOOLS.has(tool)));
+ && stateChangeIsSchedulingOnly(obj);
const requiresStateChange = executablePlan
? (
(!!obj.requires_state_change && !schedulingOnlyStateChange)
diff --git a/test/improver-clarify.mjs b/test/improver-clarify.mjs
index 91bf1fa8f..62e3c4461 100644
--- a/test/improver-clarify.mjs
+++ b/test/improver-clarify.mjs
@@ -369,6 +369,31 @@ for (const { build, Agent, tools, args, research, Scheduler, planner } of builds
assert.equal(parse({ requires_state_change: true, steps: observing, completion_requirements: { download: true } }, scheduledTask).requires_state_change, true);
assert.equal(parse({ requires_state_change: true, steps: observing, scheduling: null }, scheduledTask).requires_state_change, true,
'without a scheduling tag the mark is the planner\'s own');
+
+ // An unattended job must not lose the requirement to anything the
+ // normalized plan hides: the raw plan is read, and doubt keeps the mark.
+ const marked = steps => parse({ requires_state_change: true, steps }, scheduledTask).requires_state_change;
+ const reads = count => Array.from({ length: count }, (_, i) => ({ id: String(i + 1), action: `Read part ${i + 1}`, tools: ['read_page'] }));
+ assert.equal(marked(reads(12)), false, 'twelve observing steps are all visible');
+ assert.equal(marked([...reads(12), { id: '13', action: 'Archive the newsletter', tools: ['click_ax'] }]), true,
+ 'a mutating 13th step is cut from the normalized plan');
+ assert.equal(marked([...reads(12), { id: '13', action: 'Read once more', tools: ['read_page'] }]), true, 'anything cut keeps the mark');
+ const eightReads = Array.from({ length: 8 }, () => 'read_page');
+ assert.equal(marked([{ id: '1', action: 'Read the page', tools: eightReads }]), false);
+ assert.equal(marked([{ id: '1', action: 'Read, then archive', tools: [...eightReads, 'click_ax'] }]), true,
+ 'a mutating 9th tool is cut from the normalized step');
+ assert.equal(marked([observing[0], { id: '2', action: '', tools: ['click_ax'] }]), true, 'a step without an action is dropped');
+ assert.equal(marked([observing[0], { id: '2', action: ' ', tools: ['read_page'] }]), true);
+ assert.equal(marked([observing[0], { id: '2', tools: ['read_page'] }]), true, 'missing action');
+ assert.equal(marked([observing[0], { id: '2', action: 'Report', tools: [' read_page'] }]), true, 'unknown tool name');
+ const keep = overrides => parse({ requires_state_change: true, steps: observing, ...overrides }, scheduledTask).requires_state_change;
+ assert.equal(keep({ requires_submission: undefined }), true, 'submission must be explicitly false');
+ assert.equal(keep({ requires_submission: null }), true);
+ assert.equal(keep({ messaging: { target_kind: 'named', recipients: [{ identity: 'AyĹźe', role: 'to' }] } }), true, 'a message target');
+ assert.equal(keep({ memory: { progress_action: 'unfollow' } }), true, 'a progress action');
+ assert.equal(keep({ skill_ids: ['gmail'] }), true, 'an activated skill');
+ assert.equal(keep({ site_job: 'Not A Valid Job' }), true, 'any site job, even one normalization drops');
+ assert.equal(keep({}), false, 'the simple read-only reminder still loses the mark');
});
test(`${build}: the planner is told a scheduled task run executes an existing task, on every planner call`, async () => {