Skip to content

: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.

fix(signals): write unseen grade counts as int metadata (#96343)

Andrew Maguire3ae7a3ca6121
diff --git a/products/signals/dags/inbox_ranking/tests/test_training.py b/products/signals/dags/inbox_ranking/tests/test_training.py
index 5c7f9ab56ad4..832d4bd92847 100644
--- a/products/signals/dags/inbox_ranking/tests/test_training.py
+++ b/products/signals/dags/inbox_ranking/tests/test_training.py
@@ -21,6 +21,7 @@ from products.signals.dags.inbox_ranking.dataset.dag import LABELS_TABLE, STATE_
from products.signals.dags.inbox_ranking.training.dag import (
_delete_other_objects,
champion_object_key,
+ grade_metadata,
inbox_ranking_training_examples,
load_snapshots,
model_object_key,
@@ -524,6 +525,11 @@ def test_head_grades_report_counts_and_a_null_auc_on_a_single_class():
graded_rows(_scores(["e"]), _labels(["e"], open_count=[0]), head), head, scoring_partition="2026-08-10"
)
assert (single_class.rows, single_class.positives, single_class.auc) == (1, 0, None)
+ # Counts are ints and the null AUC is dropped: the graded asset writes these as Dagster metadata.
+ metadata = grade_metadata([grade])
+ assert metadata["open_candidate_rows"] == dagster.MetadataValue.int(2)
+ assert metadata["open_candidate_auc"] == dagster.MetadataValue.float(1.0)
+ assert "open_candidate_auc" not in grade_metadata([single_class])
@pytest.mark.parametrize(
diff --git a/products/signals/dags/inbox_ranking/training/dag.py b/products/signals/dags/inbox_ranking/training/dag.py
index 0050777f618a..05b0876f0764 100644
--- a/products/signals/dags/inbox_ranking/training/dag.py
+++ b/products/signals/dags/inbox_ranking/training/dag.py
@@ -28,6 +28,7 @@ grades the model on reports it never saw, and the two are comparable because bot
import json
import datetime
+from collections.abc import Sequence
from typing import Any
import pandas as pd
@@ -546,6 +547,20 @@ def inbox_ranking_unseen_scores(context: dagster.AssetExecutionContext) -> None:
)
+def grade_metadata(grades: Sequence[HeadGrade]) -> dict[str, dagster.MetadataValue]:
+ """One metadata entry per (head, model, metric). Counts stay ints: `MetadataValue.float` rejects them."""
+ metadata: dict[str, dagster.MetadataValue] = {}
+ for grade in grades:
+ for name, value in grade.metrics().items():
+ if value is None:
+ continue
+ key = f"{grade.head}_{grade.model_role}_{name}"
+ metadata[key] = (
+ dagster.MetadataValue.int(value) if isinstance(value, int) else dagster.MetadataValue.float(value)
+ )
+ return metadata
+
+
@dagster.asset(
name="inbox_ranking_unseen_graded",
deps=[
@@ -597,17 +612,7 @@ def inbox_ranking_unseen_graded(context: dagster.AssetExecutionContext) -> None:
for head_name, reason in skipped.items():
context.log.info(f"{head_name}: not graded, {reason}")
- context.add_output_metadata(
- {
- **{
- f"{grade.head}_{grade.model_role}_{name}": dagster.MetadataValue.float(value)
- for grade in grades
- for name, value in grade.metrics().items()
- if value is not None
- },
- "skipped_heads": dagster.MetadataValue.json(skipped),
- }
- )
+ context.add_output_metadata({**grade_metadata(grades), "skipped_heads": dagster.MetadataValue.json(skipped)})
capture_training_events(
context,
partition_key,
diff --git a/products/signals/dags/inbox_ranking/training/unseen.py b/products/signals/dags/inbox_ranking/training/unseen.py
index 127432f1e3e1..cfd1abc4925a 100644
--- a/products/signals/dags/inbox_ranking/training/unseen.py
+++ b/products/signals/dags/inbox_ranking/training/unseen.py
@@ -93,7 +93,7 @@ class HeadGrade:
# nothing the inbox could not do by sorting on age.
recency_auc: float | None
- def metrics(self) -> dict[str, float | None]:
+ def metrics(self) -> dict[str, int | float | None]:
return {
"rows": self.rows,
"positives": self.positives,