Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions products/desktop/packages/core/src/inbox/engagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,26 @@ describe("buildBulkActionEvents", () => {
expect(events.every((e) => e.dismissal_reason === undefined)).toBe(true);
});

it("attaches only the dismissal category for dismiss", () => {
it("attaches dismissal feedback only to dismiss actions", () => {
const [dismissed] = buildBulkActionEvents({
reports: [fakeReport({ id: "a" })],
actionType: "dismiss",
surface: "toolbar",
dismissalReason: "not_relevant",
dismissalNote: "Wrong project",
});
expect(dismissed.dismissal_reason).toBe("not_relevant");
expect(dismissed).not.toHaveProperty("dismissal_note");
expect(dismissed.dismissal_note).toBe("Wrong project");

const [snoozed] = buildBulkActionEvents({
reports: [fakeReport({ id: "a" })],
actionType: "snooze",
surface: "toolbar",
dismissalReason: "not_relevant",
dismissalNote: "Wrong project",
});
expect(snoozed.dismissal_reason).toBeUndefined();
expect(snoozed.dismissal_note).toBeUndefined();
});
});

Expand Down
13 changes: 12 additions & 1 deletion products/desktop/packages/core/src/inbox/engagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface BuildBulkActionEventsInput {
bulkSize?: number;
/** Dismissal category, only meaningful for `dismiss`. */
dismissalReason?: string;
dismissalNote?: string;
}

/**
Expand All @@ -76,7 +77,14 @@ export interface BuildBulkActionEventsInput {
export function buildBulkActionEvents(
input: BuildBulkActionEventsInput,
): InboxReportActionProperties[] {
const { reports, actionType, surface, triageId, dismissalReason } = input;
const {
reports,
actionType,
surface,
triageId,
dismissalReason,
dismissalNote,
} = input;
const bulkSize = input.bulkSize ?? reports.length;
const isBulk = bulkSize > 1;
return reports.map((report) => ({
Expand All @@ -94,6 +102,9 @@ export function buildBulkActionEvents(
...(actionType === "dismiss" && dismissalReason
? { dismissal_reason: dismissalReason }
: {}),
...(actionType === "dismiss" && dismissalNote
? { dismissal_note: dismissalNote }
: {}),
}));
}

Expand Down
8 changes: 6 additions & 2 deletions products/desktop/packages/shared/src/analytics-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ export type InboxReportActionType =
| "reingest"
| "implement"
| "create_pr"
| "refund"
| "open_pr"
| "open_task"
| "copy_link"
Expand Down Expand Up @@ -937,6 +938,9 @@ export interface InboxReportActionProperties {
list_size: number;
triage_id?: string;
dismissal_reason?: string;
dismissal_note?: string;
refund_reason?: string;
refund_note?: string;
signal_id?: string;
signal_source_product?: string;
signal_source_type?: string;
Expand Down Expand Up @@ -984,7 +988,7 @@ export interface InboxReportFeedbackProperties {
}

/**
* Optional note metadata, offered only once a rating is already recorded. It
* Optional note, offered only once a rating is already recorded. It
* rides on its own event rather than re-firing {@link InboxReportFeedbackProperties}
* so sentiment stays exactly one event per rating; join back to the rating on
* `report_id`. Carries `sentiment` too so a note can be read without that join.
Expand All @@ -997,7 +1001,7 @@ export interface InboxReportFeedbackNoteProperties {
sentiment: InboxReportFeedbackSentiment;
has_pr: boolean;
surface: InboxReportActionSurface;
note_length: number;
note: string;
}

// Scout events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe("ReportFeedbackFooter", () => {
sentiment: "negative",
has_pr: false,
surface: "detail_footer",
note_length: 11,
note: "some detail",
},
);
expect(screen.getByText("Note added")).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export function useInboxBulkActions(
triageId,
bulkSize: result.totalCount,
dismissalReason: dismissal?.reason,
dismissalNote: dismissal?.note,
});
for (const event of events) {
track(ANALYTICS_EVENTS.INBOX_REPORT_ACTION, event);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { ANALYTICS_EVENTS } from "@posthog/shared";
import type { SignalReport } from "@posthog/shared/types";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { act, renderHook } from "@testing-library/react";
import type { ReactNode } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";

const mocks = vi.hoisted(() => ({
refundSignalReport: vi.fn(),
track: vi.fn(),
success: vi.fn(),
error: vi.fn(),
}));

vi.mock("@posthog/ui/features/auth/authClient", () => ({
useAuthenticatedClient: () => ({
refundSignalReport: mocks.refundSignalReport,
}),
}));

vi.mock("@posthog/ui/features/feature-flags/useFeatureFlag", () => ({
useFeatureFlag: () => true,
}));

vi.mock("@posthog/ui/shell/analytics", () => ({ track: mocks.track }));

vi.mock("@posthog/ui/primitives/toast", () => ({
toast: { success: mocks.success, error: mocks.error },
}));

import { useRefundReport } from "./useRefundReport";

const report: SignalReport = {
id: "report-1",
title: "Report one",
summary: "Summary",
status: "ready",
total_weight: 1,
signal_count: 1,
artefact_count: 0,
created_at: "2026-08-20T09:00:00Z",
updated_at: "2026-08-20T09:00:00Z",
implementation_pr_url: "https://github.com/PostHog/posthog/pull/1",
};

function createWrapper() {
const queryClient = new QueryClient({
defaultOptions: { mutations: { retry: false } },
});
return function Wrapper({ children }: { children: ReactNode }) {
return (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
};
}

describe("useRefundReport", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.refundSignalReport.mockResolvedValue({
...report,
status: "suppressed",
});
});

it("tracks the refund reason and note after a successful refund", async () => {
const { result } = renderHook(() => useRefundReport(report), {
wrapper: createWrapper(),
});

await act(async () => {
await result.current.mutation.mutateAsync({
reason: "pr_incorrect",
note: "The proposed change did not fix the issue",
});
});

expect(mocks.track).toHaveBeenCalledWith(
ANALYTICS_EVENTS.INBOX_REPORT_ACTION,
expect.objectContaining({
report_id: report.id,
action_type: "refund",
refund_reason: "pr_incorrect",
refund_note: "The proposed change did not fix the issue",
}),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
} from "@posthog/shared/types";
import { useAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
import { useReportActionTracker } from "@posthog/ui/features/inbox/hooks/useReportActionTracker";
import { toast } from "@posthog/ui/primitives/toast";
import { useMutation, useQueryClient } from "@tanstack/react-query";

Expand All @@ -20,6 +21,7 @@ export function useRefundReport(report: SignalReport) {
const client = useAuthenticatedClient();
const queryClient = useQueryClient();
const flagEnabled = useFeatureFlag(SIGNALS_PR_REFUNDS_FLAG);
const trackAction = useReportActionTracker(report);

const { canRefund, disabledReason } = computeRefundEligibility(
report,
Expand All @@ -29,7 +31,11 @@ export function useRefundReport(report: SignalReport) {
const mutation = useMutation({
mutationFn: (input: { reason: SignalReportRefundReason; note?: string }) =>
client.refundSignalReport(report.id, input),
onSuccess: () => {
onSuccess: (_updatedReport, input) => {
trackAction("refund", {
refund_reason: input.reason,
...(input.note ? { refund_note: input.note } : {}),
});
toast.success("PR refunded. The report has been archived.");
queryClient.invalidateQueries({ queryKey: inboxReportKeys.all });
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { SignalReport } from "@posthog/shared/types";
import { track } from "@posthog/ui/shell/analytics";
import { useCallback, useMemo } from "react";

/** Input bound; analytics captures only the note length, never its contents. */
export const FEEDBACK_NOTE_MAX_LENGTH = 4000;

