Skip to content

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

fix(agent): multi-line commit messages via summary plus body

Emre Sokullu9c4682256ba8
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index b835f8cab..d888f6935 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -1756,28 +1756,49 @@ export class Agent extends LoopDetector {
const expectedCommitMessage = commitMessageRequirement
? String(commitMessageRequirement.rawValue ?? commitMessageRequirement.value ?? '')
: '';
- // Collision-resistant comparison: replacement records already carry a
- // SHA-256 digest, so require it here too. A 32-bit FNV-1a fingerprint
- // collides practically (e.g. 'PSgOcTcQ' vs '9SHghNQJ'), which would set
- // commitMessageVerified for the wrong message while the raw-file check
- // still reports full success. The sync helper matches _sha256Text; the
- // gate itself stays synchronous.
- const expectedCommitMessageSha256 = commitMessageRequirement
- ? this._sha256TextSync(expectedCommitMessage)
+ // GitHub composes the commit as summary + "\n\n" + extended description
+ // across two dialog fields, so a multi-line request needs both parts
+ // proven exactly: the summary on a single-line (non-textarea) commit
+ // field and the body on the textarea description field. Tag roles keep
+ // swapped fields from authorizing. Single-line requests behave exactly
+ // as before (summary proof); multi-line requests without a blank
+ // separator cannot be composed exactly and stay shut, as does anything
+ // whose parts are missing. Comparisons are collision-resistant SHA-256
+ // (a 32-bit FNV-1a fingerprint collides practically); the sync helper
+ // matches _sha256Text and the gate stays synchronous.
+ const messageSplit = expectedCommitMessage.indexOf('\n');
+ const messageRest = messageSplit < 0 ? '' : expectedCommitMessage.slice(messageSplit + 1);
+ const expectedSummary = messageSplit < 0 ? expectedCommitMessage : expectedCommitMessage.slice(0, messageSplit);
+ const expectedBody = messageRest.startsWith('\n') ? messageRest.slice(1).replace(/\n+$/, '') : '';
+ const composableMessage = messageSplit < 0 || messageRest === '' || messageRest.startsWith('\n');
+ const expectedSummarySha256 = commitMessageRequirement
+ ? this._sha256TextSync(expectedSummary)
: '';
+ const expectedBodySha256 = composableMessage && expectedBody
+ ? this._sha256TextSync(expectedBody)
+ : '';
+ const commitFieldRecords = replacementRecordValues.filter(record => (
+ record?.ambiguous !== true
+ && activeTaskTokenValid
+ && record?.taskToken === activeTaskToken
+ && !!record?.readbackSha256
+ && this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)
+ && /^(?:commit-message-input|commit_message)$/i.test(String(
+ record?.fieldMeta?.id || record?.fieldMeta?.name || '',
+ ))
+ ));
+ const summaryVerified = !!expectedSummarySha256 && commitFieldRecords.some(record => (
+ String(record?.fieldMeta?.tag || '').toLowerCase() !== 'textarea'
+ && record.expectedLength === expectedSummary.length
+ && record.expectedSha256 === expectedSummarySha256
+ ));
+ const bodyVerified = !expectedBody || (!!expectedBodySha256 && commitFieldRecords.some(record => (
+ String(record?.fieldMeta?.tag || '').toLowerCase() === 'textarea'
+ && record.expectedLength === expectedBody.length
+ && record.expectedSha256 === expectedBodySha256
+ )));
const commitMessageVerified = !commitMessageRequirement
- || (!!expectedCommitMessageSha256 && replacementRecordValues.some(record => (
- record?.ambiguous !== true
- && activeTaskTokenValid
- && record?.taskToken === activeTaskToken
- && !!record?.readbackSha256
- && this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)
- && /^(?:commit-message-input|commit_message)$/i.test(String(
- record?.fieldMeta?.id || record?.fieldMeta?.name || '',
- ))
- && record.expectedLength === expectedCommitMessage.length
- && record.expectedSha256 === expectedCommitMessageSha256
- )));
+ || (composableMessage && summaryVerified && bodyVerified);
const githubFileCommit = !metadataIncomplete
&& githubEditScope
&& verifiedReplacement
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 8a61ebaf8..c6be6d21d 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -1470,28 +1470,49 @@ export class Agent extends LoopDetector {
const expectedCommitMessage = commitMessageRequirement
? String(commitMessageRequirement.rawValue ?? commitMessageRequirement.value ?? '')
: '';
- // Collision-resistant comparison: replacement records already carry a
- // SHA-256 digest, so require it here too. A 32-bit FNV-1a fingerprint
- // collides practically (e.g. 'PSgOcTcQ' vs '9SHghNQJ'), which would set
- // commitMessageVerified for the wrong message while the raw-file check
- // still reports full success. The sync helper matches _sha256Text; the
- // gate itself stays synchronous.
- const expectedCommitMessageSha256 = commitMessageRequirement
- ? this._sha256TextSync(expectedCommitMessage)
+ // GitHub composes the commit as summary + "\n\n" + extended description
+ // across two dialog fields, so a multi-line request needs both parts
+ // proven exactly: the summary on a single-line (non-textarea) commit
+ // field and the body on the textarea description field. Tag roles keep
+ // swapped fields from authorizing. Single-line requests behave exactly
+ // as before (summary proof); multi-line requests without a blank
+ // separator cannot be composed exactly and stay shut, as does anything
+ // whose parts are missing. Comparisons are collision-resistant SHA-256
+ // (a 32-bit FNV-1a fingerprint collides practically); the sync helper
+ // matches _sha256Text and the gate stays synchronous.
+ const messageSplit = expectedCommitMessage.indexOf('\n');
+ const messageRest = messageSplit < 0 ? '' : expectedCommitMessage.slice(messageSplit + 1);
+ const expectedSummary = messageSplit < 0 ? expectedCommitMessage : expectedCommitMessage.slice(0, messageSplit);
+ const expectedBody = messageRest.startsWith('\n') ? messageRest.slice(1).replace(/\n+$/, '') : '';
+ const composableMessage = messageSplit < 0 || messageRest === '' || messageRest.startsWith('\n');
+ const expectedSummarySha256 = commitMessageRequirement
+ ? this._sha256TextSync(expectedSummary)
: '';
+ const expectedBodySha256 = composableMessage && expectedBody
+ ? this._sha256TextSync(expectedBody)
+ : '';
+ const commitFieldRecords = replacementRecordValues.filter(record => (
+ record?.ambiguous !== true
+ && activeTaskTokenValid
+ && record?.taskToken === activeTaskToken
+ && !!record?.readbackSha256
+ && this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)
+ && /^(?:commit-message-input|commit_message)$/i.test(String(
+ record?.fieldMeta?.id || record?.fieldMeta?.name || '',
+ ))
+ ));
+ const summaryVerified = !!expectedSummarySha256 && commitFieldRecords.some(record => (
+ String(record?.fieldMeta?.tag || '').toLowerCase() !== 'textarea'
+ && record.expectedLength === expectedSummary.length
+ && record.expectedSha256 === expectedSummarySha256
+ ));
+ const bodyVerified = !expectedBody || (!!expectedBodySha256 && commitFieldRecords.some(record => (
+ String(record?.fieldMeta?.tag || '').toLowerCase() === 'textarea'
+ && record.expectedLength === expectedBody.length
+ && record.expectedSha256 === expectedBodySha256
+ )));
const commitMessageVerified = !commitMessageRequirement
- || (!!expectedCommitMessageSha256 && replacementRecordValues.some(record => (
- record?.ambiguous !== true
- && activeTaskTokenValid
- && record?.taskToken === activeTaskToken
- && !!record?.readbackSha256
- && this._normalizeUrl(record.pageUrl || '') === this._normalizeUrl(pageUrl)
- && /^(?:commit-message-input|commit_message)$/i.test(String(
- record?.fieldMeta?.id || record?.fieldMeta?.name || '',
- ))
- && record.expectedLength === expectedCommitMessage.length
- && record.expectedSha256 === expectedCommitMessageSha256
- )));
+ || (composableMessage && summaryVerified && bodyVerified);
const githubFileCommit = !metadataIncomplete
&& githubEditScope
&& verifiedReplacement
diff --git a/test/run.js b/test/run.js
index b74dc6f7c..bb37018f5 100644
--- a/test/run.js
+++ b/test/run.js
@@ -75878,6 +75878,81 @@ test('commit gate hashes the verbatim message text', async () => {
}
});
+test('multi-line commit messages bind summary plus description', async () => {
+ for (const [label, AgentClass, resolveJob, tabId] of [
+ ['chrome', AgentCh, resolveAdapterWorkflowJob, 9542],
+ ['firefox', AgentFx, resolveAdapterWorkflowJobFx, 9543],
+ ]) {
+ const agent = new AgentClass({});
+ const pageUrl = 'https://github.com/Example/Repo/edit/main/docs/plan.md';
+ agent._planExecutionGuards.set(tabId, {
+ enabled: true,
+ siteWorkflow: resolveJob(pageUrl, 'edit-file-and-commit'),
+ workflowMetadataRequirements: [{ field: 'commit_message', value: 'Title\n\nDetails' }],
+ workflowMetadataRequirementsResolved: true,
+ });
+ agent._taskTokens.set(tabId, 'task-multiline');
+ const editorBody = '# Doc\n';
+ const editorRecord = {
+ key: 'ax:doc:ref_editor',
+ locatorType: 'ax',
+ refId: 'ref_editor',
+ documentToken: 'doc',
+ pageUrl,
+ ambiguous: false,
+ expectedLength: editorBody.length,
+ expectedSha256: await agent._sha256Text(editorBody),
+ expectedFp: agent._workflowInventoryFingerprint(editorBody),
+ fieldMeta: { contentEditable: true, ariaLabelledByText: 'Editing file contents' },
+ readbackLength: editorBody.length,
+ readbackSha256: await agent._sha256Text(editorBody),
+ verifiedAt: Date.now(),
+ taskToken: 'task-multiline',
+ };
+ const messageRecordFor = async (key, text, fieldMeta) => ({
+ key,
+ locatorType: 'ax',
+ refId: 'ref_msg',
+ documentToken: 'doc',
+ pageUrl,
+ ambiguous: false,
+ expectedLength: text.length,
+ expectedSha256: await agent._sha256Text(text),
+ expectedFp: agent._workflowInventoryFingerprint(text),
+ fieldMeta,
+ readbackLength: text.length,
+ readbackSha256: await agent._sha256Text(text),
+ verifiedAt: Date.now(),
+ taskToken: 'task-multiline',
+ });
+ const summaryMeta = { tag: 'input', id: 'commit-message-input' };
+ const descriptionMeta = { tag: 'textarea', name: 'commit_message' };
+ // Summary plus description proofs authorize the composed message.
+ agent._verifiedTextReplacements.set(tabId, new Map([
+ ['ax:doc:ref_editor', editorRecord],
+ ['ax:doc:ref_summary', await messageRecordFor('ax:doc:ref_summary', 'Title', summaryMeta)],
+ ['ax:doc:ref_desc', await messageRecordFor('ax:doc:ref_desc', 'Details', descriptionMeta)],
+ ]));
+ assert.ok(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit,
+ `${label}: split summary/body proofs did not authorize`);
+ // Swapped roles must not: the composed bytes would differ.
+ agent._verifiedTextReplacements.set(tabId, new Map([
+ ['ax:doc:ref_editor', editorRecord],
+ ['ax:doc:ref_summary', await messageRecordFor('ax:doc:ref_summary', 'Details', summaryMeta)],
+ ['ax:doc:ref_desc', await messageRecordFor('ax:doc:ref_desc', 'Title', descriptionMeta)],
+ ]));
+ assert.equal(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit, undefined,
+ `${label}: swapped summary/body authorized a different message`);
+ // Summary alone is not the whole message.
+ agent._verifiedTextReplacements.set(tabId, new Map([
+ ['ax:doc:ref_editor', editorRecord],
+ ['ax:doc:ref_summary', await messageRecordFor('ax:doc:ref_summary', 'Title', summaryMeta)],
+ ]));
+ assert.equal(agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {})?.githubFileCommit, undefined,
+ `${label}: summary alone authorized a multi-line message`);
+ }
+});
+
test('terminal path match compares verbatim request text', async () => {
for (const [label, AgentClass, tabId] of [
['chrome', AgentCh, 9516],