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
Close a finished run's unanswered approval cards
Claude41134f43c35f
diff --git a/docs/native-chat-durable-resume.md b/docs/native-chat-durable-resume.mdindex 1c00cbc90..3161e388d 100644--- a/docs/native-chat-durable-resume.md+++ b/docs/native-chat-durable-resume.md@@ -8,7 +8,7 @@ Native Telegram sends and delivery acknowledgement require the verified latest vA same-task alarm can finish from that receipt only after reading the current native conversation again. The same message must still exist with the same authored body and peer, the composer must be empty, and no pending outbound message, OTP pause, unrelated current page action, or verification debt may remain. A provider, task, recipient, or page change during the read invalidates it. Internal terminal reads never consume incoming deltas: a newly arrived question blocks completion until the model explicitly observes it. The normal `done` bookkeeping step preserves its own freshly verified proof; a later tool invalidates that sequence. This does not add a fictional action to the resumed run's execution counter.-An unanswered permission or ordinary clarification is recovered from its live Agent entry when the panel reopens, even after replay acknowledgement. The descriptor remains bound to the current request, run, task, provider and steering revision; settled entries, Stop, replacement tasks and worker loss cannot revive it. Hydration rechecks current state, preserves the original deadline and never answers or renews the question. Accepted mid-run corrections wake obsolete permission waits without recording a grant or dispatching the earlier action, then continue through the normal steering boundary. The paired owned-fixture suites contain 54 hydration and 22 permission-steering checks; this is UI and control-flow proof, not native delivery or external-service endurance proof.+An unanswered permission or ordinary clarification is recovered from its live Agent entry when the panel reopens, even after replay acknowledgement. The descriptor remains bound to the current request, run, task, provider and steering revision; settled entries, Stop, replacement tasks and worker loss cannot revive it. When a run ends (finished, failed or stopped), the panel closes the cards it still showed: a permission card is removed and a question is locked, so a card left on screen after Stop can no longer be clicked; a scheduled task's cards stay with that task. Hydration rechecks current state, preserves the original deadline and never answers or renews the question. Accepted mid-run corrections wake obsolete permission waits without recording a grant or dispatching the earlier action, then continue through the normal steering boundary. The paired owned-fixture suites contain 54 hydration and 22 permission-steering checks; this is UI and control-flow proof, not native delivery or external-service endurance proof.The authenticated source22 native-panel reopen restored the same unanswered permission card, and a genuine public correction woke that wait without granting it; the old click returned no-dispatch. This phase passed, but the whole 300-second task failed after passive page updates discarded two arithmetic-only plain replies before any calculator call and led to a new unrelated permission prompt. A separate source22 first-main correction calculated the exact result, then discarded five plain replies and stopped as page-unstable. These failed runs remain separate from the successful card-restoration phase (`auth-telegram-source22-permission-steering-content-free-diagnosis.json` and the retained native reopen/first-main artifacts).diff --git a/package.json b/package.jsonindex ccb36325f..0ecbb4eda 100644--- a/package.json+++ b/package.json@@ -9,7 +9,7 @@"test:authenticated": "npm --prefix website-tests test","test:authenticated:installed": "npm --prefix website-tests run test:installed","test": "npm run test:failure-recovery && npm run test:shard:quick && npm run test:shard:runtime-unit && npm run test:shard:browser-a && npm run test:shard:browser-b1 && npm run test:shard:browser-b2 && npm run test:shard:browser-c && npm run test:shard:tail",- "test:failure-recovery": "node --test test/failure-recovery.mjs test/failure-recovery-ui.mjs test/post-submit-model-recovery.mjs test/run-ui-response-retry.mjs test/ask-stream-retry-ui.mjs test/page-monitor-relaxed-retry.mjs && npm run test:quality:relaxed-monitoring-retry",+ "test:failure-recovery": "node --test test/failure-recovery.mjs test/failure-recovery-ui.mjs test/clarify-run-end.mjs test/post-submit-model-recovery.mjs test/run-ui-response-retry.mjs test/ask-stream-retry-ui.mjs test/page-monitor-relaxed-retry.mjs && npm run test:quality:relaxed-monitoring-retry","test:quality:relaxed-monitoring-retry": "node test/quality/relaxed-monitoring-retry-mv3.mjs","test:captcha:ui": "node test/captcha-settings-ui.mjs && node test/captcha-application-ui.mjs && node --test test/captcha-draft-content.mjs test/captcha-challenge-surfaces.mjs","test:captcha:bridge:ui": "node test/captcha-callback-bridge-ui.mjs",diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.jsindex 1934eb53d..c4c7406f1 100644--- a/src/chrome/src/ui/sidepanel.js+++ b/src/chrome/src/ui/sidepanel.js@@ -6056,9 +6056,10 @@ function clarificationSubmissionKey(tabId, requestId, clarifyId) {return JSON.stringify([Number(tabId), String(requestId || ''), String(clarifyId || '')]);}-function invalidateUnresolvedClarifyCards(assistantEl, currentClarifyId = '') {+function invalidateUnresolvedClarifyCards(assistantEl, currentClarifyId = '', { keepScheduled = false } = {}) {for (const card of assistantEl?.querySelectorAll('.clarify-card') || []) {- if (card.classList.contains('clarify-answered') || String(card.dataset.clarifyId || '') === currentClarifyId) continue;+ if (card.classList.contains('clarify-answered') || String(card.dataset.clarifyId || '') === currentClarifyId+ || (keepScheduled && card.dataset.scheduledJobId)) continue;clearClarifyCountdown(card);if (card.dataset.permission === '1') card.remove();else {@@ -11355,6 +11356,10 @@ function handleAgentUpdateMessage(msg) {requestId: msg.requestId,runId: msg.runId,});+ // A finished run accepts no more answers: a card it still showed (the+ // permission card on screen when Stop was pressed, say) closes with it.+ // A scheduled task's cards belong to that task.+ invalidateUnresolvedClarifyCards(eventAssistantEl || currentAssistantEl, '', { keepScheduled: true });const suppressTimedOutPlanTerminal = !!(eventAssistantEl || currentAssistantEl)?.querySelector('.plan-review-expired')&& isPlanReviewTimeoutTerminal(data?.finalContent);diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.jsindex 258efabf6..cf9ca543f 100644--- a/src/firefox/src/ui/sidepanel.js+++ b/src/firefox/src/ui/sidepanel.js@@ -5898,9 +5898,10 @@ function clarificationSubmissionKey(tabId, requestId, clarifyId) {return JSON.stringify([Number(tabId), String(requestId || ''), String(clarifyId || '')]);}-function invalidateUnresolvedClarifyCards(assistantEl, currentClarifyId = '') {+function invalidateUnresolvedClarifyCards(assistantEl, currentClarifyId = '', { keepScheduled = false } = {}) {for (const card of assistantEl?.querySelectorAll('.clarify-card') || []) {- if (card.classList.contains('clarify-answered') || String(card.dataset.clarifyId || '') === currentClarifyId) continue;+ if (card.classList.contains('clarify-answered') || String(card.dataset.clarifyId || '') === currentClarifyId+ || (keepScheduled && card.dataset.scheduledJobId)) continue;clearClarifyCountdown(card);if (card.dataset.permission === '1') card.remove();else {@@ -10844,6 +10845,10 @@ function handleAgentUpdateMessage(msg) {data?.attachmentDeliveryState,);invalidatePlanReviewCards({ tabId: msg.tabId ?? currentTabId, requestId: msg.requestId, runId: msg.runId });+ // A finished run accepts no more answers: a card it still showed (the+ // permission card on screen when Stop was pressed, say) closes with it.+ // A scheduled task's cards belong to that task.+ invalidateUnresolvedClarifyCards(eventAssistantEl || currentAssistantEl, '', { keepScheduled: true });const suppressTimedOutPlanTerminal = !!(eventAssistantEl || currentAssistantEl)?.querySelector('.plan-review-expired')&& isPlanReviewTimeoutTerminal(data?.finalContent);diff --git a/test/ask-stream-retry-ui.mjs b/test/ask-stream-retry-ui.mjsindex ccd8c3a08..61eeb589e 100644--- a/test/ask-stream-retry-ui.mjs+++ b/test/ask-stream-retry-ui.mjs@@ -91,6 +91,7 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {'clearThinkingActivityTimers', 'setActivityText', 'showActivity', 'hideActivity','startThinkingActivity', 'renderAgentErrorUpdate', 'handleAgentUpdateMessage','roleFromMessageElement', 'normalizeHistoryText', 'extractChatHistoryMessages', 'formatMarkdown', 'isSuccessfulAskCompletion',+ 'invalidateUnresolvedClarifyCards',].map(name => extract(source, name)).join('\n');const hydration = extract(source, 'applyActiveRunState');const snapshotStart = hydration.indexOf(' let lastRenderedSeq =');diff --git a/test/clarify-run-end.mjs b/test/clarify-run-end.mjsnew file mode 100644index 000000000..bdc23ba55--- /dev/null+++ b/test/clarify-run-end.mjs@@ -0,0 +1,56 @@+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import { test } from 'node:test';+import { chromium, firefox } from 'playwright';++// A finished run accepts no more answers. A WebBrain card it still showed,+// such as the typing permission card on screen when the user pressed Stop+// (C2 trace), closes with the run instead of staying clickable.+for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {+ const panel = (await readFile(new URL(`../src/${build}/src/ui/sidepanel.js`, import.meta.url), 'utf8')).replace(/\r\n/g, '\n');+ const extract = name => {+ const start = panel.indexOf(`function ${name}(`);+ const end = panel.indexOf('\n}\n', start);+ assert.ok(start >= 0 && end > start, `missing ${name}`);+ return panel.slice(start, end + 2);+ };++ test(`${build}: a finished run closes the cards it still showed`, () => {+ const runComplete = panel.slice(panel.indexOf(" case 'run_complete':"), panel.indexOf(" case 'clarify':"));+ assert.match(runComplete, /invalidateUnresolvedClarifyCards\(eventAssistantEl \|\| currentAssistantEl, '', \{ keepScheduled: true \}\);/);+ });++ test(`${build}: closing a run's cards removes its permission cards and keeps a scheduled task's`, async () => {+ const browser = await engine.launch({ headless: true });+ try {+ const page = await browser.newPage();+ await page.setContent(`<div class="message assistant"><div class="message-content">+ <div class="clarify-card" data-clarify-id="perm-typing" data-permission="1"><button>Allow once</button><button>Deny</button></div>+ <div class="clarify-card" data-clarify-id="question"><input class="clarify-input"><button>Send</button></div>+ <div class="clarify-card clarify-answered" data-clarify-id="answered"><button disabled>Done</button></div>+ <div class="clarify-card" data-clarify-id="scheduled-question" data-scheduled-job-id="job-1"><button>Reply</button></div>+ </div></div>`);+ const counts = await page.evaluate(source => {+ window.cleared = [];+ window.clearClarifyCountdown = card => cleared.push(card.dataset.clarifyId);+ window.eval(source);+ invalidateUnresolvedClarifyCards(document.querySelector('.message.assistant'), '', { keepScheduled: true });+ const card = id => document.querySelector(`[data-clarify-id="${id}"]`);+ return {+ permission: !!card('perm-typing'),+ question: { obsolete: card('question').classList.contains('clarify-obsolete'),+ disabled: [...card('question').querySelectorAll('button, input')].every(control => control.disabled) },+ answered: card('answered').classList.contains('clarify-obsolete'),+ scheduled: { obsolete: card('scheduled-question').classList.contains('clarify-obsolete'),+ enabled: !card('scheduled-question').querySelector('button').disabled },+ cleared,+ };+ }, extract('invalidateUnresolvedClarifyCards'));+ assert.equal(counts.permission, false, 'a permission card is transient and leaves with its run');+ assert.deepEqual(counts.question, { obsolete: true, disabled: true }, 'a question stays readable but locked');+ assert.equal(counts.answered, false, 'an answered card is untouched');+ assert.deepEqual(counts.scheduled, { obsolete: false, enabled: true }, 'a scheduled task waits for its own answer');+ assert.deepEqual(counts.cleared, ['perm-typing', 'question']);+ } finally { await browser.close(); }+ });+}diff --git a/test/failure-recovery-ui.mjs b/test/failure-recovery-ui.mjsindex 482807f2b..a63efe6d0 100644--- a/test/failure-recovery-ui.mjs+++ b/test/failure-recovery-ui.mjs@@ -101,6 +101,7 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {'clearAssistantTextStreamState', 'renderAssistantTextUpdate', 'isStoppedByUserStatus','handleAgentUpdateMessage', 'addMessageCopyButton', 'getMessageCopyText','roleFromMessageElement', 'normalizeHistoryText', 'extractChatHistoryMessages', 'formatMarkdown',+ 'invalidateUnresolvedClarifyCards',].map(name => extract(source, name)).join('\n');const send = extract(source, 'sendMessage');const responseStart = send.indexOf(' if (renderToCurrentTab && currentTabId === tabId && isTabAbortRequested(tabId))');