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
fix(chat): unwedge the support-chat workflow after a failed or proven-undelivered send
Codex release-state test8a3366fc4646
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex a39a482a7..78a06f1ad 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -44,7 +44,7 @@ import {workflowRequiredRowsAreProcessed,} from './adapter-workflow-evidence.js';import { answerNamesAllObservedRecipients, answerNamesIdentity, messageTargetMatchesObservedIdentities, normalizeMessageTarget, normalizeRecipientAnswer, normalizeRecipientIdentity, resolveClarifiedRecipients } from './message-recipient-guard.js';-import { advanceChatSession, createChatSession, decideChatSend, markChatSendPending, normalizeChatSession, serializeChatSession } from './chat-workflow.js';+import { advanceChatSession, createChatSession, decideChatSend, markChatSendPending, normalizeChatSession, normalizeChatSnapshot, serializeChatSession } from './chat-workflow.js';import {fetchUrl,executeHttpSkillTool,@@ -17735,6 +17735,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dasync _observeChatWorkflow(tabId, args = {}) {const observation = await this._readChatObservation(tabId);if (observation?.success !== true) return observation;+ // chat_observe reports the normalized threadKey, so a key the model passes+ // back must be compared against that same form β not against the raw+ // content-script value, which normalization can still change.+ const observedThreadKey = normalizeChatSnapshot(observation).threadKey;let prior = this.chatSessions.get(tabId) || createChatSession();const rebindThreadKey = String(args.rebind_thread_key || args.rebindThreadKey || '').trim();const reconcilePending = args.reconcile_pending_outbound === true;@@ -17769,7 +17773,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout derror: 'Chat thread rebind requires a prior thread_changed pause with no pending outbound send.',};}- if (rebindThreadKey !== observation.threadKey) {+ if (!observedThreadKey || rebindThreadKey !== observedThreadKey) {return {success: false,noDispatch: true,@@ -17777,7 +17781,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout derror: 'Chat thread rebind was rejected because the requested key does not match the current observation.',};}- prior = createChatSession({ threadKey: observation.threadKey });+ prior = createChatSession({ threadKey: observedThreadKey });}const advanced = advanceChatSession(prior, observation);this.chatSessions.set(tabId, advanced.session);@@ -17804,7 +17808,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis.chatSessions.set(tabId, observed.session);this._persist(tabId);const requestedThreadKey = String(args.thread_key || args.threadKey || '');- if (!requestedThreadKey || requestedThreadKey !== before.threadKey) {+ // chat_observe reported the normalized key, so match against that one.+ const observedThreadKey = observed.snapshot.threadKey;+ if (!requestedThreadKey || !observedThreadKey || requestedThreadKey !== observedThreadKey) {return {success: false,noDispatch: true,@@ -17879,19 +17885,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis.chatSessions.set(tabId, pending);const pendingPersisted = await this._persistNow(tabId);if (pendingPersisted !== true && pendingPersisted?.ok !== true) {+ // Nothing was dispatched, so this pending record is provably false.+ // Leaving it in place would refuse every later send with 'send_pending'+ // until the user confirms an uncertain outcome that never happened.+ this.chatSessions.set(tabId, observed.session);return {success: false,noDispatch: true,dispatched: false,reason: 'chat_state_not_durable',error: 'Chat send blocked because the pending outbound message could not be persisted safely. Retry after storage is available.',- chatWorkflow: this._chatWorkflowView({- session: pending,- snapshot: before,- events: [],- newMessages: [],- nextAction: 'observe',- }),+ chatWorkflow: workflow(),};}let dispatch;@@ -17905,13 +17909,27 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout derror: error?.message || String(error),};}+ // A dispatch that proves it never reached the page is not an uncertain+ // send: keeping the pending record would strand the workflow behind an+ // explicit user reconciliation for a message that was never typed.+ let dispatchedSession = pending;+ if (dispatch?.noDispatch === true && dispatch?.dispatched !== true) {+ dispatchedSession = { ...pending, pendingOutbound: null };+ this.chatSessions.set(tabId, dispatchedSession);+ this._persist(tabId);+ }const after = await this._readChatObservation(tabId);if (after?.success !== true) {return {...this._chatObservationResult(after, {- session: pending,- snapshot: after,+ session: dispatchedSession,+ // `after` failed, so it carries no thread binding or evidence. Report+ // the session's own so the model can still reconcile this send.+ snapshot: {+ threadKey: dispatchedSession.threadKey,+ resolutionEvidence: dispatchedSession.resolutionEvidence,+ },events: [],newMessages: [],nextAction: 'observe',@@ -17926,7 +17944,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout ddispatch,};}- const verifiedState = advanceChatSession(pending, after);+ const verifiedState = advanceChatSession(dispatchedSession, after);this.chatSessions.set(tabId, verifiedState.session);this._persist(tabId);const previouslySeenIds = new Set(observed.session.seenMessageIds);@@ -17948,7 +17966,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}),messageKey: decision.messageKey,dispatch,- chatWorkflow: this._chatWorkflowView(verifiedState),};}diff --git a/src/chrome/src/agent/chat-workflow.js b/src/chrome/src/agent/chat-workflow.jsindex ac91aac8f..74476fbdd 100644--- a/src/chrome/src/agent/chat-workflow.js+++ b/src/chrome/src/agent/chat-workflow.js@@ -336,7 +336,15 @@ export function advanceChatSession(value, rawSnapshot, now = Date.now()) {if (snapshot.userInput?.required) {events.push({ type: 'user_input_required', ...snapshot.userInput });} else {- if (session.state === 'needs_user_input' && session.stopReason !== 'thread_changed') {+ // A thread_changed pause is only lifted by evidence that the bound thread+ // is active again β either an explicit rebind (which starts a fresh+ // session) or an observation of the same threadKey. Without the second+ // case the pause is escaped implicitly by the next state transition while+ // stopReason stays 'thread_changed' forever, which would keep the rebind+ // precondition permanently satisfied.+ const boundThreadObserved = !!session.threadKey && session.threadKey === snapshot.threadKey;+ if (session.state === 'needs_user_input'+ && (session.stopReason !== 'thread_changed' || boundThreadObserved)) {events.push({ type: 'user_input_cleared', resumeState: session.pausedState });}if (evidenceComplete(snapshot.resolutionEvidence)) {diff --git a/src/chrome/src/content/chat-observation.js b/src/chrome/src/content/chat-observation.jsindex db5c74048..6268aa714 100644--- a/src/chrome/src/content/chat-observation.js+++ b/src/chrome/src/content/chat-observation.js@@ -266,9 +266,16 @@const selected = [];for (const candidate of candidates) {const duplicate = selected.find(item => {- if (item.id && candidate.id) return item.id === candidate.id;+ if (item.id && candidate.id && item.id === candidate.id) return true;+ // A wrapper and the bubble inside it are one message, even when the+ // page gives each of them its own id: innerText of the ancestor+ // already repeats the descendant's text, so keeping both reports the+ // same message twice. Only DOM containment collapses entries; sibling+ // bubbles with identical text stay separate and are numbered instead.+ if (!contains(item.node, candidate.node) && !contains(candidate.node, item.node)) return false;return item.text === candidate.text- && (contains(item.node, candidate.node) || contains(candidate.node, item.node));+ || item.text.includes(candidate.text)+ || candidate.text.includes(item.text);});if (!duplicate) {selected.push(candidate);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex bd191d726..70bf55263 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -43,7 +43,7 @@ import {workflowRequiredRowsAreProcessed,} from './adapter-workflow-evidence.js';import { answerNamesAllObservedRecipients, answerNamesIdentity, messageTargetMatchesObservedIdentities, normalizeMessageTarget, normalizeRecipientAnswer, normalizeRecipientIdentity, resolveClarifiedRecipients } from './message-recipient-guard.js';-import { advanceChatSession, createChatSession, decideChatSend, markChatSendPending, normalizeChatSession, serializeChatSession } from './chat-workflow.js';+import { advanceChatSession, createChatSession, decideChatSend, markChatSendPending, normalizeChatSession, normalizeChatSnapshot, serializeChatSession } from './chat-workflow.js';import {fetchUrl,executeHttpSkillTool,@@ -15484,6 +15484,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dasync _observeChatWorkflow(tabId, args = {}) {const observation = await this._readChatObservation(tabId);if (observation?.success !== true) return observation;+ // chat_observe reports the normalized threadKey, so a key the model passes+ // back must be compared against that same form β not against the raw+ // content-script value, which normalization can still change.+ const observedThreadKey = normalizeChatSnapshot(observation).threadKey;let prior = this.chatSessions.get(tabId) || createChatSession();const rebindThreadKey = String(args.rebind_thread_key || args.rebindThreadKey || '').trim();const reconcilePending = args.reconcile_pending_outbound === true;@@ -15518,7 +15522,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout derror: 'Chat thread rebind requires a prior thread_changed pause with no pending outbound send.',};}- if (rebindThreadKey !== observation.threadKey) {+ if (!observedThreadKey || rebindThreadKey !== observedThreadKey) {return {success: false,noDispatch: true,@@ -15526,7 +15530,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout derror: 'Chat thread rebind was rejected because the requested key does not match the current observation.',};}- prior = createChatSession({ threadKey: observation.threadKey });+ prior = createChatSession({ threadKey: observedThreadKey });}const advanced = advanceChatSession(prior, observation);this.chatSessions.set(tabId, advanced.session);@@ -15553,7 +15557,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis.chatSessions.set(tabId, observed.session);this._persist(tabId);const requestedThreadKey = String(args.thread_key || args.threadKey || '');- if (!requestedThreadKey || requestedThreadKey !== before.threadKey) {+ // chat_observe reported the normalized key, so match against that one.+ const observedThreadKey = observed.snapshot.threadKey;+ if (!requestedThreadKey || !observedThreadKey || requestedThreadKey !== observedThreadKey) {return {success: false,noDispatch: true,@@ -15628,19 +15634,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis.chatSessions.set(tabId, pending);const pendingPersisted = await this._persistNow(tabId);if (pendingPersisted !== true && pendingPersisted?.ok !== true) {+ // Nothing was dispatched, so this pending record is provably false.+ // Leaving it in place would refuse every later send with 'send_pending'+ // until the user confirms an uncertain outcome that never happened.+ this.chatSessions.set(tabId, observed.session);return {success: false,noDispatch: true,dispatched: false,reason: 'chat_state_not_durable',error: 'Chat send blocked because the pending outbound message could not be persisted safely. Retry after storage is available.',- chatWorkflow: this._chatWorkflowView({- session: pending,- snapshot: before,- events: [],- newMessages: [],- nextAction: 'observe',- }),+ chatWorkflow: workflow(),};}let dispatch;@@ -15654,13 +15658,27 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout derror: error?.message || String(error),};}+ // A dispatch that proves it never reached the page is not an uncertain+ // send: keeping the pending record would strand the workflow behind an+ // explicit user reconciliation for a message that was never typed.+ let dispatchedSession = pending;+ if (dispatch?.noDispatch === true && dispatch?.dispatched !== true) {+ dispatchedSession = { ...pending, pendingOutbound: null };+ this.chatSessions.set(tabId, dispatchedSession);+ this._persist(tabId);+ }const after = await this._readChatObservation(tabId);if (after?.success !== true) {return {...this._chatObservationResult(after, {- session: pending,- snapshot: after,+ session: dispatchedSession,+ // `after` failed, so it carries no thread binding or evidence. Report+ // the session's own so the model can still reconcile this send.+ snapshot: {+ threadKey: dispatchedSession.threadKey,+ resolutionEvidence: dispatchedSession.resolutionEvidence,+ },events: [],newMessages: [],nextAction: 'observe',@@ -15675,7 +15693,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout ddispatch,};}- const verifiedState = advanceChatSession(pending, after);+ const verifiedState = advanceChatSession(dispatchedSession, after);this.chatSessions.set(tabId, verifiedState.session);this._persist(tabId);const previouslySeenIds = new Set(observed.session.seenMessageIds);@@ -15697,7 +15715,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}),messageKey: decision.messageKey,dispatch,- chatWorkflow: this._chatWorkflowView(verifiedState),};}diff --git a/src/firefox/src/agent/chat-workflow.js b/src/firefox/src/agent/chat-workflow.jsindex ac91aac8f..74476fbdd 100644--- a/src/firefox/src/agent/chat-workflow.js+++ b/src/firefox/src/agent/chat-workflow.js@@ -336,7 +336,15 @@ export function advanceChatSession(value, rawSnapshot, now = Date.now()) {if (snapshot.userInput?.required) {events.push({ type: 'user_input_required', ...snapshot.userInput });} else {- if (session.state === 'needs_user_input' && session.stopReason !== 'thread_changed') {+ // A thread_changed pause is only lifted by evidence that the bound thread+ // is active again β either an explicit rebind (which starts a fresh+ // session) or an observation of the same threadKey. Without the second+ // case the pause is escaped implicitly by the next state transition while+ // stopReason stays 'thread_changed' forever, which would keep the rebind+ // precondition permanently satisfied.+ const boundThreadObserved = !!session.threadKey && session.threadKey === snapshot.threadKey;+ if (session.state === 'needs_user_input'+ && (session.stopReason !== 'thread_changed' || boundThreadObserved)) {events.push({ type: 'user_input_cleared', resumeState: session.pausedState });}if (evidenceComplete(snapshot.resolutionEvidence)) {diff --git a/src/firefox/src/content/chat-observation.js b/src/firefox/src/content/chat-observation.jsindex db5c74048..6268aa714 100644--- a/src/firefox/src/content/chat-observation.js+++ b/src/firefox/src/content/chat-observation.js@@ -266,9 +266,16 @@const selected = [];for (const candidate of candidates) {const duplicate = selected.find(item => {- if (item.id && candidate.id) return item.id === candidate.id;+ if (item.id && candidate.id && item.id === candidate.id) return true;+ // A wrapper and the bubble inside it are one message, even when the+ // page gives each of them its own id: innerText of the ancestor+ // already repeats the descendant's text, so keeping both reports the+ // same message twice. Only DOM containment collapses entries; sibling+ // bubbles with identical text stay separate and are numbered instead.+ if (!contains(item.node, candidate.node) && !contains(candidate.node, item.node)) return false;return item.text === candidate.text- && (contains(item.node, candidate.node) || contains(candidate.node, item.node));+ || item.text.includes(candidate.text)+ || candidate.text.includes(item.text);});if (!duplicate) {selected.push(candidate);