Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Require settled X message history
Emre Sokullu9238ac364780
diff --git a/docs/social-publication-contract.md b/docs/social-publication-contract.mdindex 18ce912e3..9284e5bce 100644--- a/docs/social-publication-contract.md+++ b/docs/social-publication-contract.md@@ -59,4 +59,6 @@ The config accepts the existing provider fields (`providerName`, `baseUrl`, `modCalls run sequentially. Reports distinguish first-response validity, repairs, semantic contract errors, audit false accepts/rejects, token usage, and median/p95 latency. First-call latency is reported separately without assuming a cold server. Default results are ignored local artifacts under `test/llm/results-social-publication/`, with a Markdown report, per-case JSONL, and prompt/fixture hashes. The runner never invokes a browser action or publishes a post.+For X direct messages, a mounted but empty log is treated as loading rather than as a proven first-message conversation. Dispatch and completion require a settled, nonempty conversation tail before a later matching sent row can be accepted.+X direct messages use their own message workflow, not the public publication contract. On `/i/chat/<conversation>`, the conversation header binds the recipient. An exact display-name or bare-username match resolves to that header's canonical handle during planning or before dispatch; subsequent verification requires the same handle, never a replacement account with the same display name. A send binds the exact body and the identities of all mounted message rows, including hidden and pending ones. An explicitly supplied body is required by the message-field classifier and is recovered from the approved task when a classifier response omits it, including route-local commands such as `Send Alex: Hello there`. Completion requires a new matching outgoing row after the prior conversation tail with `data-send-status="sent"`, an empty composer, and the same conversation. The open X chat composer does not override that delivery evidence; other adapters retain their dialog checks. Workflow field requirements are loaded even when repeated-item tracking is disabled. Incoming, pending, failed, or pre-existing messages cannot satisfy it.diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex fad5557ca..ca1c0acdf 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -5522,7 +5522,11 @@ export class Agent extends LoopDetector {? currentIds.indexOf(priorIds[priorIds.length - 1]) : -1;exactOutgoingBodyObserved = !!this._workflowMessageBody(binding.messageBody)&& Array.isArray(priorIds) && Array.isArray(currentIds) && Array.isArray(sentIds)- && (priorIds.length === 0 || anchorIndex >= 0)+ // The content-side guard records only a settled X log with a+ // concrete tail. Retain that invariant here as well so a malformed+ // or older binding cannot turn a late-loaded historic row into+ // evidence for this dispatch.+ && priorIds.length > 0 && anchorIndex >= 0&& sentIds.some(id => !priorIds.includes(id) && currentIds.indexOf(id) > anchorIndex);sentStatusObserved = exactOutgoingBodyObserved&& recipientObserveddiff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex 5b46760ff..dbc561971 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -5048,8 +5048,12 @@.filter(row => /^message-(?!text-)[a-zA-Z0-9_-]{1,128}$/.test(row.getAttribute('data-testid') || '')): [];const twitterMessageIds = twitterRows.map(row => row.getAttribute('data-testid'));- const twitterBaselineComplete = twitterLogs.length === 1 && twitterRows.length <= 2000- && new Set(twitterMessageIds).size === twitterMessageIds.length;+ // An empty mounted log can mean X is still loading older history. Do+ // not treat it as a proven first-message conversation: without a prior+ // tail, an old matching row that appears after dispatch is+ // indistinguishable from the message this run attempted to send.+ const twitterBaselineComplete = twitterLogs.length === 1 && twitterRows.length > 0+ && twitterRows.length <= 2000 && new Set(twitterMessageIds).size === twitterMessageIds.length;const matchingTwitterMessageIds = expectedBody => {const expected = normalizedMessageBody(expectedBody);if (!expected || !twitterBaselineComplete) return [];diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 8503f3fe6..06e1ba1e5 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -5240,7 +5240,11 @@ export class Agent extends LoopDetector {? currentIds.indexOf(priorIds[priorIds.length - 1]) : -1;exactOutgoingBodyObserved = !!this._workflowMessageBody(binding.messageBody)&& Array.isArray(priorIds) && Array.isArray(currentIds) && Array.isArray(sentIds)- && (priorIds.length === 0 || anchorIndex >= 0)+ // The content-side guard records only a settled X log with a+ // concrete tail. Retain that invariant here as well so a malformed+ // or older binding cannot turn a late-loaded historic row into+ // evidence for this dispatch.+ && priorIds.length > 0 && anchorIndex >= 0&& sentIds.some(id => !priorIds.includes(id) && currentIds.indexOf(id) > anchorIndex);sentStatusObserved = exactOutgoingBodyObserved&& recipientObserveddiff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.jsindex 52b15239d..7809d2a47 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -4220,8 +4220,12 @@.filter(row => /^message-(?!text-)[a-zA-Z0-9_-]{1,128}$/.test(row.getAttribute('data-testid') || '')): [];const twitterMessageIds = twitterRows.map(row => row.getAttribute('data-testid'));- const twitterBaselineComplete = twitterLogs.length === 1 && twitterRows.length <= 2000- && new Set(twitterMessageIds).size === twitterMessageIds.length;+ // An empty mounted log can mean X is still loading older history. Do+ // not treat it as a proven first-message conversation: without a prior+ // tail, an old matching row that appears after dispatch is+ // indistinguishable from the message this run attempted to send.+ const twitterBaselineComplete = twitterLogs.length === 1 && twitterRows.length > 0+ && twitterRows.length <= 2000 && new Set(twitterMessageIds).size === twitterMessageIds.length;const matchingTwitterMessageIds = expectedBody => {const expected = normalizedMessageBody(expectedBody);if (!expected || !twitterBaselineComplete) return [];diff --git a/test/run.js b/test/run.jsindex c7c2ab388..fd7d38b7c 100644--- a/test/run.js+++ b/test/run.js@@ -93935,7 +93935,7 @@ test('publication workflows classify and bind requested payload fields', async (messageRecipientDispatchBinding: { token: `x-body-${body}` },messageRecipientBody: body,messageRecipientBodyBaselineCount: 0,- messageRecipientExistingMessageIds: [],+ messageRecipientExistingMessageIds: ['message-prior'],});return agent._workflowTerminalEvidenceFromDone(xTabId, { liveRegionMessages: [] }, xUrl, {submit: { dispatched: true, observedAfterSubmit: true, originatingUrl: xUrl, workflowBinding },@@ -93946,7 +93946,7 @@ test('publication workflows classify and bind requested payload fields', async (conclusive: true,composerEmpty: true,strongRecipientCandidates: [{ identity: '@altryne', role: 'to' }],- existingMessageIds: ['message-new'],+ existingMessageIds: ['message-prior', 'message-new'],matchingOutgoingMessageIds: ['message-new'],matchingOutgoingMessageCount: 1,});@@ -93955,6 +93955,28 @@ test('publication workflows classify and bind requested payload fields', async (`${AgentClass.name}: a sent X DM drifted from the approved body`);assert.equal(xTerminal('Hello there')?.verificationKind, 'message_sent',`${AgentClass.name}: the approved X DM body could not complete`);+ const emptyBaselineBinding = agent._workflowSubmitBindingForAttempt(xTabId, xUrl, {+ messageRecipientGuardRequired: true,+ messageRecipientDispatchBinding: { token: 'x-empty-baseline' },+ messageRecipientBody: 'Hello there',+ messageRecipientBodyBaselineCount: 0,+ messageRecipientExistingMessageIds: [],+ });+ const lateHistoricRow = agent._workflowTerminalEvidenceFromDone(xTabId, { liveRegionMessages: [] }, xUrl, {+ submit: { dispatched: true, observedAfterSubmit: true, originatingUrl: xUrl, workflowBinding: emptyBaselineBinding },+ verifiedFinalSubmit: false,+ relevantForms: 1,+ }, {+ success: true,+ conclusive: true,+ composerEmpty: true,+ strongRecipientCandidates: [{ identity: '@altryne', role: 'to' }],+ existingMessageIds: ['message-late-history'],+ matchingOutgoingMessageIds: ['message-late-history'],+ matchingOutgoingMessageCount: 1,+ });+ assert.equal(lateHistoricRow, null,+ `${AgentClass.name}: a late-loaded historic X row satisfied an empty dispatch baseline`);}});