/**
Expand Down Expand Up @@ -46,7 +45,7 @@ export function useReportFeedbackTracker(
track(ANALYTICS_EVENTS.INBOX_REPORT_FEEDBACK_NOTE, {
...base,
sentiment,
note_length: text.length,
note: text,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Free-text reviewer/refund/dismissal notes now sent verbatim to analytics

This change replaces a privacy-preserving note_length: number field with the raw note: text content in the INBOX_REPORT_FEEDBACK_NOTE event, and adds dismissal_note/refund_note free-text fields to INBOX_REPORT_ACTION. These notes are free-form text typed by desktop reviewers about customer reports (support/PR review context) and up to 4000 characters (FEEDBACK_NOTE_MAX_LENGTH), so they can contain customer PII, account details, or other sensitive business data. The removed comment at products/desktop/packages/ui/src/features/inbox/hooks/useReportFeedbackTracker.ts previously stated explicitly: "analytics captures only the note length, never its contents" — that safeguard is now gone with no redaction, scrubbing, or consent gate before the text is forwarded to the analytics pipeline (track(...) → PostHog capture, which may be replicated to data warehouses/third parties and viewed by a much broader audience than the original reviewer note).

Concretely: products/desktop/packages/ui/src/features/inbox/hooks/useReportFeedbackTracker.ts:46-50 sends note: text verbatim; products/desktop/packages/ui/src/features/inbox/hooks/useRefundReport.ts:34-37 sends refund_note: input.note; products/desktop/packages/core/src/inbox/engagement.ts:105-107 propagates dismissal_note. None of these paths apply any sanitization/redaction before the text leaves the client into the analytics event stream. Recommend either reverting to length/hash-only capture, or explicitly classifying these fields as free-text/PII in the analytics pipeline and gating their storage/visibility (e.g., excluding from broadly-replicated warehouses, redacting known PII patterns) before shipping this contract change.


Severity: medium | Confidence: 55% | React with 👍 if useful or 👎 if not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was by design

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood — since capturing the full note text is the intentional purpose of this PR (per the description: "Desktop feedback events now capture the full reviewer note"), I'll treat this as accepted/by design rather than a defect to fix in this PR. I'd still flag for the team, outside of this review, that these notes are free text potentially containing customer PII or sensitive business details, so it's worth confirming the analytics pipeline's data handling/retention policy accounts for that (e.g., PII scrubbing rules, warehouse replication scope) rather than treating it as opaque length-only telemetry going forward. No further action needed from me here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: Sensitive note contents enter telemetry

A user can now send arbitrary sensitive text into the shared analytics project by entering it in a feedback note. The same raw-text sink is added for dismissal notes in useInboxBulkActions.ts and refund notes in useRefundReport.ts; retain only non-content metadata such as note presence or length, or send the text through a dedicated access-controlled feedback channel with appropriate retention and disclosure.

});
},
[base],
Expand Down
Loading