#107040·posthog

feat(signals): expose inbox ranking scores to staff on the signal report API

Author: andrewm4894Created Sep 25, 2026Updated Sep 25, 2026
Labelsself-driving

Context

Inbox ranking serving has three layers on master and a fourth in review:

  • #106137 added the ranking_score artefact (RankingScore in products/signals/backend/artefact_schemas.py): one row per scoring pass, a results map keyed <model_name>@<model_version>, and a served_key that names exactly one scored result.
  • #106460 publishes the serving manifest, and #106765 added score_reports, which writes those artefacts.
  • #106907 (issue #106847) adds the sweep that calls score_reports on a schedule. It also hides ranking_score rows from the artefact log endpoint and from artefact_count.

When the sweep runs, the scores are in Postgres, but no API returns them. This issue adds one read-only field to the signal report API so that staff can read the served score for a report through the API and the MCP inbox tools while we dogfood the model.

It also lets staff see the raw ranking_score rows in the report's activity log.

No frontend change. No frontend code changes, and non-staff users never see a score or a row.

Change

1. Prefetch the latest ranking_score artefact (products/signals/backend/views.py)

Add a Prefetch in _prefetch_signal_report_priority_artefacts, the same shape as prefetched_repo_selection_artefacts: type=RANKING_SCORE, order_by("-created_at")[:1], to_attr="prefetched_ranking_score_artefacts". The slice matters. The sweep appends a row on every new report vector and every new manifest version, so a report collects many rows.

Only add the prefetch when the request user is staff. Non-staff requests must not pay for the extra query.

2. Serializer field (products/signals/backend/serializers.py, SignalReportSerializer)

ranking = serializers.SerializerMethodField(...), read-only, with help_text, and an @extend_schema_field with a small serializer, so the generated types and MCP schema are typed and not any.

get_ranking returns None when:

  • the request user is not staff (self.context["request"].user.is_staff), or there is no request in the context;
  • the report has no ranking_score artefact;
  • the content does not validate as RankingScore (log once and return None; never raise from a serializer).

Otherwise it returns only the served entry, results[served_key]:

json
{
  "model_key": "report_embeddings@2026-09-24",
  "scored_at": "...",
  "manifest_version": "...",
  "scores": {"pr_created": 0.31, "pr_merged": 0.07},
  "readable_heads": ["pr_created", "pr_merged"]
}
  • scores holds every head of the served result. readable_heads lists the heads that the model's copied metadata marks readable (the per-head readability that #106460 copies from metadata.json; use the helper in products/signals/backend/ranking/model_contract.py if one fits and don't parse it a second time). Staff can then see an unreadable head, but it carries a label.
  • Challenger results never leave the backend. Pick the entry by served_key, never by position or by role scan.
  • Use the prefetched list when it exists, with the same fallback query as get_priority when it does not.

3. Staff see ranking_score rows in the artefact log

#106907 excludes SYSTEM_SCORING_ARTEFACT_TYPES from the artefact list endpoint for every user. Apply that exclusion to non-staff requests only, so that staff also see the raw rows in the report's activity log. Keep artefact_count excluding them for everyone, because it is a count on the inbox row and not a debugging surface. The log already renders an unknown type as a header with no body, so the frontend does not change.

4. Regenerate

hogli build:openapi. Commit the generated changes. Do not edit any frontend component.

Tests

In products/signals/backend/test/test_signal_report_api.py, create ranking_score artefacts directly as fixtures. The sweep is not needed.

  • A staff user gets the served entry, and a non-staff user gets null. Parameterize both on list and detail.
  • With two rows, the newest wins. With a challenger result present, the served entry comes back and the challenger does not.
  • A report with no score gives null.
  • The artefact list endpoint returns ranking_score rows to staff and hides them from non-staff. artefact_count excludes them for both.
  • The list endpoint for a staff user runs no extra query per report (assertNumQueries stays flat as report count grows).

Out of scope

  • Any frontend display, in the inbox or in the report detail.
  • Ordering or filtering by score, and a cached score column on the report row. That work comes later, after the shadow read.
  • Stamping model rank or scores onto impressions.
  • A per-team feature flag. This field is staff-only by design.

Sequencing

Items 1, 2 and 4 have no code dependency on #106907. The schema from #106137 is enough, and the tests use fixture artefacts. Item 3 changes the exclusion that #106907 adds, and #106907 also edits views.py, models.py and test_signal_report_api.py, so start from master after it merges, or rebase onto it.