Skip to content

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

Tiny Ask screenshot gate: queue its trace note until the run starts

Claudea78898a2986f
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 9cc0d4e40..cf487ccf2 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -1094,6 +1094,9 @@ export class Agent extends LoopDetector {
this._screenshotCaptureCounter = 0;
this.pendingVisionRouteTraces = new Map();
this.pendingVisionStatusTraces = new Map();
+ // tiny Ask screenshot-gate notes: the gate runs during enrichment, before
+ // the trace run starts (flushed in _startTraceRun).
+ this.pendingTinyAskGateTraces = new Map();
this.pendingVisionSubCallTraces = new Map();
this.visionStatusNotices = new Map(); // tabId -> Set of route/status notices surfaced this run
this.carouselTraversalStates = new Map();
@@ -12118,13 +12121,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} catch (error) {
if (error?.name === 'AbortError' || this._checkAbort(tabId)) throw error;
}
+ const gateNote = {
+ probability: Number.isFinite(probability) ? Math.round(probability * 1000) / 1000 : null,
+ ms: Date.now() - started,
+ };
const runId = this.currentRunId.get(tabId);
- if (runId) {
- trace.recordNote(runId, null, 'tiny_ask_screenshot_gate', {
- probability: Number.isFinite(probability) ? Math.round(probability * 1000) / 1000 : null,
- ms: Date.now() - started,
- });
- }
+ if (runId) trace.recordNote(runId, null, 'tiny_ask_screenshot_gate', gateNote);
+ else this.pendingTinyAskGateTraces.set(tabId, gateNote);
if (!(probability >= TINY_ASK_SCREENSHOT_GATE_THRESHOLD)) return null;
onUpdate?.('thinking', { step: 0, note: 'Looking at the page…' });
try {
@@ -25396,6 +25399,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
this.pendingVisionRouteTraces.delete(tabId);
this.pendingVisionStatusTraces.delete(tabId);
this.pendingVisionSubCallTraces.delete(tabId);
+ this.pendingTinyAskGateTraces.delete(tabId);
return null;
}
if (runId) {
@@ -25422,6 +25426,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const pendingVisionSubCalls = this.pendingVisionSubCallTraces.get(tabId) || [];
this.pendingVisionSubCallTraces.delete(tabId);
for (const payload of pendingVisionSubCalls) trace.recordVisionSubCall(runId, payload);
+ const pendingGate = this.pendingTinyAskGateTraces.get(tabId);
+ this.pendingTinyAskGateTraces.delete(tabId);
+ if (pendingGate) trace.recordNote(runId, null, 'tiny_ask_screenshot_gate', pendingGate);
if (typeof runOptions?.onTraceStarted === 'function') {
try { runOptions.onTraceStarted(runId); } catch {}
}
@@ -25430,6 +25437,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
this.pendingVisionRouteTraces.delete(tabId);
this.pendingVisionStatusTraces.delete(tabId);
this.pendingVisionSubCallTraces.delete(tabId);
+ this.pendingTinyAskGateTraces.delete(tabId);
}
return runId;
}
diff --git a/test/run.js b/test/run.js
index 327770f87..270fed719 100644
--- a/test/run.js
+++ b/test/run.js
@@ -41694,6 +41694,14 @@ test('tiny Ask shows a vision-capable in-browser model the visible page when its
assert.match(JSON.stringify(user.content), /Blue plan: \$5 per month/, 'the page text still goes along');
assert.equal(user.content.at(-1).text, '¿De qué color es el botón de compra?', 'the question comes last');
assert.doesNotMatch(JSON.stringify(agent.conversations.get(tabId)), /data:image|c2NyZWVu/, 'the screenshot is not persisted');
+ // The gate runs during enrichment, before the trace run starts: its note
+ // is queued (this harness never starts a trace), then flushed below.
+ assert.equal(agent.pendingTinyAskGateTraces.get(tabId)?.probability, 0.9, 'the gate note is kept for the trace');
+ const agentSource = fs.readFileSync(path.join(ROOT, 'src/chrome/src/agent/agent.js'), 'utf8');
+ const start = agentSource.slice(agentSource.indexOf('async _startTraceRun('), agentSource.indexOf('async _endTraceRun('));
+ assert.match(start, /const pendingGate = this\.pendingTinyAskGateTraces\.get\(tabId\);\n\s*this\.pendingTinyAskGateTraces\.delete\(tabId\);\n\s*if \(pendingGate\) trace\.recordNote\(runId, null, 'tiny_ask_screenshot_gate', pendingGate\);/,
+ '_startTraceRun records the queued gate note');
+ assert.equal((start.match(/this\.pendingTinyAskGateTraces\.delete\(tabId\)/g) || []).length, 3, 'and drops it when no trace starts');
}
{
const { requests, captures, run } = setup({ gate: () => 0.1 });