Skip to content

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

Keep a later self-verifying action apart from the submission whose debt it leaves open

Claudefb7694c40e1a
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 8a73b8308..d369ddf66 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -7801,6 +7801,10 @@ export class Agent extends LoopDetector {
const resultSequence = submit.semanticCommit?.verificationNavigation?.actionSequence
?? submit.mastodonPublication?.verificationNavigation?.actionSequence
?? submit.actionSequence;
+ // A self-verifying action (a scheduled task, a verified chat send) after
+ // the submission leaves lastAction on the submission but is a later step.
+ const later = Number(this.completionInvariants.get(tabId)?.laterSelfVerifiedSequence || 0);
+ if (later > Number(resultSequence)) return false;
return Number.isFinite(Number(resultSequence)) && Number(resultSequence) === Number(lastAction.sequence);
}
diff --git a/src/chrome/src/agent/completion-invariant.js b/src/chrome/src/agent/completion-invariant.js
index b30e3cf45..fbf4ecb24 100644
--- a/src/chrome/src/agent/completion-invariant.js
+++ b/src/chrome/src/agent/completion-invariant.js
@@ -939,7 +939,12 @@ export function recordCompletionToolResult(state, name, args = {}, result, { cha
next.hadAction = true;
// A persisted scheduler result proves its own mutation, but it must never
// erase verification debt opened by an earlier page action.
- if (selfVerified && current.verificationDebt) return next;
+ if (selfVerified && current.verificationDebt) {
+ // The run has moved on, though lastAction still names the page action the
+ // debt belongs to: the later action's sequence is kept apart.
+ next.laterSelfVerifiedSequence = sequence;
+ return next;
+ }
next.verificationDebt = !selfVerified;
next.lastAction = {
name,
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index cf7b845f6..b406128ca 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -7342,6 +7342,10 @@ export class Agent extends LoopDetector {
const resultSequence = submit.semanticCommit?.verificationNavigation?.actionSequence
?? submit.mastodonPublication?.verificationNavigation?.actionSequence
?? submit.actionSequence;
+ // A self-verifying action (a scheduled task, a verified chat send) after
+ // the submission leaves lastAction on the submission but is a later step.
+ const later = Number(this.completionInvariants.get(tabId)?.laterSelfVerifiedSequence || 0);
+ if (later > Number(resultSequence)) return false;
return Number.isFinite(Number(resultSequence)) && Number(resultSequence) === Number(lastAction.sequence);
}
diff --git a/src/firefox/src/agent/completion-invariant.js b/src/firefox/src/agent/completion-invariant.js
index b30e3cf45..fbf4ecb24 100644
--- a/src/firefox/src/agent/completion-invariant.js
+++ b/src/firefox/src/agent/completion-invariant.js
@@ -939,7 +939,12 @@ export function recordCompletionToolResult(state, name, args = {}, result, { cha
next.hadAction = true;
// A persisted scheduler result proves its own mutation, but it must never
// erase verification debt opened by an earlier page action.
- if (selfVerified && current.verificationDebt) return next;
+ if (selfVerified && current.verificationDebt) {
+ // The run has moved on, though lastAction still names the page action the
+ // debt belongs to: the later action's sequence is kept apart.
+ next.laterSelfVerifiedSequence = sequence;
+ return next;
+ }
next.verificationDebt = !selfVerified;
next.lastAction = {
name,
diff --git a/test/post-submit-model-recovery.mjs b/test/post-submit-model-recovery.mjs
index ea6b42e14..cb0a7e542 100644
--- a/test/post-submit-model-recovery.mjs
+++ b/test/post-submit-model-recovery.mjs
@@ -151,6 +151,30 @@ for (const browser of ['chrome', 'firefox']) {
assert.equal(offer.retryMode, 'resume');
assert.equal(f.updates.some(x => x.type === 'warning'), false, 'No post-submit inspection notice');
});
+ test(`${browser}: a later self-verifying action does not make the earlier submission the latest step`, async () => {
+ // The submission left verification debt; scheduling a follow-up then
+ // succeeded and proved itself. lastAction still names the submission, but
+ // the run has moved on, so a model failure must name the earlier submission.
+ const { recordCompletionToolResult } = await import(`../src/${browser}/src/agent/completion-invariant.js`);
+ const f = fixture();
+ f.agent.completionInvariants.set(f.tab, { runToken: 'owned-run', sequence: 2, verificationDebt: true, hadAction: true,
+ lastAction: { name: 'click_ax', sequence: 2, uncertain: false } });
+ f.agent._completionSubmitStates.set(f.tab, { dispatched: true, actionSequence: 2,
+ originatingUrl: 'https://mastoturk.org/home', currentUrl: 'https://mastoturk.org/home' });
+ assert.equal(f.agent._completionSubmissionIsLatestAction(f.tab), true);
+ const after = recordCompletionToolResult(f.agent.completionInvariants.get(f.tab), 'schedule_task', {},
+ { success: true, scheduled: true, jobId: 'job-1', scheduledAt: new Date(Date.now() + 3600e3).toISOString() });
+ assert.equal(after.lastAction.sequence, 2, 'the debt still belongs to the submission');
+ f.agent.completionInvariants.set(f.tab, after);
+ assert.equal(f.agent._completionSubmissionIsLatestAction(f.tab), false);
+ f.agent._currentUrl = async () => 'https://mastoturk.org/home';
+ assert.equal(await f.agent._recoverPostActionModelFailure(f.tab, f.messages, f.update, {}, 7), null);
+ const error = Object.assign(new Error('offscreen proxy timed out'), { code: 'TRANSPORT' });
+ const result = await f.agent._finalModelFailure(f.tab, f.messages, f.update, {}, error, 7);
+ assert.deepEqual(f.operations, []);
+ assert.match(result.content, /A submission on mastoturk\.org was sent earlier in this task/);
+ });
+
test(`${browser}: a navigation bound to the submission's result still lets WebBrain check it`, async () => {
const f = fixture();
f.agent._completionSubmitStates.set(f.tab, { dispatched: true, actionSequence: 2,