Skip to content

Conversation

@apognu
Copy link
Contributor

@apognu apognu commented Nov 19, 2025

The false positive ratio must be computed from the latest outcome of closed cases where a rule appears, this required adding the org ID to case events, ingesting some of the case events, and performing a separate query.

A migration adds the org ID, an appropriate index and backfills the data for the case_events table.

Not tested on production data yet.


Note

Adds false-positive ratio to the rule hit table by exporting latest closed-case outcomes per rule to rule_hit_outcomes, requiring org_id on case_events and updating event creation paths.

  • Analytics queries:
    • Extend analytics.RuleHitTable with rule_id and false_positive_ratio; add FalsePositiveRatio type.
    • RuleHitTable endpoint now joins aggregated false positives from rule_hit_outcomes (latest outcome per case).
  • Data export pipeline:
    • New AnalyticsCopyCaseEvents to copy latest outcome_updated events for closed cases into rule_hit_outcomes (partitioned by org/year/month/trigger_object_type).
    • Export job now runs exportCaseEvents in parallel with other exports and watermarks via AnalyticsGetLatestRow.
    • Add WithCtesRaw to build CTEs with raw placeholders.
  • Models/DB:
    • Add OrgId uuid.UUID to models.CaseEvent, CreateCaseEventAttributes, and DB adapter; batch insert now writes org_id.
    • Migrations: add org_id column to case_events, backfill from cases, and create partial index idx_case_events_by_org on (org_id, event_type, created_at).
  • Usecases/Repositories:
    • Update all case-event creations to populate OrgId (case create/update, assign/unassign, snooze/unsnooze, comments/tags/files, decision review, SAR, screenings, rule snooze, escalate, mass update).
    • Change UpdateDecisionsWithEvents to accept orgId and propagate across callers.

Written by Cursor Bugbot for commit 30d0fe4. This will update automatically on new commits. Configure here.

@apognu apognu self-assigned this Nov 19, 2025
@apognu apognu added enhancement New feature or request go Pull requests that update Go code labels Nov 19, 2025
@apognu apognu force-pushed the feat/rule-false-positive branch 2 times, most recently from d4e3b4b to a5a7e53 Compare November 19, 2025 10:33
@apognu apognu marked this pull request as ready for review November 19, 2025 14:04

create index concurrently if not exists idx_case_events_by_org
on case_events (org_id, event_type, created_at)
where event_type in ('outcome_updated');
Copy link
Contributor

Choose a reason for hiding this comment

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

I created the index manually (⚠️ and created the org_id column and backfilled it for only outcome_updated events, so need to roll this back before deploying prod !!! ⚠️ ), so we can now test the query in prod.

@apognu apognu force-pushed the feat/rule-false-positive branch 2 times, most recently from f48fd68 to 2cf9154 Compare November 21, 2025 07:27
Copy link
Contributor

@Pascal-Delange Pascal-Delange left a comment

Choose a reason for hiding this comment

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

Makes sense like this 👍
As discussed in DM, check the limit placement, I think as it is we can lose some decisions/rules due to waterparking/pagination/limit too late.

Copy link
Contributor

@Pascal-Delange Pascal-Delange left a comment

Choose a reason for hiding this comment

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

LGTM!

@apognu apognu force-pushed the feat/rule-false-positive branch from 1d8fff4 to 30d0fe4 Compare November 24, 2025 07:51
The false positive ratio must be computed from the latest outcome
of closed cases where a rule appears, this required adding the org ID
to case events, ingesting some of the case events, and performing a
separate query.
@apognu apognu force-pushed the feat/rule-false-positive branch from 30d0fe4 to 7a8806e Compare November 24, 2025 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants