Skip to content

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

Compare a nested restart with the top-level read after normalizing scalars

Claude881d353ab0c9
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 860c985b3..748685900 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -11312,6 +11312,10 @@ 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'];
+ // 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));
// 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
@@ -11327,7 +11331,7 @@ export class Agent extends LoopDetector {
// that agree with it (a partial copy), is the restart the tool
// returned (page 1 of an anchored subtree after its revision changed),
// and it is the read.
- && Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !Object.is(next[key], value));
+ && Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !agrees(key, value));
if (restart) {
delete next.continuationArgs;
repaired = true;
@@ -11335,7 +11339,7 @@ export class Agent extends LoopDetector {
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));
+ && Object.entries(continuation).every(([key, value]) => agrees(key, value));
if (!valid) {
return { args, repaired: false, note: '', result: {
success: false, invalidArguments: true, invalidToolArguments: true,
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 582d86c3c..2b248dbdc 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -10990,6 +10990,10 @@ 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'];
+ // 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));
// 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
@@ -11005,7 +11009,7 @@ export class Agent extends LoopDetector {
// that agree with it (a partial copy), is the restart the tool
// returned (page 1 of an anchored subtree after its revision changed),
// and it is the read.
- && Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !Object.is(next[key], value));
+ && Object.entries(continuation).some(([key, value]) => String(next[key] ?? '').trim() !== '' && !agrees(key, value));
if (restart) {
delete next.continuationArgs;
repaired = true;
@@ -11013,7 +11017,7 @@ export class Agent extends LoopDetector {
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));
+ && Object.entries(continuation).every(([key, value]) => agrees(key, value));
if (!valid) {
return { args, repaired: false, note: '', result: {
success: false, invalidArguments: true, invalidToolArguments: true,
diff --git a/test/read-continuation-schema.mjs b/test/read-continuation-schema.mjs
index 63d761930..14ed9197a 100644
--- a/test/read-continuation-schema.mjs
+++ b/test/read-continuation-schema.mjs
@@ -233,6 +233,12 @@ 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.
+ 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));
+ assert.equal(mixed.args.ref_id, 'ref_12', JSON.stringify(top));
+ }
});
test(`${browser}: oversized declared prose windows are bounded without losing the requested document position`, () => {