# Feedback reports

Signed-in people report a problem from the web or the app, with annotated screenshots; staff triage and reply in the admin Feedback inbox.

## What it does [#what-it-does]

A Feedback Report is what a signed-in User sends with **Report a problem**: a title (3–120 characters), a description (10–5,000) and up to five screenshots (5 MB each, 9 MB together). It records the page path, the platform, the app version, a short user agent, the interface language and, when it is sent from an error screen, the error tracker's event id and the failed call's request id. A report belongs to its reporter, not to an Organization; the Active Organization at the time is kept for context only.

Staff (platform roles `admin` and `support`) work through reports in `/admin/feedback`: one tab per status (`new`, `triaged`, `fixed`, `closed`), a table, and a panel with the screenshots, the technical fields, a link to the reporter in the user admin (for admins), a link to the event in the error tracker, the status and assignee, the replies and a **Create GitHub issue** button.

## Where people report [#where-people-report]

- **Web:** the user menu ("Report a problem") and the error screen. The error screen reports the error to the tracker first ([Error reporting](/docs/architecture/observability)), so the dialog opens with the event id; the request id is the `x-request-id` of an API call that failed in the last minute.
- **App:** Settings, the error screen and, behind a setting, shaking the phone (see [Mobile](#mobile)).

The dialog and its image tools load on the first open (`feedback.launcher.tsx`), the annotation editor only when a screenshot is opened (`feedback.dialog.tsx`); both are the declared dynamic imports of W7 in [web conventions](/docs/development/web-conventions).

## Screenshots and annotation [#screenshots-and-annotation]

Images are added by choosing files, pasting, or **Capture screen**: the dialog hides, the page repaints (two animation frames), `getDisplayMedia` asks for the current tab (`preferCurrentTab`), one frame is drawn to a canvas and the stream's tracks stop. Every image is downscaled in the browser to at most 2,000 px on its longer side and re-encoded as WebP (JPEG where the browser has no WebP encoder), which also drops metadata such as a photo's location.

The annotation editor draws arrows, boxes and text in five colors, and a blur that pixelates the area. Everything is burned into the exported image: the original pixels under a blur never leave the browser. Undo removes the last mark. On the keyboard, the focused canvas moves a cursor with the arrow keys (Shift for bigger steps), Enter sets the start and then the end of a mark, Escape cancels it and Ctrl+Z or ⌘Z undoes.

The server trusts none of this: it reads each image's type and size from its bytes (PNG, JPEG or WebP signatures and headers), refuses anything else, anything over 2,000 px, 5 MB or 9 MB in total, and stores the images privately under `feedback/<report id>/`. That prefix is outside every Organization's `orgs/<id>/`, so the [files gateway](/docs/features/files) never lists or serves them; the inbox streams one image at a time to staff with `feedback.read` (`feedback.inbox.attachment` returns the file itself, never a URL).

## Procedures [#procedures]

| Procedure                    | Who                                                          | Failures                                                                                                                           |
| ---------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| `feedback.submit`            | Any signed-in User                                           | `INPUT_VALIDATION` (`image_type`, `image_size`, `image_total`, `image_dimensions`), `TOO_MANY_REQUESTS` (5 reports per 10 minutes) |
| `feedback.inbox.list`        | Staff with `feedback.read`                                   | —                                                                                                                                  |
| `feedback.inbox.detail`      | Staff with `feedback.read`                                   | `NOT_FOUND`                                                                                                                        |
| `feedback.inbox.attachment`  | Staff with `feedback.read`                                   | `NOT_FOUND`                                                                                                                        |
| `feedback.inbox.assignees`   | Staff with `feedback.read`                                   | —                                                                                                                                  |
| `feedback.inbox.update`      | Staff with `feedback.triage` (audited as `feedback.updated`) | `NOT_FOUND`, `BAD_REQUEST` (assignee may not triage)                                                                               |
| `feedback.inbox.reply`       | Staff with `feedback.reply`                                  | `NOT_FOUND`                                                                                                                        |
| `feedback.inbox.createIssue` | Staff with `feedback.triage`                                 | `BAD_REQUEST` (not configured), `CONFLICT` (already linked), `INTERNAL_SERVER_ERROR` (GitHub refused)                              |

The inbox procedures are `platformProcedure({ feedback: [action] })`: the platform role is re-read from the database and must grant the action (`admin` and `support` hold `feedback.read`, `triage` and `reply`; ADR-0016), then they run as the system under their own reason, `feedback-inbox`. Reports can be assigned to anyone whose platform role grants `feedback.triage`. The `/admin/feedback` screen and its navigation item open to the same people.

The limit counts valid reports in the `rate_limit` table (the same rolling window as the MCP and error-tunnel limits, reason `feedback.rate-limit`), so it holds across Cloudflare locations and on a Node host.

## Data and isolation [#data-and-isolation]

Three tables with row-level security:

- `feedback_report`: a reporter reads and inserts only their own rows, and only a fresh report (status `new`, no assignee, no issue, the Active Organization only while they are a Member of it). Status, assignee and issue are written by the inbox only.
- `feedback_attachment`: the reporter's own images; the key must sit under `feedback/<report id>/`.
- `feedback_message`: replies, readable by the reporter, written by the inbox only.

`app_tenant` holds no UPDATE or DELETE on any of them. Children reference the report with `(report_id, user_id)`, so they always belong to the same reporter, and deleting a User deletes their reports.

## Replies [#replies]

A reply is stored with its push notices in one transaction (`feedback-reply:<message id>` rows in the push outbox, one per signed-in app session, sent by the push job like reminders), then emailed after the commit in the report's language (`feedbackReplyEmail` in `packages/email`, en, de, fr and pt-BR). An email is never retried; a refused one leaves the reply saved and the admin sees "the email could not be sent". The push only says that there is a reply; the reply itself travels by email.

## GitHub issue [#github-issue]

"Create GitHub issue" appears when `FEEDBACK_GITHUB_REPO` (`owner/repo`) and `FEEDBACK_GITHUB_TOKEN` (a token that may create issues there) are both set. The issue carries the title and description with e-mail addresses, credentials and CPFs removed, the technical fields and a link back to the report in the admin. It never carries images or the reporter's identity. One POST with a 10-second timeout and no retry; a report links at most one issue.

## Link to the error tracker [#link-to-the-error-tracker]

The panel links an event as `<dashboard>/projects/<project id>/events/sentry/<event id>` (Rustrak's address for an event by its SDK id). The dashboard is `ERROR_REPORTING_DASHBOARD_URL`, or `ERROR_REPORTING_URL` when only that is set; the project id is the last path segment of `ERROR_REPORTING_DSN`. Without either, the panel shows the event id as text.

## Retention [#retention]

The cron tick's `feedbackRetention` job deletes the images of reports closed 180 days ago (`FEEDBACK_IMAGE_RETENTION_DAYS`), at most 20 reports per tick: objects for good (not into the files trash), then the attachment rows, and it stamps `images_purged_at`. Reopening a report stops the clock; deleted images stay deleted. The report text stays until the reporter's account is deleted.

## Mobile [#mobile]

The app reports through the same `feedback.submit`, sending PNG or JPEG images as base64 (React Native form data does not carry a Blob reliably), with platform `ios` or `android`, the native app version and the route path without ids or tokens.

- **Entry points:** a "Report a problem" row in Settings, the error screen (the route boundary reports the error first; `reportError` in `packages/error-reporting/src/native.ts` returns and remembers the event id, and the RPC link keeps the request id of the last failed call), and shaking the phone.
- **Shake to report** (`expo-sensors` accelerometer) is a switch in Settings. Its default is the `feedback.shake` flag (off): turn the flag on for staff and beta builds; a person's own choice always wins.
- **The sheet** is a full-screen modal (a page sheet's swipe gesture took the annotator's drawing touches). "Capture screen" hides the sheet, captures the screen with `react-native-view-shot`, and opens the annotator.
- **The annotator** draws with `@shopify/react-native-skia`: arrow, box, text, blur, five colors, undo. The export draws the image again at most 2,000 px wide with the marks burned in; a blur pixelates the pixels under it.
- **A reply's push** is shown in the foreground for the signed-in person and opens the app; the reply itself is in the email.

`react-native-view-shot` and `expo-sensors` are native modules: a development build made before them must be rebuilt.

## Key files [#key-files]

- [`packages/api/src/features/feedback/feedback.procedures.ts`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/api/src/features/feedback/feedback.procedures.ts)
- [`packages/api/src/features/feedback/feedback.service.ts`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/api/src/features/feedback/feedback.service.ts)
- [`packages/api/src/features/feedback/feedback.images.ts`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/api/src/features/feedback/feedback.images.ts)
- [`packages/api/src/features/feedback/feedback.reply.ts`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/api/src/features/feedback/feedback.reply.ts)
- [`packages/api/src/features/feedback/feedback.jobs.ts`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/api/src/features/feedback/feedback.jobs.ts)
- [`packages/db/src/schema/feedback.ts`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/db/src/schema/feedback.ts)
- [`apps/web/src/features/feedback/feedback.dialog.tsx`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/apps/web/src/features/feedback/feedback.dialog.tsx)
- [`apps/web/src/features/feedback/feedback.annotation-model.ts`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/apps/web/src/features/feedback/feedback.annotation-model.ts)
- [`apps/web/src/features/feedback/feedback.inbox-page.tsx`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/apps/web/src/features/feedback/feedback.inbox-page.tsx)
