Skip to content

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

Keep a deletion bound to its post when the relative time ticks over

Claudeabd5fdaa4891
diff --git a/docs/guards.md b/docs/guards.md
index 58c26e7b3..efe951048 100644
--- a/docs/guards.md
+++ b/docs/guards.md
@@ -139,6 +139,13 @@ Mastodon post is one WebBrain cannot match after the fact (the home timeline
shows it, not a page of its own), and "now delete it" used to be refused on
every click there.
+A deletion stays bound to the item's text, with each `<time datetime>`
+element read as its datetime rather than as the relative time it shows.
+Mastodon's "8 min" turning into "9 min" while the user decides on the deletion
+card is the same post, but edited text or another datetime is not. Before
+this, the check after the card refused such a deletion as `resource_changed`,
+on every retry.
+
The `permission_gate`, `host_check`, `budget`, `infra` and `user_control`
entries in the registry document checks that are not guards; they are listed
there so the registry covers every refusal.
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index be48ed8c4..50cba94b7 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -6831,10 +6831,15 @@ export class Agent extends LoopDetector {
if (!detected || !['click', 'click_ax', 'iframe_click'].includes(name)
|| Number.isFinite(args?.x) || Number.isFinite(args?.y)) return '';
const record = detected.actionRecord;
+ // The resource's texts with its timestamps read as their datetime
+ // (stableTextValues), so a relative time ticking over while the user
+ // decides on WebBrain's card does not change the key.
+ const resource = detected.actionResource ? (({ textValues, stableTextValues, ...identity }) => ({ ...identity,
+ textValues: Array.isArray(stableTextValues) ? stableTextValues : textValues }))(detected.actionResource) : null;
return this._sha256TextSync(JSON.stringify({ taskKey: this._progressTaskKeyHash(tabId), name,
target: this._formValidationActionKey(name, args), kind: detected.mutationKind || (detected.publicationControl ? 'publish' : 'submit'),
isSubmit: detected.isSubmit === true, preparatory: detected.resolvedPreparatoryTarget === true,
- document: detected.frameDocumentIdentity, resource: detected.actionResource || null,
+ document: detected.frameDocumentIdentity, resource,
snapshot: detected.publicationSnapshot || null,
fields: this._publicMutationFields(detected.fields), destination: detected.actionUrl || '',
// A changed row, stage or peer set changes the key, so neither a fresh
@@ -33916,6 +33921,22 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// Other menus/dialogs still make this native transition ambiguous.
return nodes.filter(node => node.matches(native) || (!node.closest(native) && !node.querySelector(native)));
};
+ // A record's texts as its identity: a <time datetime> element reads as its
+ // datetime, not as the relative time it renders ("8 min" turns into
+ // "9 min" by itself while a deletion waits on WebBrain's card), so a
+ // ticking timestamp does not make the same post another one.
+ const stableText = node => {
+ let text = '';
+ const pending = [node];
+ while (pending.length) {
+ const current = pending.pop();
+ if (current.nodeType === 3) text += current.data;
+ else if (current.nodeType === 1 && current.matches('time[datetime]')) text += `\u0000${current.getAttribute('datetime')}\u0000`;
+ else if (current.nodeType === 1) for (let index = current.childNodes.length - 1; index >= 0; index -= 1) pending.push(current.childNodes[index]);
+ }
+ return text;
+ };
+ const stableTexts = nodes => [...new Set(nodes.map(stableText).filter(value => value.length <= 25000))];
const nativeResourceProofs = () => {
if (args.__wbNativeResourceAdapter !== 'mastodon') return [];
const signedIn = nativeSignedInAccount();
@@ -33935,12 +33956,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (!handle || permalink.origin !== location.origin || permalink.search || permalink.hash
|| account !== `${permalink.origin}/@${handle.toLowerCase()}` || account !== signedIn) continue;
const nodes = [record, ...record.querySelectorAll('*')];
- const textValues = [...new Set(nodes.slice(0, 400).filter(nativeIdentityVisible).flatMap(node => [node.innerText, node.textContent])
+ const shown = nodes.slice(0, 400).filter(nativeIdentityVisible);
+ const textValues = [...new Set(shown.flatMap(node => [node.innerText, node.textContent])
.filter(value => typeof value === 'string' && value.length <= 25000))];
proofs.push({ url: permalink.href, account, nativeAdapter: 'mastodon',
taskKey: args.__wbResourceTaskKey, runToken: args.__wbResourceRunToken,
complete: records.length <= 80 && nodes.length <= 400 && JSON.stringify(textValues).length <= 60000,
- scopeToken: rememberResourceScope(record, permalink.href), textValues, _record: record });
+ scopeToken: rememberResourceScope(record, permalink.href), textValues, stableTextValues: stableTexts(shown), _record: record });
}
return proofs;
};
@@ -33963,11 +33985,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return /^https?:$/.test(parsed.protocol) && parsed.origin === location.origin ? parsed.href : ''; } catch { return ''; } }).filter(Boolean))];
if (urls.length !== 1) continue;
const nodes = [record, ...record.querySelectorAll('*')];
- const textValues = [...new Set(nodes.slice(0, 400).filter(isVisible).flatMap(node => [node.innerText, node.textContent])
+ const shown = nodes.slice(0, 400).filter(isVisible);
+ const textValues = [...new Set(shown.flatMap(node => [node.innerText, node.textContent])
.filter(value => typeof value === 'string' && value.length <= 25000))];
results.push({ url: urls[0], complete: nodes.length <= 400 && records.length <= 80 && JSON.stringify(textValues).length <= 60000,
scopeToken: rememberResourceScope(record, urls[0]),
- textValues, _record: record });
+ textValues, stableTextValues: stableTexts(shown), _record: record });
}
// Native evidence is authoritative for a native record, including its
// active account fence; a generic wrapper cannot bypass that fence.
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 241956fd9..5aaf74b87 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -6372,10 +6372,15 @@ export class Agent extends LoopDetector {
if (!detected || !['click', 'click_ax', 'iframe_click'].includes(name)
|| Number.isFinite(args?.x) || Number.isFinite(args?.y)) return '';
const record = detected.actionRecord;
+ // The resource's texts with its timestamps read as their datetime
+ // (stableTextValues), so a relative time ticking over while the user
+ // decides on WebBrain's card does not change the key.
+ const resource = detected.actionResource ? (({ textValues, stableTextValues, ...identity }) => ({ ...identity,
+ textValues: Array.isArray(stableTextValues) ? stableTextValues : textValues }))(detected.actionResource) : null;
return this._sha256TextSync(JSON.stringify({ taskKey: this._progressTaskKeyHash(tabId), name,
target: this._formValidationActionKey(name, args), kind: detected.mutationKind || (detected.publicationControl ? 'publish' : 'submit'),
isSubmit: detected.isSubmit === true, preparatory: detected.resolvedPreparatoryTarget === true,
- document: detected.frameDocumentIdentity, resource: detected.actionResource || null,
+ document: detected.frameDocumentIdentity, resource,
snapshot: detected.publicationSnapshot || null,
fields: this._publicMutationFields(detected.fields), destination: detected.actionUrl || '',
// A changed row, stage or peer set changes the key, so neither a fresh
@@ -30784,6 +30789,22 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// Other menus/dialogs still make this native transition ambiguous.
return nodes.filter(node => node.matches(native) || (!node.closest(native) && !node.querySelector(native)));
};
+ // A record's texts as its identity: a <time datetime> element reads as its
+ // datetime, not as the relative time it renders ("8 min" turns into
+ // "9 min" by itself while a deletion waits on WebBrain's card), so a
+ // ticking timestamp does not make the same post another one.
+ const stableText = node => {
+ let text = '';
+ const pending = [node];
+ while (pending.length) {
+ const current = pending.pop();
+ if (current.nodeType === 3) text += current.data;
+ else if (current.nodeType === 1 && current.matches('time[datetime]')) text += `\u0000${current.getAttribute('datetime')}\u0000`;
+ else if (current.nodeType === 1) for (let index = current.childNodes.length - 1; index >= 0; index -= 1) pending.push(current.childNodes[index]);
+ }
+ return text;
+ };
+ const stableTexts = nodes => [...new Set(nodes.map(stableText).filter(value => value.length <= 25000))];
const nativeResourceProofs = () => {
if (args.__wbNativeResourceAdapter !== 'mastodon') return [];
const signedIn = nativeSignedInAccount();
@@ -30803,12 +30824,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (!handle || permalink.origin !== location.origin || permalink.search || permalink.hash
|| account !== `${permalink.origin}/@${handle.toLowerCase()}` || account !== signedIn) continue;
const nodes = [record, ...record.querySelectorAll('*')];
- const textValues = [...new Set(nodes.slice(0, 400).filter(nativeIdentityVisible).flatMap(node => [node.innerText, node.textContent])
+ const shown = nodes.slice(0, 400).filter(nativeIdentityVisible);
+ const textValues = [...new Set(shown.flatMap(node => [node.innerText, node.textContent])
.filter(value => typeof value === 'string' && value.length <= 25000))];
proofs.push({ url: permalink.href, account, nativeAdapter: 'mastodon',
taskKey: args.__wbResourceTaskKey, runToken: args.__wbResourceRunToken,
complete: records.length <= 80 && nodes.length <= 400 && JSON.stringify(textValues).length <= 60000,
- scopeToken: rememberResourceScope(record, permalink.href), textValues, _record: record });
+ scopeToken: rememberResourceScope(record, permalink.href), textValues, stableTextValues: stableTexts(shown), _record: record });
}
return proofs;
};
@@ -30831,11 +30853,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return /^https?:$/.test(parsed.protocol) && parsed.origin === location.origin ? parsed.href : ''; } catch { return ''; } }).filter(Boolean))];
if (urls.length !== 1) continue;
const nodes = [record, ...record.querySelectorAll('*')];
- const textValues = [...new Set(nodes.slice(0, 400).filter(isVisible).flatMap(node => [node.innerText, node.textContent])
+ const shown = nodes.slice(0, 400).filter(isVisible);
+ const textValues = [...new Set(shown.flatMap(node => [node.innerText, node.textContent])
.filter(value => typeof value === 'string' && value.length <= 25000))];
results.push({ url: urls[0], complete: nodes.length <= 400 && records.length <= 80 && JSON.stringify(textValues).length <= 60000,
scopeToken: rememberResourceScope(record, urls[0]),
- textValues, _record: record });
+ textValues, stableTextValues: stableTexts(shown), _record: record });
}
// Native evidence is authoritative for a native record, including its
// active account fence; a generic wrapper cannot bypass that fence.
diff --git a/test/native-resource-deletion-binding.mjs b/test/native-resource-deletion-binding.mjs
index 86fb1cd62..2f99c7ba5 100644
--- a/test/native-resource-deletion-binding.mjs
+++ b/test/native-resource-deletion-binding.mjs
@@ -301,6 +301,46 @@ for (const build of ['chrome', 'firefox']) {
} finally { await f.page.close(); }
});
+ // QA M1c: the post's relative time ("8 min") ticked over while the
+ // user decided on WebBrain's deletion card, and the confirmation's
+ // fresh probe no longer matched, so the deletion was refused as
+ // resource_changed every time it was retried.
+ await t.test('a relative time ticking over while the deletion waits keeps the same post', async () => {
+ const f = await fixture();
+ try {
+ const request = `Delete only ${resource}.`;
+ const provider = { chat() {} }, agent = new Agent({ getActive: () => provider });
+ agent.conversations.set(1, [{ role: 'system', content: 'system' }, { role: 'user', content: request }]);
+ agent._startPlanExecutionGuard(1, 'act', { requestKind: 'execute', requiresStateChange: true, requiresSubmission: true });
+ await f.page.evaluate(() => {
+ document.querySelector('#record-200 .status__relative-time').innerHTML
+ = '<time datetime="2026-10-18T19:22:00.000Z" title="18 Eki 2026 22:22">8 dk</time>';
+ });
+ await f.showConfirmation();
+ const detected = await f.probe('#confirm');
+ assert.equal(detected.actionResource.url, resource);
+ const tick = text => f.page.evaluate(value => {
+ document.querySelector('#record-200 .status__relative-time time').textContent = value;
+ }, text);
+ let probes = 0;
+ agent._detectLikelySubmitAction = async () => { await tick(`${9 + probes++} dk`); return f.probe('#confirm'); };
+ installModelStub(agent);
+ const result = await agent._resourceMutationPreSubmitBlock(1, 'click', { selector: '#confirm' }, detected, provider);
+ assert.equal(result?.actionGuard?.reason || null, null, JSON.stringify(result?.actionGuard));
+ assert.ok(probes >= 1, 'The post was probed again after it ticked over');
+ assert.equal(await f.page.evaluate(() => qaDeletes), 0, 'Preflight never dispatches deletion.');
+ // What the post says, and the moment it was posted, still bind it.
+ const key = found => agent._resourceMutationActionKey(1, 'click', { selector: '#confirm' }, found);
+ await f.page.evaluate(() => { document.querySelector('#record-200 .status__content__text--visible p').textContent = 'Edited post'; });
+ assert.notEqual(key(await f.probe('#confirm')), key(detected), 'Edited text is another post');
+ await f.page.evaluate(() => {
+ document.querySelector('#record-200 .status__content__text--visible p').textContent = 'Exact owned post 200';
+ document.querySelector('#record-200 .status__relative-time time').setAttribute('datetime', '2026-10-18T18:00:00.000Z');
+ });
+ assert.notEqual(key(await f.probe('#confirm')), key(detected), 'Another moment is another post');
+ } finally { await f.page.close(); }
+ });
+
for (const variant of ['stable-confirmation', 'stable-direct', 'flip-before-authorization', 'flip-during-authorization']) {
await t.test(`${variant} is revalidated by production mutation preflight`, async () => {
const f = await fixture();