Skip to content

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

Track the last committing action's kind, not a monotonic flag

Claude1306876c92ac
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 2982b1f19..3f539ce62 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -2628,9 +2628,9 @@ export class Agent extends LoopDetector {
}
this._completionSubmitStates.set(tabId, state);
// A later non-committing form (a GET search) replaces this receipt, so the
- // guard remembers that something other than a deletion was committed.
- if (state.dispatched && publicationGuard && state.nonCommitting !== true && state.mutationKind !== 'delete') {
- publicationGuard.ordinaryCommitDispatched = true;
+ // guard remembers the kind of the last action that did commit.
+ if (state.dispatched && publicationGuard && state.nonCommitting !== true) {
+ publicationGuard.lastCommitKind = state.mutationKind;
}
if (state.dispatched && publicationGuard?.resourceMutationAuthorization) {
const record = state.actionRecord;
@@ -6583,7 +6583,7 @@ export class Agent extends LoopDetector {
socialPublication: structuredClone(previous?.socialPublication || null),
} : null);
guard.resourceMutationDispatches = structuredClone(previous?.resourceMutationDispatches || []);
- guard.ordinaryCommitDispatched = previous?.ordinaryCommitDispatched === true;
+ guard.lastCommitKind = previous?.lastCommitKind || null;
if (priorSubmission || attemptedPublication) guard.evidenceTaskKey = guard.taskKey;
guard.socialPublicationSteering = previous?.socialPublicationSteering || null;
guard.socialPublicationClarifications = previous?.socialPublicationClarifications || [];
@@ -40018,7 +40018,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
steeringPriorContext: carryMatches ? structuredClone(carried.steeringPriorContext || null) : null,
steeringPriorSubmissionReconciliation: carryMatches ? structuredClone(carried.steeringPriorSubmissionReconciliation || null) : null,
resourceMutationDispatches: carryMatches ? structuredClone(carried.resourceMutationDispatches || []) : [],
- ordinaryCommitDispatched: carryMatches && carried.ordinaryCommitDispatched === true,
+ lastCommitKind: carryMatches ? carried.lastCommitKind || null : null,
// The user's answers on WebBrain's deletion card hold for the same task.
deletionDecisions: carryMatches && Array.isArray(carried.deletionDecisions)
? structuredClone(carried.deletionDecisions.slice(-32)) : [],
@@ -40566,7 +40566,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
steeringPriorContext: structuredClone(guard.steeringPriorContext || null),
steeringPriorSubmissionReconciliation: structuredClone(guard.steeringPriorSubmissionReconciliation || null),
resourceMutationDispatches: structuredClone(guard.resourceMutationDispatches || []),
- ordinaryCommitDispatched: guard.ordinaryCommitDispatched === true,
+ lastCommitKind: guard.lastCommitKind || null,
deletionDecisions: structuredClone((guard.deletionDecisions || []).slice(-32)),
unverifiedStepDecisions: structuredClone(this._carriedUnverifiedStepDecisions(guard)),
socialPublication: guard.socialPublication ? structuredClone(guard.socialPublication) : null,
@@ -40897,18 +40897,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// caveat. The one-nudge budget and run-ending statuses below are the
// strict path.
// The unverified action is a deletion only when deletions are all that was
- // dispatched. A dispatched deletion is also the current submit receipt
- // (_recordCompletionSubmitState keeps both), so that receipt is fine; a
- // later ordinary form submission replaces it with one that is not a
- // deletion and leaves no resource-mutation record of its own. A
- // non-committing form (a GET search that checks the item is gone) also
- // replaces the receipt but dispatches no second mutation, so it is ignored.
- const currentReceipt = missingRequiredSubmission ? this._currentCompletionSubmitState(tabId) : null;
+ // dispatched and the last action that committed was a deletion. A form
+ // submitted after it (or before it, if a deletion came last) is told apart
+ // by the kind of the last commit, which a later non-committing form such as
+ // a GET search does not overwrite.
const missingDeletion = missingRequiredSubmission
&& Array.isArray(state.resourceMutationDispatches) && state.resourceMutationDispatches.length > 0
&& state.resourceMutationDispatches.every(attempt => attempt?.mutationKind === 'delete')
- && state.ordinaryCommitDispatched !== true
- && (currentReceipt?.dispatched !== true || currentReceipt.mutationKind === 'delete' || currentReceipt.nonCommitting === true);
+ && (state.lastCommitKind == null || state.lastCommitKind === 'delete');
const advisory = this._planGuardAdvisory(tabId, state, { viaDone, looksPlanOnly, runtimeModeContradiction,
structuredPlan: structuredPlan
|| (state.allowsPlannerShapedResult !== true && this._isPlannerShapedJson(content)),
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 5f4586dc8..e1d1f4535 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -2185,9 +2185,9 @@ export class Agent extends LoopDetector {
}
this._completionSubmitStates.set(tabId, state);
// A later non-committing form (a GET search) replaces this receipt, so the
- // guard remembers that something other than a deletion was committed.
- if (state.dispatched && publicationGuard && state.nonCommitting !== true && state.mutationKind !== 'delete') {
- publicationGuard.ordinaryCommitDispatched = true;
+ // guard remembers the kind of the last action that did commit.
+ if (state.dispatched && publicationGuard && state.nonCommitting !== true) {
+ publicationGuard.lastCommitKind = state.mutationKind;
}
if (state.dispatched && publicationGuard?.resourceMutationAuthorization) {
const record = state.actionRecord;
@@ -6124,7 +6124,7 @@ export class Agent extends LoopDetector {
socialPublication: structuredClone(previous?.socialPublication || null),
} : null);
guard.resourceMutationDispatches = structuredClone(previous?.resourceMutationDispatches || []);
- guard.ordinaryCommitDispatched = previous?.ordinaryCommitDispatched === true;
+ guard.lastCommitKind = previous?.lastCommitKind || null;
if (priorSubmission || attemptedPublication) guard.evidenceTaskKey = guard.taskKey;
guard.socialPublicationSteering = previous?.socialPublicationSteering || null;
guard.socialPublicationClarifications = previous?.socialPublicationClarifications || [];
@@ -36761,7 +36761,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
steeringPriorContext: carryMatches ? structuredClone(carried.steeringPriorContext || null) : null,
steeringPriorSubmissionReconciliation: carryMatches ? structuredClone(carried.steeringPriorSubmissionReconciliation || null) : null,
resourceMutationDispatches: carryMatches ? structuredClone(carried.resourceMutationDispatches || []) : [],
- ordinaryCommitDispatched: carryMatches && carried.ordinaryCommitDispatched === true,
+ lastCommitKind: carryMatches ? carried.lastCommitKind || null : null,
// The user's answers on WebBrain's deletion card hold for the same task.
deletionDecisions: carryMatches && Array.isArray(carried.deletionDecisions)
? structuredClone(carried.deletionDecisions.slice(-32)) : [],
@@ -37309,7 +37309,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
steeringPriorContext: structuredClone(guard.steeringPriorContext || null),
steeringPriorSubmissionReconciliation: structuredClone(guard.steeringPriorSubmissionReconciliation || null),
resourceMutationDispatches: structuredClone(guard.resourceMutationDispatches || []),
- ordinaryCommitDispatched: guard.ordinaryCommitDispatched === true,
+ lastCommitKind: guard.lastCommitKind || null,
deletionDecisions: structuredClone((guard.deletionDecisions || []).slice(-32)),
unverifiedStepDecisions: structuredClone(this._carriedUnverifiedStepDecisions(guard)),
socialPublication: guard.socialPublication ? structuredClone(guard.socialPublication) : null,
@@ -37640,18 +37640,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// caveat. The one-nudge budget and run-ending statuses below are the
// strict path.
// The unverified action is a deletion only when deletions are all that was
- // dispatched. A dispatched deletion is also the current submit receipt
- // (_recordCompletionSubmitState keeps both), so that receipt is fine; a
- // later ordinary form submission replaces it with one that is not a
- // deletion and leaves no resource-mutation record of its own. A
- // non-committing form (a GET search that checks the item is gone) also
- // replaces the receipt but dispatches no second mutation, so it is ignored.
- const currentReceipt = missingRequiredSubmission ? this._currentCompletionSubmitState(tabId) : null;
+ // dispatched and the last action that committed was a deletion. A form
+ // submitted after it (or before it, if a deletion came last) is told apart
+ // by the kind of the last commit, which a later non-committing form such as
+ // a GET search does not overwrite.
const missingDeletion = missingRequiredSubmission
&& Array.isArray(state.resourceMutationDispatches) && state.resourceMutationDispatches.length > 0
&& state.resourceMutationDispatches.every(attempt => attempt?.mutationKind === 'delete')
- && state.ordinaryCommitDispatched !== true
- && (currentReceipt?.dispatched !== true || currentReceipt.mutationKind === 'delete' || currentReceipt.nonCommitting === true);
+ && (state.lastCommitKind == null || state.lastCommitKind === 'delete');
const advisory = this._planGuardAdvisory(tabId, state, { viaDone, looksPlanOnly, runtimeModeContradiction,
structuredPlan: structuredPlan
|| (state.allowsPlannerShapedResult !== true && this._isPlannerShapedJson(content)),
diff --git a/test/guard-advisory-completion.mjs b/test/guard-advisory-completion.mjs
index 54565f899..018ac96b0 100644
--- a/test/guard-advisory-completion.mjs
+++ b/test/guard-advisory-completion.mjs
@@ -1023,6 +1023,7 @@ for (const build of ['chrome', 'firefox']) {
await refusedOnceThenAccepted(Agent, planCase({ requiresStateChange: true, requiresSubmission: true }, (guard, h) => {
guard.successfulConsequentialToolCalls = 1; guard.successfulTaskToolCalls = 1; guard.evidenceTaskKey = guard.taskKey;
guard.resourceMutationDispatches = [{ mutationKind: 'delete', resourceUrl: 'https://mastoturk.org/@owned/1', actionSequence: 3 }];
+ guard.lastCommitKind = 'delete';
h.agent._completionSubmitStates.set(h.tab, { dispatched: true, mutationKind: 'delete', actionSequence: 3, taskKey: guard.taskKey });
}), { summary: 'Deleted the post.', outcome: 'success' }, 'I couldn\'t confirm that the deletion took effect.', `${build} deletion`);
@@ -1039,15 +1040,24 @@ for (const build of ['chrome', 'firefox']) {
await refusedOnceThenAccepted(Agent, planCase({ requiresStateChange: true, requiresSubmission: true }, (guard, h) => {
guard.successfulConsequentialToolCalls = 2; guard.successfulTaskToolCalls = 2; guard.evidenceTaskKey = guard.taskKey;
guard.resourceMutationDispatches = [{ mutationKind: 'delete', resourceUrl: 'https://mastoturk.org/@owned/1', actionSequence: 3 }];
- guard.ordinaryCommitDispatched = true;
+ guard.lastCommitKind = 'submit';
h.agent._completionSubmitStates.set(h.tab, { dispatched: true, nonCommitting: true, mutationKind: 'submit', actionSequence: 5, taskKey: guard.taskKey });
}), { summary: 'Deleted the post and sent the form.', outcome: 'success' }, 'I couldn\'t confirm that the submission went through.', `${build} deletion, form, then search`);
+ // An ordinary form, then a deletion: the deletion is the last commit and the unverified action.
+ await refusedOnceThenAccepted(Agent, planCase({ requiresStateChange: true, requiresSubmission: true }, (guard, h) => {
+ guard.successfulConsequentialToolCalls = 2; guard.successfulTaskToolCalls = 2; guard.evidenceTaskKey = guard.taskKey;
+ guard.resourceMutationDispatches = [{ mutationKind: 'delete', resourceUrl: 'https://mastoturk.org/@owned/1', actionSequence: 5 }];
+ guard.lastCommitKind = 'delete';
+ h.agent._completionSubmitStates.set(h.tab, { dispatched: true, mutationKind: 'delete', actionSequence: 5, taskKey: guard.taskKey });
+ }), { summary: 'Sent the form and deleted the post.', outcome: 'success' }, 'I couldn\'t confirm that the deletion took effect.', `${build} form, then deletion`);
+
// With an ordinary form submission also dispatched, the unverified action
// may be that submission, so the deletion wording is not used.
await refusedOnceThenAccepted(Agent, planCase({ requiresStateChange: true, requiresSubmission: true }, (guard, h) => {
guard.successfulConsequentialToolCalls = 2; guard.successfulTaskToolCalls = 2; guard.evidenceTaskKey = guard.taskKey;
guard.resourceMutationDispatches = [{ mutationKind: 'delete', resourceUrl: 'https://mastoturk.org/@owned/1' }];
+ guard.lastCommitKind = 'submit';
h.agent._completionSubmitStates.set(h.tab, { dispatched: true, taskKey: guard.taskKey });
}), { summary: 'Deleted the post and sent the form.', outcome: 'success' }, 'I couldn\'t confirm that the submission went through.', `${build} deletion plus form`);