Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(bug-report): upload the screenshot from the client so it embeds (PRD-7681) (#3039)

Andrew Mikofalvy4129774f195b
diff --git a/.changeset/bug-report-inline-screenshot.md b/.changeset/bug-report-inline-screenshot.md
new file mode 100644
index 000000000..37d7a64cf
--- /dev/null
+++ b/.changeset/bug-report-inline-screenshot.md
@@ -0,0 +1,16 @@
+---
+'@inkeep/open-knowledge': patch
+---
+
+Screenshots attached to a bug report now show up in the report itself, instead of only inside the downloadable diagnostic bundle. Anyone triaging a report sees the picture immediately rather than having to download a zip and unpack it to find out what the reporter was looking at.
+
+| Before | After |
+| --- | --- |
+| Report says a screenshot was included; nothing visible | The screenshot is displayed in the report |
+| Triager downloads the bundle and unzips it to see anything | Nothing to download for a look at the screen |
+
+This was supposed to work already, and never did once. The intake tried to pull the screenshot out of the bundle after the upload, but the storage the bundle lands in refuses that read, so the step failed silently on every single report and the screenshot was quietly left out. The app now uploads the screenshot alongside the bundle rather than expecting the server to dig it back out, which removes the failing step entirely.
+
+Two things worth knowing. This takes effect for reports sent from this version onward, because the app is what supplies the screenshot now — reports already filed are unaffected. And re-sending a report from the report list in a later session sends it without the inline screenshot, since the capture is no longer in memory by then; the screenshot is still inside the bundle in that case.
+
+Unchanged: the screenshot is still opt-in via the checkbox in the report dialog, still previewed before you send, and unchecking it still means no screenshot leaves your machine.
diff --git a/packages/app/src/components/ReportBugDialog.dom.test.tsx b/packages/app/src/components/ReportBugDialog.dom.test.tsx
index bcbaac2dc..dfcb93927 100644
--- a/packages/app/src/components/ReportBugDialog.dom.test.tsx
+++ b/packages/app/src/components/ReportBugDialog.dom.test.tsx
@@ -353,6 +353,10 @@ describe('ReportBugDialog', () => {
projectSlug: 'demo-project',
note: 'upload me',
},
+ // Consent for the separate screenshot upload, read off the bundle's own
+ // file inventory. This fixture's summary carries no screenshot entry, so
+ // main must be told not to upload the capture it may still be holding.
+ includeScreenshot: false,
},
]);
expect(screen.getByDisplayValue('OK-8H3KQD')).not.toBeNull();
@@ -752,6 +756,30 @@ describe('ReportBugDialog', () => {
expect(screen.queryByText(/crash dump not redacted/)).toBeNull();
});
+ test('a screenshot-bearing bundle tells main to upload the screenshot', async () => {
+ // The consent signal for the separate screenshot upload is read off the
+ // bundle's file inventory, not the checkbox state, so it cannot drift from the
+ // artifact the reporter reviewed if the checkbox is toggled after create.
+ const log = installBridge({
+ captureScreenshot: () => Promise.resolve(SCREENSHOT),
+ create: () =>
+ Promise.resolve({
+ ...CREATE_OK,
+ summary: { ...SUMMARY, files: [...SUMMARY.files, 'extra/screenshot.png'] },
+ }),
+ });
+ await renderDialog();
+
+ await userEvent.click(screen.getByRole('button', { name: 'Create report' }));
+ await screen.findByRole('heading', { name: 'Review your report' });
+ await userEvent.click(screen.getByRole('button', { name: 'Send report' }));
+
+ await vi.waitFor(() => {
+ expect(log.sendCalls).toHaveLength(1);
+ });
+ expect(log.sendCalls[0]?.includeScreenshot).toBe(true);
+ });
+
test('the capture waits for the launcher (⌘K palette) to clear before revealing', async () => {
// Stand in for the command palette still animating out as the dialog opens
// (the reported leak: the palette was opened only to reach Report a bug).
diff --git a/packages/app/src/components/ReportBugDialogBody.tsx b/packages/app/src/components/ReportBugDialogBody.tsx
index 7107045b9..13c30b64e 100644
--- a/packages/app/src/components/ReportBugDialogBody.tsx
+++ b/packages/app/src/components/ReportBugDialogBody.tsx
@@ -379,6 +379,12 @@ function ReportBugDialog({
projectSlug: report.summary.projectSlug,
note: composeNote(note, noteContextLines),
},
+ // Read consent off the bundle's own inventory rather than the checkbox
+ // state: the inventory is what `create` acted on and what the reporter
+ // reviewed, so it cannot drift from the artifact being sent if the checkbox
+ // is toggled after create. Main uses this to decide whether to upload the
+ // screenshot separately for inline display in the ticket.
+ includeScreenshot: report.summary.files.includes(BUG_REPORT_SCREENSHOT_ZIP_ENTRY),
});
if (opSeqRef.current !== seq) return;
if (result.ok) {
diff --git a/packages/app/src/lib/desktop-bridge-types.ts b/packages/app/src/lib/desktop-bridge-types.ts
index 3ed93f93b..186f2fc00 100644
--- a/packages/app/src/lib/desktop-bridge-types.ts
+++ b/packages/app/src/lib/desktop-bridge-types.ts
@@ -1275,6 +1275,14 @@ export interface OkDesktopBridge {
send(request: {
zipPath: string;
metadata: OkBugReportSendMetadata;
+ /**
+ * Whether the bundle at `zipPath` contains the app screenshot, taken from
+ * the bundle's own file inventory rather than the dialog's checkbox state.
+ * The inventory is what the reporter reviewed, so it is the authoritative
+ * consent record: absent or false means main must not upload the capture it
+ * is still holding.
+ */
+ includeScreenshot?: boolean;
}): Promise<OkBugReportSendResult>;
crashAck(request: { eventId: string }): Promise<OkBugReportCrashAckResult>;
list(): Promise<OkBugReportListResult>;
diff --git a/packages/core/src/desktop-bridge.ts b/packages/core/src/desktop-bridge.ts
index 59b067531..1758842c8 100644
--- a/packages/core/src/desktop-bridge.ts
+++ b/packages/core/src/desktop-bridge.ts
@@ -1443,6 +1443,14 @@ export interface OkDesktopBridge {
send(request: {
zipPath: string;
metadata: OkBugReportSendMetadata;
+ /**
+ * Whether the bundle at `zipPath` contains the app screenshot, taken from
+ * the bundle's own file inventory rather than the dialog's checkbox state.
+ * The inventory is what the reporter reviewed, so it is the authoritative
+ * consent record: absent or false means main must not upload the capture it
+ * is still holding.
+ */
+ includeScreenshot?: boolean;
}): Promise<OkBugReportSendResult>;
crashAck(request: { eventId: string }): Promise<OkBugReportCrashAckResult>;
list(): Promise<OkBugReportListResult>;
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index 45232b145..8b6867f27 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -4809,6 +4809,11 @@ function registerIpcHandlers() {
// Records uploading → sent/upload-failed/email-drafted on the sidecar
// and holds the in-flight lock, for the first send and a list retry.
sidecar: bugReportSidecar.sendHooks,
+ // Same per-window capture `create` stages into the zip, uploaded
+ // separately as its own Linear asset so the ticket embeds it inline.
+ // Still present here because the dialog has not closed yet; a list retry
+ // in a later session finds nothing and files without the inline image.
+ screenshotPngBytes: () => bugReportScreenshots.get(event.sender.id)?.png ?? null,
},
request,
);
diff --git a/packages/desktop/src/main/ipc/bug-report.test.ts b/packages/desktop/src/main/ipc/bug-report.test.ts
index 950c7ae68..4372a2349 100644
--- a/packages/desktop/src/main/ipc/bug-report.test.ts
+++ b/packages/desktop/src/main/ipc/bug-report.test.ts
@@ -346,9 +346,16 @@ function startIntakeStub(
completeBody?: unknown;
/** Record the completion request but never respond. */
stallComplete?: boolean;
+ /** Status for the SECOND mint (the image/png screenshot mint) only. */
+ screenshotMintStatus?: number;
+ /** Status for the screenshot PUT only (the second PUT to /upload/dest). */
+ screenshotPutStatus?: number;
+ /** Body for the screenshot mint only, for the malformed / non-https guards. */
+ screenshotMintBody?: unknown;
} = {},
): Promise<IntakeStub> {
const requests: RecordedRequest[] = [];
+ let putCount = 0;
let url = '';
const server = createServer((req, res) => {
const chunks: Buffer[] = [];
@@ -363,6 +370,22 @@ function startIntakeStub(
};
if (method === 'POST' && path === '/api/bug-report') {
if (overrides.stallMint === true) return;
+ // The screenshot mint is distinguishable by its content type, which lets a
+ // test fail only that one and prove the report still files.
+ let mintedContentType: unknown;
+ try {
+ mintedContentType = (
+ JSON.parse(Buffer.concat(chunks).toString('utf8')) as { contentType?: unknown }
+ ).contentType;
+ } catch {
+ mintedContentType = undefined;
+ }
+ if (mintedContentType === 'image/png' && overrides.screenshotMintStatus !== undefined) {
+ return respond(overrides.screenshotMintStatus, { error: 'screenshot mint refused' });
+ }
+ if (mintedContentType === 'image/png' && overrides.screenshotMintBody !== undefined) {
+ return respond(200, overrides.screenshotMintBody);
+ }
respond(
overrides.mintStatus ?? 200,
overrides.mintBody ?? {
@@ -373,6 +396,12 @@ function startIntakeStub(
);
} else if (method === 'PUT' && path === '/upload/dest') {
if (overrides.stallPut === true) return;
+ // The screenshot PUT is the second one; failing only it proves the report
+ // survives a screenshot upload that is refused after a successful mint.
+ putCount += 1;
+ if (putCount === 2 && overrides.screenshotPutStatus !== undefined) {
+ return respond(overrides.screenshotPutStatus, { error: 'screenshot put refused' });
+ }
const putStatus = overrides.putStatus ?? 200;
if (putStatus >= 300 && putStatus < 400) {
// A redirecting storage endpoint — the client must refuse to chase it.
@@ -442,17 +471,24 @@ function makeZipFixture(bugReportsRoot: string): string {
}
/** Deps plus a zip fixture placed inside the deps' containment root. */
-function makeSendRig(intakeBaseUrl: string | undefined): {
+function makeSendRig(
+ intakeBaseUrl: string | undefined,
+ screenshotPng?: Buffer,
+): {
deps: BugReportSendDeps;
zipPath: string;
} {
const bugReportsRoot = makeBugReportsRoot();
+ const deps = makeSendDeps(intakeBaseUrl, bugReportsRoot);
return {
- deps: makeSendDeps(intakeBaseUrl, bugReportsRoot),
+ deps: screenshotPng === undefined ? deps : { ...deps, screenshotPngBytes: () => screenshotPng },
zipPath: makeZipFixture(bugReportsRoot),
};
}
+// Minimal PNG signature — enough to assert the exact bytes reach the PUT.
+const SCREENSHOT_PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x07, 0x09]);
+
describe('resolveBugReportIntakeUrl', () => {
test('an explicit env URL always wins', () => {
const envUrl = 'https://intake.example.test';
@@ -473,6 +509,220 @@ describe('resolveBugReportIntakeUrl', () => {
});
});
+describe('handleBugReportSend — inline screenshot upload', () => {
+ test('uploads the screenshot as its own asset and passes its URL to completion', async () => {
+ // Client-side by necessity: the intake cannot read the screenshot back out of
+ // the bundle it just received, because Linear serves uploaded assets behind
+ // authentication and the workspace API key does not authorize the raw asset
+ // URL. Only this process holds the PNG before it is zipped.
+ const stub = await startIntakeStub();
+ const { deps, zipPath } = makeSendRig(stub.url, SCREENSHOT_PNG);
+
+ const result = await handleBugReportSend(deps, {
+ kind: 'send',
+ zipPath,
+ metadata: SEND_METADATA,
+ includeScreenshot: true,
+ });
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+
+ // The screenshot rides AFTER the bundle PUT and BEFORE completion, so a
+ // screenshot failure can never strand a bundle that already landed.
+ expect(stub.requests.map((r) => `${r.method} ${r.path}`)).toEqual([
+ 'POST /api/bug-report',
+ 'PUT /upload/dest',
+ 'POST /api/bug-report',
+ 'PUT /upload/dest',
+ 'POST /api/bug-report/complete',
+ ]);
+
+ const [, , imageMint, imagePut, complete] = stub.requests;
+ expect(JSON.parse(imageMint?.body.toString('utf8') ?? '')).toEqual({
+ filename: 'screenshot.png',
+ sizeBytes: SCREENSHOT_PNG.byteLength,
+ contentType: 'image/png',
+ metadata: { ...SEND_METADATA, ...SEND_HOST },
+ });
+ expect(imagePut?.headers['content-type']).toBe('image/png');
+ expect(imagePut?.body.equals(SCREENSHOT_PNG)).toBe(true);
+
+ expect(JSON.parse(complete?.body.toString('utf8') ?? '')).toMatchObject({
+ screenshotAssetUrl: 'https://uploads.example.invalid/asset/dest',
+ });
+ });
+
+ test('omits the screenshot key entirely when no capture is available', async () => {
+ // A list retry in a later session, a reporter who unchecked the box, or a
+ // failed capture. The key is omitted rather than sent as null so an intake
+ // that predates the field is unaffected.
+ const stub = await startIntakeStub();
+ const { deps, zipPath } = makeSendRig(stub.url);
+
+ const result = await handleBugReportSend(deps, {
+ kind: 'send',
+ zipPath,
+ metadata: SEND_METADATA,
+ });
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+ expect(stub.requests).toHaveLength(3);
+ const body = JSON.parse(stub.requests[2]?.body.toString('utf8') ?? '') as Record<
+ string,
+ unknown
+ >;
+ expect('screenshotAssetUrl' in body).toBe(false);
+ });
+
+ test('still files the report when the screenshot PUT is refused', async () => {
+ // The mint succeeds and the upload itself fails, which is a different branch
+ // from a refused mint and the one an intake-side storage hiccup takes.
+ const stub = await startIntakeStub({ screenshotPutStatus: 500 });
+ const { deps, zipPath } = makeSendRig(stub.url, SCREENSHOT_PNG);
+
+ const result = await handleBugReportSend(deps, {
+ kind: 'send',
+ zipPath,
+ metadata: SEND_METADATA,
+ includeScreenshot: true,
+ });
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+ expect(stub.requests.map((r) => `${r.method} ${r.path}`)).toEqual([
+ 'POST /api/bug-report',
+ 'PUT /upload/dest',
+ 'POST /api/bug-report',
+ 'PUT /upload/dest',
+ 'POST /api/bug-report/complete',
+ ]);
+ const body = JSON.parse(stub.requests[4]?.body.toString('utf8') ?? '') as Record<
+ string,
+ unknown
+ >;
+ expect('screenshotAssetUrl' in body).toBe(false);
+ });
+
+ test('files the report when the screenshot mint body is malformed', async () => {
+ // Guard: a 200 whose body does not parse into a mint must not proceed with
+ // undefined fields. Without the guard the throw is swallowed by the catch-all
+ // and the regression looks identical to a refused mint.
+ const stub = await startIntakeStub({ screenshotMintBody: { nope: true } });
+ const { deps, zipPath } = makeSendRig(stub.url, SCREENSHOT_PNG);
+
+ const result = await handleBugReportSend(deps, {
+ kind: 'send',
+ zipPath,
+ metadata: SEND_METADATA,
+ includeScreenshot: true,
+ });
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+ // Mint attempted, no PUT followed it.
+ expect(stub.requests.map((r) => `${r.method} ${r.path}`)).toEqual([
+ 'POST /api/bug-report',
+ 'PUT /upload/dest',
+ 'POST /api/bug-report',
+ 'POST /api/bug-report/complete',
+ ]);
+ });
+
+ test('refuses a screenshot upload URL that is not https', async () => {
+ // The same transport gate the bundle's minted URL gets: a compromised or
+ // misconfigured intake must not be able to downgrade this PUT to cleartext.
+ const stub = await startIntakeStub({
+ screenshotMintBody: {
+ uploadUrl: 'http://insecure.example.invalid/upload',
+ assetUrl: 'https://uploads.example.invalid/asset/dest',
+ headers: {},
+ },
+ });
+ const { deps, zipPath } = makeSendRig(stub.url, SCREENSHOT_PNG);
+
+ const result = await handleBugReportSend(deps, {
+ kind: 'send',
+ zipPath,
+ metadata: SEND_METADATA,
+ includeScreenshot: true,
+ });
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+ // No cleartext PUT was issued anywhere in the sequence.
+ expect(stub.requests.some((r) => r.path.includes('insecure'))).toBe(false);
+ const body = JSON.parse(stub.requests[3]?.body.toString('utf8') ?? '') as Record<
+ string,
+ unknown
+ >;
+ expect('screenshotAssetUrl' in body).toBe(false);
+ });
+
+ test('does not upload the screenshot when the reporter did not include it', async () => {
+ // The consent gate. main still holds the capture for this window, so without
+ // the gate an unchecked screenshot would be uploaded and embedded anyway.
+ const stub = await startIntakeStub();
+ const { deps, zipPath } = makeSendRig(stub.url, SCREENSHOT_PNG);
+
+ const result = await handleBugReportSend(deps, {
+ kind: 'send',
+ zipPath,
+ metadata: SEND_METADATA,
+ includeScreenshot: false,
+ });
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+ // Bundle mint + bundle PUT + completion. No screenshot mint, no screenshot PUT.
+ expect(stub.requests).toHaveLength(3);
+ const body = JSON.parse(stub.requests[2]?.body.toString('utf8') ?? '') as Record<
+ string,
+ unknown
+ >;
+ expect('screenshotAssetUrl' in body).toBe(false);
+ });
+
+ test('does not upload the screenshot when consent is absent (list retry)', async () => {
+ // Fail-closed: an omitted flag must behave like an explicit false.
+ const stub = await startIntakeStub();
+ const { deps, zipPath } = makeSendRig(stub.url, SCREENSHOT_PNG);
+
+ const result = await handleBugReportSend(deps, {
+ kind: 'send',
+ zipPath,
+ metadata: SEND_METADATA,
+ });
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+ expect(stub.requests).toHaveLength(3);
+ });
+
+ test('still files the report when the screenshot mint is refused', async () => {
+ // The expected answer from an intake deployed before it learned the image
+ // content type, and the load-bearing best-effort contract: a screenshot is
+ // never worth losing a report over, and the bundle has already landed.
+ const stub = await startIntakeStub({ screenshotMintStatus: 400 });
+ const { deps, zipPath } = makeSendRig(stub.url, SCREENSHOT_PNG);
+
+ const result = await handleBugReportSend(deps, {
+ kind: 'send',
+ zipPath,
+ metadata: SEND_METADATA,
+ includeScreenshot: true,
+ });
+
+ expect(result).toEqual({ ok: true, reference: 'OK-1042' });
+ // No screenshot PUT was attempted, and completion still ran.
+ expect(stub.requests.map((r) => `${r.method} ${r.path}`)).toEqual([
+ 'POST /api/bug-report',
+ 'PUT /upload/dest',
+ 'POST /api/bug-report',
+ 'POST /api/bug-report/complete',
+ ]);
+ const body = JSON.parse(stub.requests[3]?.body.toString('utf8') ?? '') as Record<
+ string,
+ unknown
+ >;
+ expect('screenshotAssetUrl' in body).toBe(false);
+ });
+});
+
describe('handleBugReportSend — upload happy path', () => {
test('runs mint, direct PUT with verbatim signed headers, and completion, returning the reference', async () => {
const stub = await startIntakeStub();
diff --git a/packages/desktop/src/main/ipc/bug-report.ts b/packages/desktop/src/main/ipc/bug-report.ts
index b9912b47d..e6c4c6355 100644
--- a/packages/desktop/src/main/ipc/bug-report.ts
+++ b/packages/desktop/src/main/ipc/bug-report.ts
@@ -83,6 +83,18 @@ export interface OkBugReportSendRequest {
/** Zip produced by a prior `create` — the exact file the user reviewed is what uploads. */
zipPath: string;
metadata: OkBugReportSendMetadata;
+ /**
+ * Whether the bundle contains the app screenshot, derived by the renderer from
+ * the bundle's own file inventory. Gates the separate screenshot upload that
+ * embeds the picture inline in the ticket.
+ *
+ * This has to be carried explicitly because `create` owns the consent decision
+ * and `send` is a separate operation that cannot see it: main still holds the
+ * capture for the window, so without this gate a reporter who unchecked the
+ * screenshot would have it uploaded anyway. Fail-closed — absent means no
+ * upload, which is also what a list retry in a later session gets.
+ */
+ includeScreenshot?: boolean;
}
export interface OkBugReportCrashAckRequest {
@@ -433,6 +445,14 @@ export interface BugReportSendDeps {
* transport omit it).
*/
sidecar?: BugReportSendSidecarHooks;
+ /**
+ * Main-owned PNG bytes of the screenshot captured when the report dialog
+ * opened, uploaded as its own Linear asset so the ticket embeds it inline.
+ * Returns null when nothing was captured, when the reporter opted out, or on a
+ * list retry in a later session. Absent (or null) simply means the ticket files
+ * without the inline image.
+ */
+ screenshotPngBytes?: () => Buffer | null;
}
/**
@@ -451,6 +471,15 @@ const MINT_TIMEOUT_MS = 30_000;
const PUT_TIMEOUT_MS = 120_000;
const COMPLETE_TIMEOUT_MS = 30_000;
+// The screenshot upload gets its own, much tighter ceilings rather than
+// inheriting the bundle's. The bundle's 120s PUT allowance exists for a
+// multi-megabyte zip on a bad connection; the screenshot is one PNG of one
+// screen, and it is best-effort. Reusing 120s would mean a hung screenshot
+// upload silently delays the user's report by two minutes to add a nicety, which
+// inverts the priority. Give up quickly instead and file the report.
+const SCREENSHOT_MINT_TIMEOUT_MS = 10_000;
+const SCREENSHOT_PUT_TIMEOUT_MS = 20_000;
+
/**
* Ceiling on the zip size `send` will buffer into main-process memory for the
* PUT. Real bundles sit in the tens of MB (the log/span sinks are size-capped)
@@ -545,6 +574,7 @@ function isSendRequest(request: unknown): request is OkBugReportSendRequest {
if (typeof request !== 'object' || request === null) return false;
const r = request as Record<string, unknown>;
if (r.kind !== 'send' || typeof r.zipPath !== 'string') return false;
+ if (r.includeScreenshot !== undefined && typeof r.includeScreenshot !== 'boolean') return false;
if (typeof r.metadata !== 'object' || r.metadata === null) return false;
const m = r.metadata as Record<string, unknown>;
return (
@@ -619,6 +649,93 @@ type BugReportUploadOutcome =
| { ok: true; reference: string }
| { ok: false; reason: string; cause?: unknown };
+/**
+ * Trace a skipped screenshot and return null in one expression. Every exit from
+ * `uploadScreenshotAsset` is a non-failure (the report still files), but it must
+ * leave a trace: a screenshot that silently vanishes is indistinguishable from
+ * one that was never requested, which is how the server-side predecessor stayed
+ * broken unnoticed.
+ */
+function logScreenshotSkip(reason: string, cause?: unknown): null {
+ logIpcError({
+ event: 'ipc.error',
+ channel: 'ok:bug-report:dispatch',
+ reason: `screenshot-upload-skipped: ${reason}`,
+ handler: 'uploadScreenshotAsset',
+ ...(cause === undefined ? {} : { cause }),
+ });
+ return null;
+}
+
+/**
+ * Mint + PUT the screenshot PNG as its own Linear asset and return the asset URL
+ * for the ticket description to embed inline. Returns null on ANY failure and
+ * never throws — the caller must be able to file the report regardless.
+ *
+ * Kept separate from the bundle upload so its failures cannot be confused with
+ * the bundle's: a rejected screenshot mint must not surface as `mint-rejected`
+ * and abandon a report whose bundle already landed.
+ */
+async function uploadScreenshotAsset(
+ base: URL,
+ screenshotBytes: Uint8Array,
+ metadata: BugReportWireMetadata,
+ timeouts?: Partial<BugReportUploadTimeouts>,
+): Promise<string | null> {
+ try {
+ const mintRes = await fetch(new URL('/api/bug-report', base), {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({
+ filename: BUG_REPORT_SCREENSHOT_ZIP_NAME,
+ sizeBytes: screenshotBytes.byteLength,
+ contentType: 'image/png',
+ metadata,
+ }),
+ redirect: 'manual',
+ signal: AbortSignal.timeout(timeouts?.mintMs ?? SCREENSHOT_MINT_TIMEOUT_MS),
+ });
+ // A 400 here is the expected answer from an intake deployed before it learned
+ // the image content type, so this is a normal outcome, not an error path.
+ if (!mintRes.ok) return logScreenshotSkip(`mint responded ${mintRes.status}`);
+ const mint = parseMintResponse(await mintRes.json().catch(() => null));
+ if (mint === null) return logScreenshotSkip('mint response malformed');
+ // Same transport gate the bundle's minted URL gets: a misconfigured or
+ // compromised intake must not be able to downgrade this PUT to cleartext.
+ if (parseTransportSafeUrl(mint.uploadUrl) === null) {
+ return logScreenshotSkip('mint named a non-https upload URL');
+ }
+
+ // Re-pack into a plain ArrayBuffer-backed view: fetch's BodyInit typing
+ // rejects the ArrayBufferLike backing a Buffer carries, same trap the bundle
+ // PUT documents above.
+ const body = new Uint8Array(screenshotBytes.byteLength);
+ body.set(screenshotBytes);
+ const putRes = await fetch(mint.uploadUrl, {
+ method: 'PUT',
+ headers: { 'content-type': 'image/png', ...mint.headers },
+ body,
+ redirect: 'manual',
+ signal: AbortSignal.timeout(timeouts?.putMs ?? SCREENSHOT_PUT_TIMEOUT_MS),
+ });
+ if (
+ putRes.type === 'opaqueredirect' ||
+ putRes.status === 0 ||
+ (putRes.status >= 300 && putRes.status < 400)
+ ) {
+ return logScreenshotSkip('upload redirected');
+ }
+ if (!putRes.ok) return logScreenshotSkip(`upload responded ${putRes.status}`);
+ return mint.assetUrl;
+ } catch (err) {
+ // Offline, timeout, DNS — the bundle has already landed by this point, so the
+ // only correct move is to carry on and file the report without the inline
+ // image. Still traced: a silently dropped screenshot with no log line is the
+ // exact failure mode that hid this feature being broken for two weeks.
+ return logScreenshotSkip('transport error', err);
+ }
+}
+
/**
* Two-step client upload (mint → direct PUT → completion), keeping the zip
* bytes out of the intake function body: the endpoint mints a short-lived
@@ -632,6 +749,7 @@ async function uploadBugReport(
zipPath: string,
metadata: BugReportWireMetadata,
timeouts?: Partial<BugReportUploadTimeouts>,
+ screenshotBytes?: Uint8Array | null,
): Promise<BugReportUploadOutcome> {
const base = parseTransportSafeUrl(baseUrl);
if (base === null) {
@@ -712,11 +830,33 @@ async function uploadBugReport(
}
if (!putRes.ok) return { ok: false, reason: `upload-rejected: ${putRes.status}` };
+ // Upload the screenshot as its own Linear asset so the ticket can embed it
+ // inline. Deliberately client-side: the intake cannot read the bytes back out
+ // of the bundle it just received, because Linear serves uploaded assets
+ // behind authentication and the workspace API key does not authorize the raw
+ // asset URL. Only this process, which holds the PNG before it zips it, can
+ // supply them.
+ //
+ // Strictly best-effort and strictly after the bundle PUT: every failure path
+ // yields null and the report files exactly as it does today. A screenshot is
+ // never worth losing a report over.
+ const screenshotAssetUrl =
+ screenshotBytes === undefined || screenshotBytes === null
+ ? null
+ : await uploadScreenshotAsset(base, screenshotBytes, metadata, timeouts);
+
step = 'complete';
const completeRes = await fetch(new URL('/api/bug-report/complete', base), {
method: 'POST',
headers: { 'content-type': 'application/json' },
- body: JSON.stringify({ assetUrl: mint.assetUrl, metadata }),
+ body: JSON.stringify(
+ // Omit the key entirely rather than sending null: the intake treats the
+ // field as optional, and an older deployment that has not learned it yet
+ // strips unknown keys instead of rejecting the body.
+ screenshotAssetUrl === null
+ ? { assetUrl: mint.assetUrl, metadata }
+ : { assetUrl: mint.assetUrl, screenshotAssetUrl, metadata },
+ ),
redirect: 'manual',
signal: AbortSignal.timeout(timeouts?.completeMs ?? COMPLETE_TIMEOUT_MS),
});
@@ -930,12 +1070,28 @@ export async function handleBugReportSend(
return { ok: false, reason: 'send-failed', fallback };
}
}
+ // Consent gate first, bytes second. main holds the capture for this window
+ // regardless of what the reporter chose, so reading it without checking
+ // `includeScreenshot` would upload a screenshot the reporter declined. The flag
+ // reflects the bundle's own inventory, so it is the same decision the reporter
+ // reviewed. Absent (a list retry, or an older renderer) means no upload.
+ const screenshotBytes =
+ request.includeScreenshot === true ? (deps.screenshotPngBytes?.() ?? null) : null;
+ if (request.includeScreenshot === true && screenshotBytes === null) {
+ // Consent was given and the capture is gone — a list retry in a later session
+ // is the ordinary cause. Distinct from consent being withheld, and traced for
+ // the same reason every other skip is: a screenshot that vanishes silently is
+ // indistinguishable from one that was never asked for.
+ logScreenshotSkip('capture unavailable at send time');
+ }
+
const wireMetadata: BugReportWireMetadata = { ...metadata, ...hostFacts };
const outcome = await uploadBugReport(
deps.intakeBaseUrl,
canonicalZipPath,
wireMetadata,
deps.timeouts,
+ screenshotBytes,
);
if (outcome.ok) {
await runSidecarHook(