:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import type { SignalReportSuppressionSourceEnumApi } from 'products/signals/frontend/generated/api.schemas'
// Port of `packages/agent/packages/agent-contracts/src/dismissal-reasons.ts`. Canonical reason codes recorded when a
// report is dismissed or resolved. Values are persisted on dismissal artefacts by the backend `state`
// action – add or reorder options here only, and keep the values in sync with desktop and with
// `SIGNAL_REPORT_DISMISSAL_REASON_CHOICES` in `products/signals/backend/views.py`.
export const DISMISSAL_REASON_OPTIONS = [
{ value: 'already_fixed', label: 'Already fixed' },
{ value: 'report_unclear', label: 'Report is unclear to me' },
{ value: 'analysis_wrong', label: "Agent's analysis is wrong" },
{ value: 'wrong_repo', label: 'Agent picked the wrong repository' },
{ value: 'wontfix_intentional', label: "Won't fix - intentional behavior" },
{ value: 'wontfix_irrelevant', label: 'Not relevant to this project' },
{ value: 'other', label: 'Something else…' },
] as const
/**
* Reasons offered when a person resolves a report. `already_fixed` is also a dismiss reason on
* purpose: as a dismissal it tells the agent the report was stale when filed, and as a resolve it
* records the report as done. The person picks by which of those they want. Recurrence works the
* same on both paths — a later signal about the same issue starts a fresh report rather than
* joining this one — so the choice no longer decides whether the issue can come back.
*/
export const RESOLVE_REASON_OPTIONS = [
{ value: 'fixed_outside_posthog', label: 'Implemented manually' },
{ value: 'no_action_needed', label: 'No action needed' },
{ value: 'already_fixed', label: 'Was already fixed before this report' },
{ value: 'other', label: 'Something else…' },
] as const
export const STOP_MONITORING_REASON_OPTIONS = [
{ value: 'verified_manually', label: 'Verified manually' },
{ value: 'no_action_needed', label: 'No action needed' },
{ value: 'already_fixed', label: 'Was already fixed before this report' },
{ value: 'other', label: 'Something else…' },
] as const
/** Persisted dismiss reason (values match {@link DISMISSAL_REASON_OPTIONS}). */
export type DismissalReasonValue = (typeof DISMISSAL_REASON_OPTIONS)[number]['value']
/** Persisted feedback can include reasons that are no longer selectable in the dialog. */
export type ResolveReasonValue =
| (typeof RESOLVE_REASON_OPTIONS)[number]['value']
| (typeof STOP_MONITORING_REASON_OPTIONS)[number]['value']
| 'pr_merged'
/**
* Whether a persisted reason describes a resolve rather than a dismissal. A resolved row only shows
* a reason chip for these: a report that was dismissed, restored, then resolved by a merged PR keeps
* its old dismiss reason, and showing that on finished work would mislabel it.
*/
export function isResolveReason(value: string | null | undefined): boolean {
return (
value === 'fixed_outside_posthog' ||
value === 'verified_manually' ||
value === 'no_action_needed' ||
value === 'pr_merged' ||
value === 'already_fixed'
)
}
/** Feedback captured by the dismiss dialog and forwarded to the report state API. */
export interface DismissalFeedback {
reason: DismissalReasonValue
note: string
/** 'owner/repo' the reports should have targeted; only set when reason is 'wrong_repo'. */
correctedRepository: string | null
}
/**
* The dismissal fields of a `state`/`bulk-state` request body, so every surface maps
* {@link DismissalFeedback} to the API the same way. Spread into `{ state: 'suppressed', ... }`.
* The note is clamped to the API's 4000-character cap.
*/
export function suppressDismissalPayload(dismissal: DismissalFeedback): {
dismissal_reason: DismissalReasonValue
dismissal_note?: string
corrected_repository?: string
} {
const note = dismissal.note.trim().slice(0, 4000)
return {
dismissal_reason: dismissal.reason,
...(note ? { dismissal_note: note } : {}),
// The API rejects corrected_repository with any other reason, so the gate lives here
// rather than in every dialog that builds a DismissalFeedback.
...(dismissal.reason === 'wrong_repo' && dismissal.correctedRepository
? { corrected_repository: dismissal.correctedRepository }
: {}),
}
}
// Reason codes persisted by flows outside the two dialogs (never user-selectable there), so the
// reason chip still renders a label instead of the raw code. `refunded` is written by the PR
// refund action, which dismisses the report as part of the refund. `merged` is written by the
// report merge action, which archives each duplicate it folds into the surviving report.
// `wrong_assignee` is no longer offered: a report sent to the wrong person still holds work, so the
// person removes themselves from its reviewers with a reason instead. Older dismissals and clients
// still carry it.
const EXTRA_DISMISSAL_REASON_LABELS: Record<string, string> = {
pr_merged: 'PR already merged',
wrong_assignee: 'Wrong assignee',
refunded: 'Refunded',
merged: 'Merged into another report',
}
// Why a report nobody dismissed left the inbox, keyed by the backend's `suppression_source`.
// `dismissed` has no entry: those rows show the person's reason, or nothing when none was given.
const HELD_BACK_LABELS: Partial<Record<SignalReportSuppressionSourceEnumApi, string>> = {
safety_judge: 'Held back by safety check',
not_actionable: 'Judged not actionable',
system: 'Held back automatically',
}
/** Chip label for a suppressed report that no person or agent dismissed, or null. */
export function heldBackLabel(source: SignalReportSuppressionSourceEnumApi | null | undefined): string | null {
return source ? (HELD_BACK_LABELS[source] ?? null) : null
}
/** Human label for a persisted reason code, or the raw code if it's not a known option. */
export function dismissalReasonLabel(value: string | null | undefined): string | null {
if (!value) {
return null
}
return (
DISMISSAL_REASON_OPTIONS.find((o) => o.value === value)?.label ??
RESOLVE_REASON_OPTIONS.find((o) => o.value === value)?.label ??
STOP_MONITORING_REASON_OPTIONS.find((o) => o.value === value)?.label ??
EXTRA_DISMISSAL_REASON_LABELS[value] ??
value
)
}