Skip to content

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

Drop a page-1 continuation placeholder from a first tree read

Claude5b830ec6785f
diff --git a/docs/accessibility-tree-and-refs.md b/docs/accessibility-tree-and-refs.md
index adfe5f418..658544128 100644
--- a/docs/accessibility-tree-and-refs.md
+++ b/docs/accessibility-tree-and-refs.md
@@ -117,6 +117,12 @@ window reduces model round trips; it does not turn a multi-page tree into proof
of complete coverage. `tree_revision` binds page 2 and later to the snapshot
created by page 1. Page 1 always starts or restarts a fresh snapshot, so the
runtime ignores a stale revision if a model carries one into a page-1 call.
+For the same reason, a `continuationArgs` object for page 1 without a revision,
+on a call that names no revision either, continues nothing and is dropped: the
+call's own top-level fields are the read. Some models fill every field of the
+schema and send such an object with each first read, often with other values,
+and that read used to fail as invalid arguments. A continuation for page 2 or
+later must still match the call's top-level fields exactly.
Pagination also cannot prove that an application rendered hidden conversation
content. On a Gmail thread route, a discovery read returns a trusted
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index be48ed8c4..dbfcdda3d 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -11312,7 +11312,21 @@ export class Agent extends LoopDetector {
try { continuation = continuation.length <= 32768 ? JSON.parse(continuation) : null; } catch { continuation = null; }
}
const allowed = ['filter', 'maxDepth', 'maxChars', 'ref_id', 'page', 'tree_revision'];
- const valid = continuation && typeof continuation === 'object' && !Array.isArray(continuation)
+ // Only a truncated result returns a continuation, and it is always for
+ // page 2 or later with a tree revision. One for page 1 without a
+ // revision, on a call that names none either, continues nothing: the
+ // call starts a read, and its top-level fields are that read. Models
+ // that fill every field of the schema send one with each first read,
+ // often with other values, so it is dropped instead of failing the read.
+ const restart = continuation && typeof continuation === 'object' && !Array.isArray(continuation)
+ && Object.keys(continuation).length > 0 && Object.keys(continuation).every(key => allowed.includes(key))
+ && !String(continuation.tree_revision ?? '').trim() && !String(next.tree_revision ?? '').trim()
+ && [undefined, null, '', 1, '1'].includes(continuation.page);
+ if (restart) {
+ delete next.continuationArgs;
+ repaired = true;
+ }
+ const valid = restart || continuation && typeof continuation === 'object' && !Array.isArray(continuation)
&& Object.keys(continuation).length > 0
&& Object.keys(continuation).every(key => allowed.includes(key))
&& Object.entries(continuation).every(([key, value]) => !Object.hasOwn(next, key) || Object.is(next[key], value));
@@ -11324,8 +11338,10 @@ export class Agent extends LoopDetector {
error: 'get_accessibility_tree continuationArgs must be one complete JSON object containing only declared read fields, with no conflicting top-level fields. Re-emit the exact returned continuation fields as top-level arguments.',
} };
}
- next = this._normalizeContinuationToolArgs(name, { ...next, continuationArgs: continuation });
- repaired = true;
+ if (!restart) {
+ next = this._normalizeContinuationToolArgs(name, { ...next, continuationArgs: continuation });
+ repaired = true;
+ }
}
for (const key of ['maxDepth', 'maxChars', 'page']) {
const value = decimal(next[key]);
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 241956fd9..303e15223 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -10990,7 +10990,21 @@ export class Agent extends LoopDetector {
try { continuation = continuation.length <= 32768 ? JSON.parse(continuation) : null; } catch { continuation = null; }
}
const allowed = ['filter', 'maxDepth', 'maxChars', 'ref_id', 'page', 'tree_revision'];
- const valid = continuation && typeof continuation === 'object' && !Array.isArray(continuation)
+ // Only a truncated result returns a continuation, and it is always for
+ // page 2 or later with a tree revision. One for page 1 without a
+ // revision, on a call that names none either, continues nothing: the
+ // call starts a read, and its top-level fields are that read. Models
+ // that fill every field of the schema send one with each first read,
+ // often with other values, so it is dropped instead of failing the read.
+ const restart = continuation && typeof continuation === 'object' && !Array.isArray(continuation)
+ && Object.keys(continuation).length > 0 && Object.keys(continuation).every(key => allowed.includes(key))
+ && !String(continuation.tree_revision ?? '').trim() && !String(next.tree_revision ?? '').trim()
+ && [undefined, null, '', 1, '1'].includes(continuation.page);
+ if (restart) {
+ delete next.continuationArgs;
+ repaired = true;
+ }
+ const valid = restart || continuation && typeof continuation === 'object' && !Array.isArray(continuation)
&& Object.keys(continuation).length > 0
&& Object.keys(continuation).every(key => allowed.includes(key))
&& Object.entries(continuation).every(([key, value]) => !Object.hasOwn(next, key) || Object.is(next[key], value));
@@ -11002,8 +11016,10 @@ export class Agent extends LoopDetector {
error: 'get_accessibility_tree continuationArgs must be one complete JSON object containing only declared read fields, with no conflicting top-level fields. Re-emit the exact returned continuation fields as top-level arguments.',
} };
}
- next = this._normalizeContinuationToolArgs(name, { ...next, continuationArgs: continuation });
- repaired = true;
+ if (!restart) {
+ next = this._normalizeContinuationToolArgs(name, { ...next, continuationArgs: continuation });
+ repaired = true;
+ }
}
for (const key of ['maxDepth', 'maxChars', 'page']) {
const value = decimal(next[key]);
diff --git a/test/read-continuation-schema.mjs b/test/read-continuation-schema.mjs
index 71f9e132c..ee116021e 100644
--- a/test/read-continuation-schema.mjs
+++ b/test/read-continuation-schema.mjs
@@ -184,6 +184,38 @@ for (const browser of ['chrome', 'firefox']) {
}
});
+ test(`${browser}: a page-1 continuation without a tree revision is dropped from a first read`, () => {
+ // QA B1, G1, X5: the model filled every field of the schema, including
+ // a continuationArgs for page 1 that differed from the read it asked for,
+ // and the read failed as invalid arguments.
+ const agent = new Agent({ getActive: () => null });
+ const schema = getToolsForMode('act', { tier: 'full' }).find(tool => tool.function.name === 'get_accessibility_tree').function.parameters;
+ const read = { filter: 'all', maxDepth: 8, maxChars: 5000, ref_id: '', page: 1, tree_revision: '' };
+ for (const placeholder of [
+ { filter: 'visible', maxDepth: 10, maxChars: 6000, ref_id: '', page: 1, tree_revision: '' },
+ { filter: 'all', maxDepth: 15, maxChars: 6000, ref_id: '', page: '1', tree_revision: '' },
+ { filter: 'interactive' },
+ ]) {
+ const args = { ...read, continuationArgs: placeholder };
+ const repaired = agent._repairToolCallArgs('get_accessibility_tree', args);
+ assert.equal(repaired.result, undefined, JSON.stringify(placeholder));
+ assert.equal(repaired.repaired, true);
+ assert.deepEqual(repaired.args, read, 'The read is the one the call asked for');
+ assert.equal(validateToolArguments('get_accessibility_tree', repaired.args, schema).ok, true);
+ assert.ok(Object.hasOwn(args, 'continuationArgs'), 'The provider call is not mutated');
+ }
+ // A real continuation still may not conflict with the call, and a
+ // placeholder may still not carry undeclared fields.
+ for (const args of [
+ { filter: 'visible', maxDepth: 10, page: 1, tree_revision: '',
+ continuationArgs: { filter: 'visible', maxDepth: 15, maxChars: 6000, ref_id: '', page: 2, tree_revision: 'fnv1a64:d0891b5ff4884d4a' } },
+ { ...read, continuationArgs: { page: 1, undeclared: true } }, { ...read, continuationArgs: {} },
+ { ...read, continuationArgs: { ...continuation, page: 1, filter: 'visible' } },
+ ]) {
+ assert.equal(agent._repairToolCallArgs('get_accessibility_tree', args).result?.errorCode, 'invalid_tool_arguments', JSON.stringify(args));
+ }
+ });
+
test(`${browser}: oversized declared prose windows are bounded without losing the requested document position`, () => {
const agent = new Agent({ getActive: () => null });
const schema = getToolsForMode('act', { tier: 'full' })