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
Keep response-only quota stops unsuccessful through replay
Barack Sokullu4a50b274e4c3
diff --git a/docs/compass-quota-rollout.md b/docs/compass-quota-rollout.mdindex f47e2aaa6..60c8daba5 100644--- a/docs/compass-quota-rollout.md+++ b/docs/compass-quota-rollout.md@@ -57,7 +57,7 @@ php scripts/report-social-promotion.php --days=14The report contains quota-card views, checkout opens, server-recorded claim submissions and successful grants, explicit continuation after a reward, provider switches, and subscription conversions. A conversion is counted once when a device that opened checkout is observed with a paid entitlement on `/usage`; checkout opens alone do not count as conversions. Client counts are capped per device/day and are event totals rather than unique-person counts.-Metered consumption is recorded under the same store lock from actual completed token usage, including visual sidecars. Numeric samples use hashed device/session identifiers and retain 30 UTC days; no prompt, post body, or page content is added to these samples. The 14-day report shows free-session and free-device/week p50/p75/p90/p95 costs and the share exceeding $0.375. Calls without a session identifier contribute to `unattributed_usd`, so report that coverage gap. The first/last device-week buckets can be partial if the report starts midweek; use two complete UTC weeks for the final comparison. Lifetime claims/indexes are not subject to sample retention.+Metered consumption is recorded under the same store lock from actual completed token usage, including visual sidecars. Numeric samples use hashed device/session identifiers and retain 30 UTC days; no prompt, post body, or page content is added to these samples. Each consumption map retains at most 10,000 observations across retained dates; existing samples continue accumulating, and new keys contribute to overflow totals. Exact metered aggregates remain intact. The report discloses observation counts and overflow USD/requests in `sampling`; inspect that coverage before using the sampled distributions to change the allowance. The 14-day report shows free-session and free-device/week p50/p75/p90/p95 costs and the share exceeding $0.375. Calls without a session identifier contribute to `unattributed_usd`, so report that coverage gap. The first/last device-week buckets can be partial if the report starts midweek; use two complete UTC weeks for the final comparison. Lifetime claims/indexes are not subject to sample retention.Reassess whether $0.375 covers useful completed sessions, how many device/weeks exhaust it, how often rewards lead to explicit continuation, how many users switch providers or subscribe, and how long pending reviews take. Use actual consumption distributions and recovery/conversion behavior to decide whether to keep or raise the allowance. Do not equate views or composer opens with published posts or successful tasks.diff --git a/docs/compass-quota-validation.md b/docs/compass-quota-validation.mdindex 9f0f17e00..e9b249791 100644--- a/docs/compass-quota-validation.md+++ b/docs/compass-quota-validation.md@@ -29,7 +29,7 @@ Browser fixtures simulate extension APIs and review/checkout results. They do no## Review fixes-All three review findings were addressed. Store writes now sync a temporary file on the same filesystem and atomically replace the JSON under a stable `USAGE_PATH.lock`; existing empty, whitespace-only, or invalid stores fail closed. Regression tests inject partial writes, sync/replace failures, and kill actual writer processes immediately before and after replacement. They verify restart behavior, preserved lifetime awards/indexes, and exactly one grant when a committed approval is retried.+The initial three review findings were addressed. Store writes now sync a temporary file on the same filesystem and atomically replace the JSON under a stable `USAGE_PATH.lock`; existing empty, whitespace-only, or invalid stores fail closed. Regression tests inject partial writes, sync/replace failures, and kill actual writer processes immediately before and after replacement. They verify restart behavior, preserved lifetime awards/indexes, and exactly one grant when a committed approval is retried.Metered usage now requires the billing tier resolved at admission, including streamed usage and visual sidecars. The paid-admission regression drops the billing table mid-request and verifies neither model nor visual usage debits promotional credit. UI submissions invalidate older refresh results/errors, including across a locale remount. Browser regressions verify pending state survives delayed draft responses, stale network errors, and a remount during submission; a failed submission after remount re-enables the form. Refreshes also retain keyboard focus and deliberately empty edited copy.@@ -37,14 +37,16 @@ Metered usage now requires the billing tier resolved at admission, including strOrdinary quota reads now use a shared read lock without creating lifetime claims or rewriting the store; metering and expiring client telemetry also avoid allocating claims. Sharing explicitly creates the opaque identifier. Regressions rotate device headers across 50 direct usage reads and 20 real HTTP usage/malformed-chat requests and verify unchanged store bytes. Paid and Plus no-op reads, repeated conversion observations, and expired checkout activity are checked using store bytes and modification times. Both promotion POST handlers use the existing bounded JSON parser; oversized bodies with and without Content-Length are rejected before claim allocation. No-op exclusive transactions do not replace the ledger.-Both browsers emit one recovery signal on response-only quota failure. Provider switching checks connection results, exceptions, and stale tests before reporting readiness. The rendered fixture server selects locales from a fixed allowlist, with malicious locale query regressions. The PDF browser test captures its Chrome tab ID at creation instead of rediscovering it by URL. GitHub CodeQL confirmed the fixture injection alert was fixed, and PDF/WebMCP CI passed after the first review fixes.+Both browsers emit one recovery signal on response-only quota failure. Quota updates also mark terminal journals, reconnect results, user-memory outcomes, badges, and Ask review prompts as unsuccessful; the conversation and single quota card remain available for explicit retry. Provider switching checks connection results, exceptions, and stale tests before reporting readiness. The rendered fixture server selects locales from a fixed allowlist, with malicious locale query regressions. The PDF browser test captures its Chrome tab ID at creation instead of rediscovering it by URL. GitHub CodeQL confirmed the fixture injection alert was fixed, and PDF/WebMCP CI passed after the first review fixes.-The full **npm test** passed, including **2,426 legacy tests** and **60 security checks**. Focused quota tests passed 19 cases, and the browser fixture passed 406 assertions across both engines and 23 locales. Both extension builds, payment notices, and real Chrome PDF/WebMCP tests passed; English and Arabic narrow-panel screenshots were inspected again.+The full **npm test** passed, including **2,429 legacy tests** and **60 security checks**. Focused quota tests passed 19 cases, and the browser fixture passed 406 assertions across both engines and 23 locales. Both extension builds, payment notices, and real Chrome PDF/WebMCP tests passed; English and Arabic narrow-panel screenshots were inspected again.The full cloud **composer check** and the real HTTP/review-CLI suite passed after the latest cloud fixes. Earlier validation blockers were resolved: shell fixtures use LF line endings, the default-model test uses an isolated root without a developer .env, the PII CLI recognizes absolute Windows lock paths, and stale provider/structured-error source assertions match the current behavior. The actual .env was untouched. Expected fault-case diagnostics remain in passing test logs.Further review regressions verify that the pending claim button fetches status in both browsers, concurrent rotating device headers cannot exceed the global telemetry cap, dropped events do not rewrite the ledger, and exact checkout timestamps outside 30 days cannot convert. Linux PHP durability tests verify file-then-directory sync and safe approval retry after an injected directory-sync failure. The Linux social test could not run because that PHP installation lacks PDO SQLite; the complete cloud check and social/concurrency suite passed with Windows PHP. Windows PHP cannot sync directory handles, so production power-loss durability requires a POSIX filesystem with directory fsync.+Concurrent rotating session and device identifiers are bounded to 10,000 retained observations per consumption map. Overflow contributes to exact metered aggregates and disclosed report totals, while existing samples keep accumulating and expiration frees capacity. Regression tests cover concurrent capacity, exact overflow totals, unchanged weekly accounting, and retention. The extension branch includes current main and its upstream social-platform changes; the complete suite passes after integration.+Fresh Codex reviews and GitHub checks are recorded on each PR.## Local artifacts and rolloutdiff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex 250efc900..b90c82c30 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -1950,7 +1950,7 @@ function isPersistenceDegradedRunUpdate(update) {function runUpdatesSucceeded(updates = []) {return !updates.some(update => (- update?.type === 'error'+ update?.type === 'error' || update?.type === 'quota'|| isClarificationRequiredRunUpdate(update)|| isPersistenceDegradedRunUpdate(update)|| isPlannerRequestFailureUpdate(update)@@ -1963,7 +1963,8 @@ function terminalRunUiStatus(content, updates = [], error = null) {if (/stopped by user|aborted by user/i.test(text)) return 'stopped';if (/before executing requested tool calls/i.test(text)) return 'cancelled';if (updates.some(update => update?.type === 'error'- || isPlannerRequestFailureUpdate(update) || isPersistenceDegradedRunUpdate(update))) return 'failed';+ || isPlannerRequestFailureUpdate(update) || isPersistenceDegradedRunUpdate(update)+ || update?.type === 'quota')) return 'failed';if (updates.some(isClarificationRequiredRunUpdate)) return 'clarification_required';return 'completed';}@@ -1987,7 +1988,7 @@ const BADGE_COST_ALLOWANCE_ERROR_RE = /Cloud cost allowance reached:\s*(this sesfunction askCompletionSucceededForBadge(result, updates = [], error = null) {if (error) return false;if (updates.some(update => (- update?.type === 'error'+ update?.type === 'error' || update?.type === 'quota'|| update?.type === 'attachment_rejected'|| update?.type === 'max_steps_reached'|| update?.errordiff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.jsindex 4f69de036..5cd8c2d11 100644--- a/src/chrome/src/ui/sidepanel.js+++ b/src/chrome/src/ui/sidepanel.js@@ -1940,7 +1940,7 @@ function updatesContainSuccessfulDone(updates) {function updatesContainStoreReviewFailure(updates) {return Array.isArray(updates) && updates.some((u) => (- u?.type === 'error' ||+ u?.type === 'error' || u?.type === 'quota' ||u?.type === 'attachment_rejected' ||u?.type === 'max_steps_reached' ||u?.error ||@@ -1950,7 +1950,7 @@ function updatesContainStoreReviewFailure(updates) {function isSuccessfulAskCompletion(mode, response) {if (mode !== 'ask') return false;- if (!response || response.success === false || response.ok === false) return false;+ if (!response || response.quota || response.success === false || response.ok === false) return false;if (updatesContainStoreReviewFailure(response.updates)) return false;const content = typeof response.content === 'string' ? response.content.trim() : '';return !!content && !parseSubscribeError(content) && !parseCostAllowanceError(content);diff --git a/src/firefox/src/background.js b/src/firefox/src/background.jsindex 8ea2d6c8c..d1fe74467 100644--- a/src/firefox/src/background.js+++ b/src/firefox/src/background.js@@ -2142,7 +2142,7 @@ function isPersistenceDegradedRunUpdate(update) {function runUpdatesSucceeded(updates = []) {return !updates.some(update => (- update?.type === 'error'+ update?.type === 'error' || update?.type === 'quota'|| isClarificationRequiredRunUpdate(update)|| isPersistenceDegradedRunUpdate(update)|| isPlannerRequestFailureUpdate(update)@@ -2155,7 +2155,8 @@ function terminalRunUiStatus(content, updates = [], error = null) {if (/stopped by user|aborted by user/i.test(text)) return 'stopped';if (/before executing requested tool calls/i.test(text)) return 'cancelled';if (updates.some(update => update?.type === 'error'- || isPlannerRequestFailureUpdate(update) || isPersistenceDegradedRunUpdate(update))) return 'failed';+ || isPlannerRequestFailureUpdate(update) || isPersistenceDegradedRunUpdate(update)+ || update?.type === 'quota')) return 'failed';if (updates.some(isClarificationRequiredRunUpdate)) return 'clarification_required';return 'completed';}@@ -2179,7 +2180,7 @@ const BADGE_COST_ALLOWANCE_ERROR_RE = /Cloud cost allowance reached:\s*(this sesfunction askCompletionSucceededForBadge(result, updates = [], error = null) {if (error) return false;if (updates.some(update => (- update?.type === 'error'+ update?.type === 'error' || update?.type === 'quota'|| update?.type === 'attachment_rejected'|| update?.type === 'max_steps_reached'|| update?.errordiff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.jsindex ae1ae14dc..44a4a5ff6 100644--- a/src/firefox/src/ui/sidepanel.js+++ b/src/firefox/src/ui/sidepanel.js@@ -1642,7 +1642,7 @@ function updatesContainSuccessfulDone(updates) {function updatesContainStoreReviewFailure(updates) {return Array.isArray(updates) && updates.some((u) => (- u?.type === 'error' ||+ u?.type === 'error' || u?.type === 'quota' ||u?.type === 'attachment_rejected' ||u?.type === 'max_steps_reached' ||u?.error ||@@ -1652,7 +1652,7 @@ function updatesContainStoreReviewFailure(updates) {function isSuccessfulAskCompletion(mode, response) {if (mode !== 'ask') return false;- if (!response || response.success === false || response.ok === false) return false;+ if (!response || response.quota || response.success === false || response.ok === false) return false;if (updatesContainStoreReviewFailure(response.updates)) return false;const content = typeof response.content === 'string' ? response.content.trim() : '';return !!content && !parseSubscribeError(content) && !parseCostAllowanceError(content);diff --git a/test/compass-quota.mjs b/test/compass-quota.mjsindex e8dc5ca7a..217019ae7 100644--- a/test/compass-quota.mjs+++ b/test/compass-quota.mjs@@ -114,6 +114,27 @@ for (const browser of ['chrome', 'firefox']) {assert.equal(events.filter(e => e.type === 'error').length, 0);assert.equal(messages[0].content, 'Keep this question');assert.equal(messages.at(-1).content, result.content);+ const background = fs.readFileSync(new URL('background.js', base), 'utf8');+ const classifiers = background.slice(background.indexOf('function isClarificationRequiredRunUpdate('), background.indexOf('async function getRunUiSnapshot('));+ const { terminalRunUiStatus, runUpdatesSucceeded, askCompletionSucceededForBadge } = vm.runInNewContext(`${classifiers}; ({ terminalRunUiStatus, runUpdatesSucceeded, askCompletionSucceededForBadge })`);+ assert.equal(terminalRunUiStatus('Localized quota stop', events), 'failed');+ assert.equal(runUpdatesSucceeded(events), false, 'user memory must see the stopped turn as unsuccessful');+ assert.equal(askCompletionSucceededForBadge('Localized quota stop', events), false);+ const journal = new RunUiJournal(); journal.begin(41, 'response-only-quota');+ for (const event of events) journal.record(41, 'response-only-quota', event.type, event.data);+ const snapshot = journal.finish(41, 'response-only-quota', terminalRunUiStatus(result.content, events), result.content);+ const reconnected = await runDetachedWithReconnect({ initialAction: 'chat_start', payload: { requestId: 'response-only-quota' },+ start: async () => ({ accepted: true, requestId: 'response-only-quota' }),+ probe: async () => ({ submittedTurnDurable: true, runUi: snapshot }), wait: async () => {}, pollIntervalMs: 0 });+ assert.equal(reconnected.success, false);+ assert.equal(reconnected.quota.code, payload.error.code);+ assert.equal(reconnected.updates.filter(e => e.type === 'error').length, 0, 'failed classification must preserve a single quota card');+ const panel = fs.readFileSync(new URL('ui/sidepanel.js', base), 'utf8');+ const askEnd = panel.indexOf('\n}\n', panel.indexOf('function isSuccessfulAskCompletion(')) + 3;+ const askClassifiers = panel.slice(panel.indexOf('function updatesContainStoreReviewFailure('), askEnd);+ const isSuccessfulAskCompletion = vm.runInNewContext(`${askClassifiers}; isSuccessfulAskCompletion`, { parseSubscribeError: () => null, parseCostAllowanceError: () => null });+ assert.equal(isSuccessfulAskCompletion('ask', { content: 'Localized quota stop', updates: events }), false);+ assert.equal(isSuccessfulAskCompletion('ask', { content: 'Localized quota stop', quota: error.quota, updates: [] }), false);agent._generateContextOnlyResponse = async () => { throw new Error('Other failure'); };events.length = 0;await agent._completeResponseOnlyTurn(41, messages, (type, data) => events.push({ type, data }));