Skip to content

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

Fold case only in a filter when comparing a nested continuation

Claude14b645f3f371
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 0630d4034..0f580e326 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -11314,8 +11314,8 @@ export class Agent extends LoopDetector {
const allowed = ['filter', 'maxDepth', 'maxChars', 'ref_id', 'page', 'tree_revision'];
// Two values agree when they are the same once scalar types and the
// case of a filter are normalized, as the call is repaired below.
- const normalized = value => { const scalar = decimal(value); return typeof scalar === 'string' ? scalar.trim().toLowerCase() : scalar; };
- const agrees = (key, value) => !Object.hasOwn(next, key) || Object.is(normalized(next[key]), normalized(value));
+ const normalized = (value, key) => { const scalar = decimal(value); return typeof scalar === 'string' ? (key === 'filter' ? scalar.trim().toLowerCase() : scalar.trim()) : scalar; };
+ const agrees = (key, value) => !Object.hasOwn(next, key) || Object.is(normalized(next[key], key), normalized(value, key));
// 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
@@ -11325,7 +11325,7 @@ export class Agent extends LoopDetector {
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].includes(normalized(continuation.page))
+ && [undefined, null, '', 1].includes(normalized(continuation.page, 'page'))
// It is a placeholder only beside a read of the call's own. A restart
// the tool returns is always anchored (it names a ref_id), so one that
// names none cannot be genuine and is dropped beside any top-level read;
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 3a06438c9..1cc554e24 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -10992,8 +10992,8 @@ export class Agent extends LoopDetector {
const allowed = ['filter', 'maxDepth', 'maxChars', 'ref_id', 'page', 'tree_revision'];
// Two values agree when they are the same once scalar types and the
// case of a filter are normalized, as the call is repaired below.
- const normalized = value => { const scalar = decimal(value); return typeof scalar === 'string' ? scalar.trim().toLowerCase() : scalar; };
- const agrees = (key, value) => !Object.hasOwn(next, key) || Object.is(normalized(next[key]), normalized(value));
+ const normalized = (value, key) => { const scalar = decimal(value); return typeof scalar === 'string' ? (key === 'filter' ? scalar.trim().toLowerCase() : scalar.trim()) : scalar; };
+ const agrees = (key, value) => !Object.hasOwn(next, key) || Object.is(normalized(next[key], key), normalized(value, key));
// 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
@@ -11003,7 +11003,7 @@ export class Agent extends LoopDetector {
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].includes(normalized(continuation.page))
+ && [undefined, null, '', 1].includes(normalized(continuation.page, 'page'))
// It is a placeholder only beside a read of the call's own. A restart
// the tool returns is always anchored (it names a ref_id), so one that
// names none cannot be genuine and is dropped beside any top-level read;
diff --git a/test/read-continuation-schema.mjs b/test/read-continuation-schema.mjs
index dfb66d035..2479a42d7 100644
--- a/test/read-continuation-schema.mjs
+++ b/test/read-continuation-schema.mjs
@@ -233,7 +233,7 @@ for (const browser of ['chrome', 'firefox']) {
assert.equal(partial.result, undefined);
assert.equal(partial.args.ref_id, 'ref_12');
assert.equal(partial.args.filter, 'interactive');
- // So it is beside values that only differ in type or case.
+ // So it is beside values that only differ in type or a filter's case.
for (const top of [{ page: '1' }, { maxChars: '6000' }, { filter: 'INTERACTIVE' }, { maxDepth: ' 15 ' }]) {
const mixed = agent._repairToolCallArgs('get_accessibility_tree', { ...top, continuationArgs: restart });
assert.equal(mixed.result, undefined, JSON.stringify(top));
@@ -241,6 +241,15 @@ for (const browser of ['chrome', 'firefox']) {
}
});
+ test(`${browser}: a tree revision is compared exactly, not case-folded`, () => {
+ const agent = new Agent({ getActive: () => null });
+ const page2 = { filter: 'interactive', maxDepth: 15, maxChars: 6000, ref_id: 'ref_12', page: 2, tree_revision: 'fnv1a64:d0891b5ff4884d4a' };
+ const altered = agent._repairToolCallArgs('get_accessibility_tree', { tree_revision: 'FNV1A64:D0891B5FF4884D4A', continuationArgs: page2 });
+ assert.equal(altered.result?.errorCode, 'invalid_tool_arguments');
+ const same = agent._repairToolCallArgs('get_accessibility_tree', { tree_revision: page2.tree_revision, continuationArgs: page2 });
+ assert.equal(same.result, undefined);
+ });
+
test(`${browser}: an unanchored or loosely written page-1 object beside a read is a placeholder`, () => {
const agent = new Agent({ getActive: () => null });
// No ref_id: the tool never returns such a restart, so the top-level read stands.