Skip to content

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

Ask cards: a GitHub commit is checked again right before it is sent

Barack Sokullu82625dc04d5c
diff --git a/docs/guards.md b/docs/guards.md
index 295f3df15..9f21f5069 100644
--- a/docs/guards.md
+++ b/docs/guards.md
@@ -83,9 +83,11 @@ When a guard cannot verify a consequential step and its `onCannotDecide` is
that call runs sees it, and it is spent when the call ends, sent or not, so
the next attempt (a repeated commit or post included) asks again. Changed
content is asked about again, and a declined step with the same content is
- not. When the checks after a "Go ahead" reach another guard's question
- about the same action, that card is asked in turn and the first answer
- stands.
+ not. The content is checked again right before the step is sent, after any
+ later submit or permission card: if it changed while a card waited, the
+ step is refused there and the next attempt asks. When the checks after a
+ "Go ahead" reach another guard's question about the same action, that card
+ is asked in turn and the first answer stands.
- **Timeout.** A quality guard's card follows Settings → General: the clarify
timeout (Off waits, Instant answers at once) and "When a question times
out" (`finish` goes ahead, `safe` does not). A hard-class card never times
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 35a0d4311..46230b23c 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -3259,13 +3259,22 @@ export class Agent extends LoopDetector {
const socialBlock = await this._socialPublicationPreSubmitBlock(tabId, name, args, detectedSubmit, provider);
if (socialBlock) return socialBlock;
await this._captureMastodonPublicationAttempt(tabId, name, args, detectedSubmit, provider);
+ return this._githubCommitPreSubmitBlock(tabId, name, args, detectedSubmit, advisories);
+ }
+
+ // GitHub's edit-file-and-commit gate: a commit goes out only on the exact
+ // file and message evidence (or the user's answer on the card for the
+ // editor text it showed). Run before the call's cards and again right
+ // before dispatch, since those cards can wait while the editor changes.
+ async _githubCommitPreSubmitBlock(tabId, name, args = {}, detectedSubmit = null, advisories = null, { recheck = false } = {}) {
const guard = this._planExecutionGuards.get(tabId);
if (guard?.siteWorkflow?.adapterName !== 'github'
|| guard.siteWorkflow?.job?.id !== 'edit-file-and-commit') return null;
// This gate decides before the click by what a text click's caption
- // means, so an unread caption is read now, once, in any language.
+ // means, so an unread caption is read now, once, in any language. The
+ // recheck before dispatch uses that reading as it stands.
const caption = this._controlCaption(name, args, null);
- if (caption && this._controlEffectReading(caption) === null) await this._readControlEffect(tabId, caption);
+ if (!recheck && caption && this._controlEffectReading(caption) === null) await this._readControlEffect(tabId, caption);
const looksLikeSubmit = detectedSubmit?.isSubmit === true
|| this._formValidationActionLooksSubmit(name, args, null, detectedSubmit);
// Fail closed when submit detection is inconclusive: a click_ax carrying
@@ -16355,7 +16364,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// stands, without the card's page text.
const socialDispatchBlock = pipelineToolbarPreflight.block ? null
: this._withoutUnverifiedStepAsk(
- await this._socialPublicationPreSubmitBlock(tabId, fnName, fnArgs, detectedSubmitAction, provider));
+ await this._socialPublicationPreSubmitBlock(tabId, fnName, fnArgs, detectedSubmitAction, provider))
+ // The same for a GitHub commit: the submit and permission
+ // cards after the first check can wait while the editor
+ // changes, and a "Go ahead" covers only the text the user saw.
+ // Its notes were already given by the first check.
+ || this._withoutUnverifiedStepAsk(
+ await this._githubCommitPreSubmitBlock(tabId, fnName, fnArgs, detectedSubmitAction, [], { recheck: true }));
this._throwIfAborted(abortSignal);
// Permission, checkpoint and preflight waits can receive a correction.
// Recheck after all preparation, before marking or invoking dispatch.
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 4507933d6..8882f63ad 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -2816,13 +2816,22 @@ export class Agent extends LoopDetector {
const socialBlock = await this._socialPublicationPreSubmitBlock(tabId, name, args, detectedSubmit, provider);
if (socialBlock) return socialBlock;
await this._captureMastodonPublicationAttempt(tabId, name, args, detectedSubmit, provider);
+ return this._githubCommitPreSubmitBlock(tabId, name, args, detectedSubmit, advisories);
+ }
+
+ // GitHub's edit-file-and-commit gate: a commit goes out only on the exact
+ // file and message evidence (or the user's answer on the card for the
+ // editor text it showed). Run before the call's cards and again right
+ // before dispatch, since those cards can wait while the editor changes.
+ async _githubCommitPreSubmitBlock(tabId, name, args = {}, detectedSubmit = null, advisories = null, { recheck = false } = {}) {
const guard = this._planExecutionGuards.get(tabId);
if (guard?.siteWorkflow?.adapterName !== 'github'
|| guard.siteWorkflow?.job?.id !== 'edit-file-and-commit') return null;
// This gate decides before the click by what a text click's caption
- // means, so an unread caption is read now, once, in any language.
+ // means, so an unread caption is read now, once, in any language. The
+ // recheck before dispatch uses that reading as it stands.
const caption = this._controlCaption(name, args, null);
- if (caption && this._controlEffectReading(caption) === null) await this._readControlEffect(tabId, caption);
+ if (!recheck && caption && this._controlEffectReading(caption) === null) await this._readControlEffect(tabId, caption);
const looksLikeSubmit = detectedSubmit?.isSubmit === true
|| this._formValidationActionLooksSubmit(name, args, null, detectedSubmit);
// Fail closed when submit detection is inconclusive: a click_ax carrying
@@ -14634,7 +14643,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// stands, without the card's page text.
const socialDispatchBlock = pipelineToolbarPreflight.block ? null
: this._withoutUnverifiedStepAsk(
- await this._socialPublicationPreSubmitBlock(tabId, fnName, fnArgs, detectedSubmitAction, provider));
+ await this._socialPublicationPreSubmitBlock(tabId, fnName, fnArgs, detectedSubmitAction, provider))
+ // The same for a GitHub commit: the submit and permission
+ // cards after the first check can wait while the editor
+ // changes, and a "Go ahead" covers only the text the user saw.
+ // Its notes were already given by the first check.
+ || this._withoutUnverifiedStepAsk(
+ await this._githubCommitPreSubmitBlock(tabId, fnName, fnArgs, detectedSubmitAction, [], { recheck: true }));
this._throwIfAborted(abortSignal);
// Permission, checkpoint and preflight waits can receive a correction.
// Recheck after all preparation, before marking or invoking dispatch.
diff --git a/test/guard-ask-cards.mjs b/test/guard-ask-cards.mjs
index 3db0a80b9..bb48962eb 100644
--- a/test/guard-ask-cards.mjs
+++ b/test/guard-ask-cards.mjs
@@ -496,6 +496,36 @@ for (const { build, Agent, adapters, Scheduler } of builds) {
assert.equal(dispatched.length, 2);
});
+ test(`${build}: an editor that changes while a later card waits is checked again right before the commit`, async () => {
+ for (const changes of [true, false]) {
+ const { agent, tab, provider, page } = await githubFixture();
+ const { dispatched, cards, run } = pipeline(agent, provider, 'once');
+ // The submit confirmation and the permission card come after the
+ // unverified-step card; the editor changes while the first one waits.
+ agent._skipPermissionGate = false;
+ const waits = [];
+ agent._promptSubmitConfirmation = async () => {
+ waits.push('submit');
+ if (changes) page.editor = `${POST_BODY}Late edit.\n`;
+ return 'once';
+ };
+ agent._promptPermission = async () => { waits.push('permission'); return 'once'; };
+ const { messages } = await run(tab, [call('commit', 'click_ax', { ref_id: 'ref_7' })]);
+ assert.equal(cards.length, 1, `${changes}: one unverified-step card`);
+ assert.equal(waits[0], 'submit', `${changes}: the submit confirmation came after the card`);
+ const result = resultFor(messages, 'commit');
+ if (changes) {
+ assert.deepEqual(dispatched, [], 'the answer covered the text the user saw, not the changed editor');
+ assert.equal(result.noDispatch, true);
+ assert.match(result.error, /Commit submission is blocked/);
+ assert.equal(result.unverifiedStepConfirmation, undefined, 'no card can wait at dispatch time');
+ } else {
+ assert.deepEqual(dispatched.map(item => item.name), ['click_ax'], 'an unchanged editor still commits');
+ assert.equal(result.success, true);
+ }
+ }
+ });
+
test(`${build}: one answer covers one commit call; committing the same text again asks again`, async () => {
const { agent, tab, provider } = await githubFixture();
const { dispatched, cards, run } = pipeline(agent, provider, 'once');