Skip to content

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

Freeze feedback traces when the rating prompt opens

Barack Sokullu4eb6bb9d8c58
diff --git a/docs/privacy-and-data-flow.md b/docs/privacy-and-data-flow.md
index 4467f2d28..fb60dc387 100644
--- a/docs/privacy-and-data-flow.md
+++ b/docs/privacy-and-data-flow.md
@@ -491,7 +491,9 @@ The only outbound HTTP requests are:
10. **Feedback trace attachments** uploaded by GitHub's native issue editor,
only after the user chooses **Upload trace and open GitHub** in the extension.
Preparing, viewing, and downloading the trace are local operations. The
- confirmation identifies the conversation, recorded content tier, run and
+ attachment includes only recordings preceding the opening of the rating
+ prompt; later turns and screenshots in the same conversation are excluded.
+ The confirmation identifies the conversation, recorded content tier, run and
screenshot counts, size, and any fallback or omissions. GitHub makes the
attachment publicly accessible immediately, before the issue is submitted.
**Continue without trace** uploads no trace. Export scrubs credential-shaped
diff --git a/docs/security-model.md b/docs/security-model.md
index 82c2de489..457732dbc 100644
--- a/docs/security-model.md
+++ b/docs/security-model.md
@@ -214,8 +214,12 @@ It cannot enable lossless recording. Disabling it clears automatic records and
leaves explicit recordings intact.
Feedback prepares a snapshot of the conversation selected when the rating prompt
-opened. A dedicated dialog must authorize the actual attachment before it leaves
-the browser: GitHub uploads files immediately, even before issue submission.
+opened. A recording cutoff captured before the asynchronous lookup excludes
+later runs, events, screenshots, and completion details, even in the same
+conversation. Untimestamped records are excluded from feedback snapshots;
+ordinary full-session exports remain unbounded. A dedicated dialog must
+authorize the actual attachment before it leaves the browser: GitHub uploads
+files immediately, even before issue submission.
Viewing a trace and continuing without it never authorize an upload. The handoff
is restricted to the chat panel, an exact GitHub repository and destination tab,
the top frame, an expiring random token, and immutable staged bytes. Transfers
diff --git a/src/chrome/src/trace/feedback-export.js b/src/chrome/src/trace/feedback-export.js
index b5e2ada1a..795ab5954 100644
--- a/src/chrome/src/trace/feedback-export.js
+++ b/src/chrome/src/trace/feedback-export.js
@@ -12,6 +12,7 @@ const DIAGNOSTIC_RUN_FIELDS = [
'totalOutputTokens', 'totalCost', 'llmRequestCount', 'llmResponseCount', 'toolCallCount',
'visionSubCallCount', 'errorCount', 'retryCount', 'totalLlmLatencyMs', 'totalToolLatencyMs',
'feedbackOnly', 'feedbackHistoryOmitted', 'feedbackEventsOmitted',
+ 'feedbackSnapshotIncomplete',
];
export function diagnosticFeedbackPayload(payload) {
@@ -36,14 +37,15 @@ export function diagnosticFeedbackPayload(payload) {
export async function prepareFeedbackTrace(store, sessionId, version = '', {
limit = FEEDBACK_ATTACHMENT_LIMIT,
+ snapshotAt,
compress = async blob => typeof CompressionStream === 'function'
? new Response(blob.stream().pipeThrough(new CompressionStream('gzip'))).blob() : null,
} = {}) {
if (!sessionId) return null;
- const exported = await exportRecordedSession(store, sessionId, version);
+ const exported = await exportRecordedSession(store, sessionId, version, { snapshotAt });
if (!exported.turnCount) return null;
let payload = sanitizeTraceExport(JSON.parse(exported.json), { allRuns: true });
- const omissions = [];
+ const omissions = [...exported.snapshotOmissions];
if (exported.recordingTruncated) omissions.push('Some content was omitted at recording time.');
if (payload.runs.some(entry => entry.run.feedbackHistoryOmitted || entry.run.feedbackEventsOmitted)) {
omissions.push('Automatic diagnostic history is bounded; older runs or events may be absent.');
diff --git a/src/chrome/src/trace/session-export.js b/src/chrome/src/trace/session-export.js
index 8cf66b6ca..01514e496 100644
--- a/src/chrome/src/trace/session-export.js
+++ b/src/chrome/src/trace/session-export.js
@@ -1,19 +1,43 @@
import { buildTraceExportPayload } from './export-contract.js';
import { sanitizeTraceExport } from '../agent/trace-export.js';
+import { buildTraceStats } from './stats.js';
// Run in the downloading extension page, never send this JSON through runtime
// messaging: screenshots can make it larger than the browser message limit.
// Export the stored session without the Markdown preview's text/run limits.
// This deliberately preserves recording-time omission markers: an export
// cannot recover content that was never retained by the recorder.
-export async function exportRecordedSession(store, sessionId, version = '') {
- const runs = (await store.listRuns({ limit: Number.MAX_SAFE_INTEGER, conversationId: sessionId }))
- .filter(run => run.conversationId === sessionId)
+export async function exportRecordedSession(store, sessionId, version = '', { snapshotAt } = {}) {
+ const bounded = snapshotAt !== undefined;
+ if (bounded && (!Number.isSafeInteger(snapshotAt) || snapshotAt < 0)) throw new Error('Invalid trace snapshot timestamp.');
+ // Use an exclusive cutoff: recordings with the same clock tick as opening
+ // the prompt cannot be reliably identified as preceding it.
+ const beforeSnapshot = timestamp => Number.isFinite(timestamp) && timestamp < snapshotAt;
+ const snapshotOmissions = new Set();
+ const sessionRuns = (await store.listRuns({ limit: Number.MAX_SAFE_INTEGER, conversationId: sessionId }))
+ .filter(run => run.conversationId === sessionId);
+ if (bounded && sessionRuns.some(run => !Number.isFinite(run.startedAt))) {
+ snapshotOmissions.add('Runs without recording timestamps were excluded from the conversation snapshot.');
+ }
+ const runs = sessionRuns.filter(run => !bounded || beforeSnapshot(run.startedAt))
.sort((a, b) => (a.startedAt || 0) - (b.startedAt || 0) || String(a.runId).localeCompare(String(b.runId)));
const entries = [];
let recordingTruncated = false;
for (const run of runs) {
- const events = await store.getRunEvents(run.runId);
+ const recordedEvents = await store.getRunEvents(run.runId);
+ const events = bounded ? recordedEvents.filter(event => beforeSnapshot(event.ts)) : recordedEvents;
+ let exportedRun = run;
+ if (bounded) {
+ if (recordedEvents.some(event => !Number.isFinite(event.ts))) snapshotOmissions.add('Events without recording timestamps were excluded from the conversation snapshot.');
+ const stats = buildTraceStats(events);
+ delete stats.hasLoopError;
+ exportedRun = { ...run, ...stats };
+ if (!beforeSnapshot(run.endedAt)) {
+ // Completion fields may have been written after the prompt opened.
+ exportedRun = { ...exportedRun, endedAt: null, durationMs: null, status: 'running', finalContent: null, feedbackSnapshotIncomplete: true };
+ snapshotOmissions.add('A run was unfinished when the rating prompt opened; later events and completion details are excluded.');
+ }
+ }
for (const event of events) {
if (event.data?.losslessBudgetOmitted || event.data?.result?._truncated || event.data?.messages?._truncated) recordingTruncated = true;
if (event.kind !== 'screenshot') continue;
@@ -25,9 +49,12 @@ export async function exportRecordedSession(store, sessionId, version = '') {
event.data = { ...event.data, screenshot_base64: `data:${shot.blob.type || 'image/png'};base64,${btoa(binary)}` };
} else if (shot?.dataUrl) event.data = { ...event.data, screenshot_dataUrl: shot.dataUrl };
}
- entries.push({ run, events });
+ entries.push({ run: exportedRun, events });
}
- return { json: JSON.stringify(sanitizeTraceExport(buildTraceExportPayload(entries, {
+ const payload = buildTraceExportPayload(entries, {
sessionId, exportedByWebBrainVersion: version,
- })), null, 2), turnCount: entries.length, recordingTruncated };
+ });
+ if (bounded && payload.session) payload.session.capturedBefore = snapshotAt;
+ return { json: JSON.stringify(sanitizeTraceExport(payload), null, 2),
+ turnCount: entries.length, recordingTruncated, snapshotOmissions: [...snapshotOmissions] };
}
diff --git a/src/chrome/src/ui/feedback-copy.js b/src/chrome/src/ui/feedback-copy.js
index e35f22615..e34dcc446 100644
--- a/src/chrome/src/ui/feedback-copy.js
+++ b/src/chrome/src/ui/feedback-copy.js
@@ -7,7 +7,7 @@ const EN = {
fullLabel: 'Full recorded trace', diagnosticLabel: 'Diagnostic trace',
details: 'Conversation {session} · {type} · {runs} runs · {shots} screenshots · {size}',
preparing: 'Preparing trace locally…',
- omitted: 'Recording or retention limits omitted some content. See the trace for details.',
+ omitted: 'Some content is unavailable or excluded. See the trace for details.',
oversized: 'The full export is too large to attach. Only the diagnostic fallback will be uploaded. View trace to download the full export locally.',
failed: 'The trace attachment could not be confirmed. Check the draft before retrying, or download the trace.',
uploading: 'Attaching your trace. Please wait before submitting the issue.',
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index fa4c0711d..8e0d8b36d 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -1835,10 +1835,12 @@ function setStoreReviewStarPreview(rating) {
async function openStoreReviewPrompt() {
if (!storeReviewEl || isProcessing) return;
- // Freeze the session before tabs or conversations can change beneath the prompt.
+ // Capture the conversation and recording cutoff before asynchronous lookup.
const sourceTabId = currentTabId;
+ const snapshotAt = Date.now();
storeReviewTraceSource = sourceTabId == null ? Promise.resolve(null)
- : sendToBackground('export_traces', { tabId: sourceTabId, full: true }).catch(() => null);
+ : sendToBackground('export_traces', { tabId: sourceTabId, full: true })
+ .then(source => source?.sessionId ? { ...source, snapshotAt } : null).catch(() => null);
storeReviewSelectedRating = null;
if (storeReviewFeedbackEl) storeReviewFeedbackEl.value = '';
setStoreReviewStarPreview(null);
@@ -1904,7 +1906,7 @@ async function handleStoreReviewSendFeedback() {
const [store, { prepareFeedbackTrace }] = await Promise.all([
import('../trace/recorder.js'), import('../trace/feedback-export.js'),
]);
- return prepareFeedbackTrace(store, source.sessionId, chrome.runtime.getManifest().version || '');
+ return prepareFeedbackTrace(store, source.sessionId, chrome.runtime.getManifest().version || '', { snapshotAt: source.snapshotAt });
},
stage: prepared => stageFeedbackTrace({ ...prepared, copy }),
discard: deleteFeedbackDraft,
diff --git a/src/firefox/src/trace/feedback-export.js b/src/firefox/src/trace/feedback-export.js
index b5e2ada1a..795ab5954 100644
--- a/src/firefox/src/trace/feedback-export.js
+++ b/src/firefox/src/trace/feedback-export.js
@@ -12,6 +12,7 @@ const DIAGNOSTIC_RUN_FIELDS = [
'totalOutputTokens', 'totalCost', 'llmRequestCount', 'llmResponseCount', 'toolCallCount',
'visionSubCallCount', 'errorCount', 'retryCount', 'totalLlmLatencyMs', 'totalToolLatencyMs',
'feedbackOnly', 'feedbackHistoryOmitted', 'feedbackEventsOmitted',
+ 'feedbackSnapshotIncomplete',
];
export function diagnosticFeedbackPayload(payload) {
@@ -36,14 +37,15 @@ export function diagnosticFeedbackPayload(payload) {
export async function prepareFeedbackTrace(store, sessionId, version = '', {
limit = FEEDBACK_ATTACHMENT_LIMIT,
+ snapshotAt,
compress = async blob => typeof CompressionStream === 'function'
? new Response(blob.stream().pipeThrough(new CompressionStream('gzip'))).blob() : null,
} = {}) {
if (!sessionId) return null;
- const exported = await exportRecordedSession(store, sessionId, version);
+ const exported = await exportRecordedSession(store, sessionId, version, { snapshotAt });
if (!exported.turnCount) return null;
let payload = sanitizeTraceExport(JSON.parse(exported.json), { allRuns: true });
- const omissions = [];
+ const omissions = [...exported.snapshotOmissions];
if (exported.recordingTruncated) omissions.push('Some content was omitted at recording time.');
if (payload.runs.some(entry => entry.run.feedbackHistoryOmitted || entry.run.feedbackEventsOmitted)) {
omissions.push('Automatic diagnostic history is bounded; older runs or events may be absent.');
diff --git a/src/firefox/src/trace/session-export.js b/src/firefox/src/trace/session-export.js
index 8cf66b6ca..01514e496 100644
--- a/src/firefox/src/trace/session-export.js
+++ b/src/firefox/src/trace/session-export.js
@@ -1,19 +1,43 @@
import { buildTraceExportPayload } from './export-contract.js';
import { sanitizeTraceExport } from '../agent/trace-export.js';
+import { buildTraceStats } from './stats.js';
// Run in the downloading extension page, never send this JSON through runtime
// messaging: screenshots can make it larger than the browser message limit.
// Export the stored session without the Markdown preview's text/run limits.
// This deliberately preserves recording-time omission markers: an export
// cannot recover content that was never retained by the recorder.
-export async function exportRecordedSession(store, sessionId, version = '') {
- const runs = (await store.listRuns({ limit: Number.MAX_SAFE_INTEGER, conversationId: sessionId }))
- .filter(run => run.conversationId === sessionId)
+export async function exportRecordedSession(store, sessionId, version = '', { snapshotAt } = {}) {
+ const bounded = snapshotAt !== undefined;
+ if (bounded && (!Number.isSafeInteger(snapshotAt) || snapshotAt < 0)) throw new Error('Invalid trace snapshot timestamp.');
+ // Use an exclusive cutoff: recordings with the same clock tick as opening
+ // the prompt cannot be reliably identified as preceding it.
+ const beforeSnapshot = timestamp => Number.isFinite(timestamp) && timestamp < snapshotAt;
+ const snapshotOmissions = new Set();
+ const sessionRuns = (await store.listRuns({ limit: Number.MAX_SAFE_INTEGER, conversationId: sessionId }))
+ .filter(run => run.conversationId === sessionId);
+ if (bounded && sessionRuns.some(run => !Number.isFinite(run.startedAt))) {
+ snapshotOmissions.add('Runs without recording timestamps were excluded from the conversation snapshot.');
+ }
+ const runs = sessionRuns.filter(run => !bounded || beforeSnapshot(run.startedAt))
.sort((a, b) => (a.startedAt || 0) - (b.startedAt || 0) || String(a.runId).localeCompare(String(b.runId)));
const entries = [];
let recordingTruncated = false;
for (const run of runs) {
- const events = await store.getRunEvents(run.runId);
+ const recordedEvents = await store.getRunEvents(run.runId);
+ const events = bounded ? recordedEvents.filter(event => beforeSnapshot(event.ts)) : recordedEvents;
+ let exportedRun = run;
+ if (bounded) {
+ if (recordedEvents.some(event => !Number.isFinite(event.ts))) snapshotOmissions.add('Events without recording timestamps were excluded from the conversation snapshot.');
+ const stats = buildTraceStats(events);
+ delete stats.hasLoopError;
+ exportedRun = { ...run, ...stats };
+ if (!beforeSnapshot(run.endedAt)) {
+ // Completion fields may have been written after the prompt opened.
+ exportedRun = { ...exportedRun, endedAt: null, durationMs: null, status: 'running', finalContent: null, feedbackSnapshotIncomplete: true };
+ snapshotOmissions.add('A run was unfinished when the rating prompt opened; later events and completion details are excluded.');
+ }
+ }
for (const event of events) {
if (event.data?.losslessBudgetOmitted || event.data?.result?._truncated || event.data?.messages?._truncated) recordingTruncated = true;
if (event.kind !== 'screenshot') continue;
@@ -25,9 +49,12 @@ export async function exportRecordedSession(store, sessionId, version = '') {
event.data = { ...event.data, screenshot_base64: `data:${shot.blob.type || 'image/png'};base64,${btoa(binary)}` };
} else if (shot?.dataUrl) event.data = { ...event.data, screenshot_dataUrl: shot.dataUrl };
}
- entries.push({ run, events });
+ entries.push({ run: exportedRun, events });
}
- return { json: JSON.stringify(sanitizeTraceExport(buildTraceExportPayload(entries, {
+ const payload = buildTraceExportPayload(entries, {
sessionId, exportedByWebBrainVersion: version,
- })), null, 2), turnCount: entries.length, recordingTruncated };
+ });
+ if (bounded && payload.session) payload.session.capturedBefore = snapshotAt;
+ return { json: JSON.stringify(sanitizeTraceExport(payload), null, 2),
+ turnCount: entries.length, recordingTruncated, snapshotOmissions: [...snapshotOmissions] };
}
diff --git a/src/firefox/src/ui/feedback-copy.js b/src/firefox/src/ui/feedback-copy.js
index e35f22615..e34dcc446 100644
--- a/src/firefox/src/ui/feedback-copy.js
+++ b/src/firefox/src/ui/feedback-copy.js
@@ -7,7 +7,7 @@ const EN = {
fullLabel: 'Full recorded trace', diagnosticLabel: 'Diagnostic trace',
details: 'Conversation {session} · {type} · {runs} runs · {shots} screenshots · {size}',
preparing: 'Preparing trace locally…',
- omitted: 'Recording or retention limits omitted some content. See the trace for details.',
+ omitted: 'Some content is unavailable or excluded. See the trace for details.',
oversized: 'The full export is too large to attach. Only the diagnostic fallback will be uploaded. View trace to download the full export locally.',
failed: 'The trace attachment could not be confirmed. Check the draft before retrying, or download the trace.',
uploading: 'Attaching your trace. Please wait before submitting the issue.',
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index 4b7876965..d07362801 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -1537,10 +1537,12 @@ function setStoreReviewStarPreview(rating) {
async function openStoreReviewPrompt() {
if (!storeReviewEl || isProcessing) return;
- // Freeze the session before tabs or conversations can change beneath the prompt.
+ // Capture the conversation and recording cutoff before asynchronous lookup.
const sourceTabId = currentTabId;
+ const snapshotAt = Date.now();
storeReviewTraceSource = sourceTabId == null ? Promise.resolve(null)
- : sendToBackground('export_traces', { tabId: sourceTabId, full: true }).catch(() => null);
+ : sendToBackground('export_traces', { tabId: sourceTabId, full: true })
+ .then(source => source?.sessionId ? { ...source, snapshotAt } : null).catch(() => null);
storeReviewSelectedRating = null;
if (storeReviewFeedbackEl) storeReviewFeedbackEl.value = '';
setStoreReviewStarPreview(null);
@@ -1606,7 +1608,7 @@ async function handleStoreReviewSendFeedback() {
const [store, { prepareFeedbackTrace }] = await Promise.all([
import('../trace/recorder.js'), import('../trace/feedback-export.js'),
]);
- return prepareFeedbackTrace(store, source.sessionId, browser.runtime.getManifest().version || '');
+ return prepareFeedbackTrace(store, source.sessionId, browser.runtime.getManifest().version || '', { snapshotAt: source.snapshotAt });
},
stage: prepared => stageFeedbackTrace({ ...prepared, copy }),
discard: deleteFeedbackDraft,
diff --git a/test/feedback-traces.mjs b/test/feedback-traces.mjs
index dec524e3d..c5ec13045 100644
--- a/test/feedback-traces.mjs
+++ b/test/feedback-traces.mjs
@@ -14,10 +14,11 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
const { createConfigExport, parseConfigImport } = await import(`../src/${build}/src/config-transfer.js`);
const { mayReadFeedbackDraft, isFeedbackDestination } = await import(`../src/${build}/src/feedback-handoff.js`);
const { sanitizeTraceExport } = await import(`../src/${build}/src/agent/trace-export.js`);
+ const { exportRecordedSession } = await import(`../src/${build}/src/trace/session-export.js`);
const fixtureStore = (events = []) => ({
- listRuns: async () => [{ runId: 'r', conversationId: 'chosen', userMessage: 'password=top-secret', lossless: true },
+ listRuns: async () => [{ runId: 'r', conversationId: 'chosen', startedAt: 1, endedAt: 2, status: 'done', userMessage: 'password=top-secret', lossless: true },
{ runId: 'other', conversationId: 'unrelated', userMessage: 'DO NOT SHARE' }],
- getRunEvents: async () => structuredClone(events),
+ getRunEvents: async () => structuredClone(events.map(event => ({ ts: 1, ...event }))),
getScreenshot: async () => ({ blob: new Blob(['image bytes'], { type: 'image/png' }) }),
});
@@ -26,8 +27,9 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
const start = source.indexOf('async function openStoreReviewPrompt()');
const end = source.indexOf('async function maybePromptStoreReviewAfterSuccess()', start);
assert.ok(start >= 0 && end > start);
- let capturedTab, resolveSession;
+ let capturedTab, resolveSession, now = 100;
const panel = vm.createContext({ currentTabId: 71, storeReviewEl: {}, isProcessing: false,
+ Date: { now: () => now },
storeReviewFeedbackEl: { value: 'Previous feedback' }, storeReviewState: {}, storeReviewTraceSource: null,
sendToBackground: (_action, params) => { capturedTab = params.tabId; return new Promise(resolve => { resolveSession = resolve; }); },
setStoreReviewStarPreview: () => {}, showStoreReviewStep: () => {}, applyDOMTranslations: () => {},
@@ -36,15 +38,17 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
vm.runInContext(source.slice(start, end), panel);
await vm.runInContext('openStoreReviewPrompt()', panel);
panel.currentTabId = 99;
+ now = 300;
resolveSession({ sessionId: 'chosen' });
const captured = await panel.storeReviewTraceSource;
assert.equal(capturedTab, 71);
+ assert.equal(captured.snapshotAt, 100, 'capture must precede the asynchronous session lookup');
const store = fixtureStore([{ seq: 1, kind: 'tool', data: { name: 'click_ax', args: { api_key: 'private-key' },
result: { success: false, errorCode: 'TARGET_NOT_FOUND', authorization: 'Bearer hidden' } } },
{ seq: 2, kind: 'screenshot', data: {} }]);
// Old traces may contain content without a lossless marker.
const list = store.listRuns; store.listRuns = async () => (await list()).map(run => ({ ...run, lossless: undefined }));
- const trace = await prepareFeedbackTrace(store, captured.sessionId, 'test');
+ const trace = await prepareFeedbackTrace(store, captured.sessionId, 'test', { snapshotAt: captured.snapshotAt });
assert.equal(trace.traceType, 'full'); assert.equal(trace.runCount, 1); assert.equal(trace.screenshotCount, 1);
assert.equal(trace.blob, trace.originalBlob);
const json = await trace.blob.text();
@@ -53,6 +57,82 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
assert.equal(await prepareFeedbackTrace({ ...store, listRuns: async () => [] }, 'chosen'), null);
});
+ test(`${build}: feedback excludes later turns, events, screenshots and completion fields`, async () => {
+ const runs = [
+ { runId: 'completed', conversationId: 'chosen', startedAt: 1, endedAt: 50, status: 'done', finalContent: 'Earlier answer', lossless: true },
+ { runId: 'active', conversationId: 'chosen', startedAt: 60, endedAt: 200, status: 'done', finalContent: 'LATER COMPLETION', lossless: true,
+ toolCallCount: 99, totalCost: 99 },
+ { runId: 'same-tick', conversationId: 'chosen', startedAt: 100, userMessage: 'LATER SAME TICK' },
+ { runId: 'later', conversationId: 'chosen', startedAt: 150, userMessage: 'LATER TURN' },
+ { runId: 'undated', conversationId: 'chosen', userMessage: 'UNDATED RUN' },
+ { runId: 'other', conversationId: 'unrelated', startedAt: 1, userMessage: 'OTHER CONVERSATION' },
+ ];
+ const events = {
+ completed: [{ seq: 1, ts: 20, kind: 'tool', data: { name: 'click_ax', result: { success: true } } }],
+ active: [
+ { seq: 1, ts: 70, kind: 'tool', data: { name: 'click_ax', result: { success: true } } },
+ { seq: 2, ts: 80, kind: 'llm_response', data: { content: 'Earlier response', usage: { cost: 1 } } },
+ { seq: 3, ts: 90, kind: 'screenshot', data: { caption: 'Earlier screenshot' } },
+ { seq: 4, ts: 100, kind: 'tool', data: { result: { content: 'LATER SAME TICK' } } },
+ { seq: 5, ts: 101, kind: 'screenshot', data: { caption: 'LATER SCREENSHOT' } },
+ { seq: 6, ts: 120, kind: 'llm_response', data: { content: 'LATER RESPONSE', usage: { cost: 98 } } },
+ { seq: 7, kind: 'note', data: { content: 'UNDATED EVENT' } },
+ ],
+ };
+ const readRuns = [], readShots = [];
+ const store = {
+ listRuns: async () => structuredClone(runs),
+ getRunEvents: async runId => { readRuns.push(runId); return structuredClone(events[runId] || []); },
+ getScreenshot: async (runId, seq) => {
+ readShots.push([runId, seq]);
+ return { blob: new Blob([seq === 3 ? 'Earlier pixels' : 'LATER PIXELS'], { type: 'image/png' }) };
+ },
+ };
+ const trace = await prepareFeedbackTrace(store, 'chosen', 'test', { snapshotAt: 100 });
+ const text = await trace.blob.text();
+ const payload = JSON.parse(text);
+ assert.equal(payload.session.capturedBefore, 100);
+ assert.deepEqual(payload.runs.map(entry => entry.run.runId), ['completed', 'active']);
+ assert.deepEqual(readRuns, ['completed', 'active']);
+ assert.deepEqual(readShots, [['active', 3]], 'later screenshot bytes must never be read');
+ assert.equal(trace.runCount, 2); assert.equal(trace.screenshotCount, 1);
+ assert.equal(payload.runs[0].run.finalContent, 'Earlier answer');
+ const active = payload.runs[1];
+ assert.deepEqual(active.events.map(event => event.seq), [1, 2, 3]);
+ assert.equal(active.run.status, 'running'); assert.equal(active.run.endedAt, null);
+ assert.equal(active.run.durationMs, null); assert.equal(active.run.finalContent, null);
+ assert.equal(active.run.toolCallCount, 1); assert.equal(active.run.totalCost, 1);
+ assert.equal(active.run.feedbackSnapshotIncomplete, true);
+ assert.ok(trace.omissions.some(note => note.includes('unfinished')));
+ assert.ok(trace.omissions.some(note => note.includes('timestamps')));
+ assert.doesNotMatch(text, /LATER|UNDATED|OTHER CONVERSATION/);
+ assert.equal(await trace.originalBlob.text(), text);
+
+ const largeStore = { ...store, getRunEvents: async runId => (await store.getRunEvents(runId)).map(event =>
+ event.kind === 'tool' && event.ts < 100 ? { ...event, data: { ...event.data, result: { content: 'Earlier content '.repeat(2000) } } } : event) };
+ for (const options of [{}, { compress: async () => null }]) {
+ const oversized = await prepareFeedbackTrace(largeStore, 'chosen', 'test', { snapshotAt: 100, limit: 6000, ...options });
+ const bytes = Buffer.from(await oversized.blob.arrayBuffer());
+ const attached = JSON.parse(oversized.filename.endsWith('.gz') ? gunzipSync(bytes).toString() : bytes.toString());
+ assert.equal(attached.session.capturedBefore, 100);
+ assert.equal(attached.runs[1].run.feedbackSnapshotIncomplete, true);
+ assert.doesNotMatch(JSON.stringify(attached), /LATER|UNDATED|OTHER CONVERSATION/);
+ assert.doesNotMatch(await oversized.originalBlob.text(), /LATER|UNDATED|OTHER CONVERSATION/);
+ assert.equal(oversized.traceType, options.compress ? 'diagnostic' : 'full');
+ }
+
+ // The ordinary full export remains complete, including later turns.
+ const full = JSON.parse((await exportRecordedSession(store, 'chosen', 'test')).json);
+ assert.equal(full.runs.length, 5);
+ assert.equal(full.runs.find(entry => entry.run.runId === 'active').run.finalContent, 'LATER COMPLETION');
+ assert.equal(full.runs.find(entry => entry.run.runId === 'active').events.length, 7);
+ assert.equal(full.session.capturedBefore, undefined);
+ for (const snapshotAt of [null, NaN, '100', -1]) {
+ await assert.rejects(prepareFeedbackTrace(store, 'chosen', 'test', { snapshotAt }), /snapshot timestamp/);
+ }
+ assert.equal(await prepareFeedbackTrace(store, 'chosen', 'test', { snapshotAt: 0 }), null);
+ });
+
test(`${build}: gzip preserves full exports and oversize fallback is explicitly diagnostic`, async () => {
const events = Array.from({ length: 80 }, (_, index) => ({ seq: index, kind: 'tool', data: {
name: 'click_ax', result: { content: 'large trace content '.repeat(100), success: false, errorCode: 'CLICK_FAILED' },
@@ -270,12 +350,28 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
const { stageFeedbackTrace, deleteFeedbackDraft, listFeedbackDrafts, putFeedbackDraft, sweepFeedbackDrafts } = await import('./src/feedback-store.js');
const { getFeedbackCopy } = await import('./src/ui/feedback-copy.js');
const { requestFeedbackConsent, submitFeedbackWithTrace } = await import('./src/ui/feedback-consent.js');
+ const trace = await import('./src/trace/recorder.js');
const copy = getFeedbackCopy('en');
globalThis.controller = createFeedbackHandoff(chrome);
globalThis.localViews = 0;
- globalThis.prepared = await prepareFeedbackTrace({ listRuns: async () => [{ runId: 'r', conversationId: 'frozen-session', lossless: true }],
- getRunEvents: async () => [{ seq: 1, kind: 'tool', data: { name: 'click_ax', result: { errorCode: 'CLICK_FAILED', password: 'hidden-secret' } } }],
- getScreenshot: async () => null }, 'frozen-session', 'test');
+ settings.tracingEnabled = true; settings.losslessTrace = true;
+ const originalNow = Date.now;
+ let clock = originalNow() - 10000;
+ const snapshotAt = clock + 1000;
+ Date.now = () => clock;
+ try {
+ const runId = await trace.startRun({ runId: 'r', conversationId: 'frozen-session' });
+ await trace.recordToolCall(runId, 1, { name: 'click_ax', result: { errorCode: 'CLICK_FAILED', password: 'hidden-secret' } });
+ await trace.recordScreenshot(runId, 1, 'data:image/png;base64,aW1hZ2U=', 'Earlier screenshot');
+ clock += 2000;
+ await trace.recordToolCall(runId, 2, { name: 'click_ax', result: { content: 'LATER TOOL RESULT' } });
+ await trace.recordScreenshot(runId, 2, 'data:image/png;base64,TEFURVI=', 'LATER SCREENSHOT');
+ await trace.endRun(runId, { finalContent: 'LATER COMPLETION' });
+ const laterRunId = await trace.startRun({ runId: 'later', conversationId: 'frozen-session', userMessage: 'LATER TURN' });
+ await trace.endRun(laterRunId);
+ await trace.flushPendingWrites();
+ } finally { Date.now = originalNow; }
+ globalThis.prepared = await prepareFeedbackTrace(trace, 'frozen-session', 'test', { snapshotAt });
globalThis.start = () => submitFeedbackWithTrace({
rating: 2, comment: 'Clicking failed', copy,
prepare: async () => prepared,
@@ -332,7 +428,12 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
await github.waitForFunction(() => document.body.textContent.includes('Trace attached.'));
assert.equal(await github.evaluate(() => uploads), 1);
assert.equal(await github.evaluate(() => submissions), 0);
- assert.doesNotMatch(await github.evaluate(() => uploadedText), /hidden-secret/);
+ const attachment = await github.evaluate(() => uploadedText);
+ assert.doesNotMatch(attachment, /hidden-secret|LATER/);
+ const snapshot = JSON.parse(attachment);
+ assert.deepEqual(snapshot.runs.map(entry => entry.run.runId), ['r']);
+ assert.equal(snapshot.runs[0].run.finalContent, null);
+ assert.equal(snapshot.runs[0].events.filter(event => event.kind === 'screenshot').length, 1);
assert.match(await github.locator('textarea').inputValue(), /Clicking failed/);
await github.addScriptTag({ content }); assert.equal(await github.evaluate(() => uploads), 1);
assert.equal(await panel.evaluate(async () => (await store.listFeedbackDrafts()).length), 0);