core.telemetry¶
Point-in-time quality telemetry: snapshot computation and persistence.
Overview¶
Collects aggregate statistics on feature quality, prediction confidence,
reject rates, and class distributions. Stores only numerical summaries;
never raw content.
TelemetryStore is implemented as a slotted dataclass and keeps the
same constructor argument (store_dir).
TelemetrySnapshot¶
| Field | Type | Description |
|---|---|---|
timestamp |
datetime |
When the snapshot was computed |
user_id |
str \| None |
Scoped user (None = global) |
window_start |
datetime \| None |
Earliest bucket in the window |
window_end |
datetime \| None |
Latest bucket in the window |
total_windows |
int |
Number of prediction windows |
feature_missingness |
dict[str, float] |
Fraction missing per feature |
confidence_stats |
ConfidenceStats \| None |
mean, median, p5, p95, std |
reject_rate |
float |
Fraction of rejected predictions |
mean_entropy |
float |
Mean prediction entropy |
class_distribution |
dict[str, float] |
Fraction per class |
schema_version |
str |
Feature schema version |
suggestions_per_day |
int |
Number of suggestions surfaced on the snapshot's day (default 0) |
compute_telemetry¶
from taskclf.core.telemetry import compute_telemetry
snapshot = compute_telemetry(
features_df,
labels=predicted_labels,
confidences=confidence_array,
core_probs=probability_matrix,
user_id="user-1",
)
TelemetryStore¶
Append-only JSONL store. One file per user (or global).
from taskclf.core.telemetry import TelemetryStore
store = TelemetryStore("artifacts/telemetry")
store.append(snapshot)
recent = store.read_recent(10, user_id="user-1")
in_range = store.read_range(start_dt, end_dt)
File layout:
SuggestionTracker¶
In-memory counter of suggestion events grouped by calendar date. Implements the decision-#4 guardrail: a loaded model must produce at least one suggestion per active day.
from datetime import datetime, timezone
from taskclf.core.telemetry import SuggestionTracker
tracker = SuggestionTracker()
# Record a suggestion event
tracker.record(datetime.now(tz=timezone.utc))
# Query the count
count = tracker.count_for_date("2026-03-28")
# End-of-day check (logs a warning if zero suggestions with a loaded model)
tracker.check_zero_suggestions("2026-03-28", model_loaded=True)
| Method | Description |
|---|---|
record(ts) |
Increment the suggestion count for the date derived from ts |
count_for_date(date_str) |
Return the count for a YYYY-MM-DD date string |
check_zero_suggestions(date_str, *, model_loaded) |
Log a warning if model_loaded is True and count is 0 |
taskclf.core.telemetry
¶
Point-in-time quality telemetry: collection and persistence.
Stores only aggregate statistics -- never raw content.
ConfidenceStats
¶
TelemetrySnapshot
¶
Bases: BaseModel
Point-in-time quality snapshot of a prediction window.
Source code in src/taskclf/core/telemetry.py
TelemetryStore
dataclass
¶
Append-only JSONL store for telemetry snapshots.
Source code in src/taskclf/core/telemetry.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
append(snapshot)
¶
Append a snapshot to the appropriate JSONL file.
Returns:
| Type | Description |
|---|---|
Path
|
Path of the file written to. |
Source code in src/taskclf/core/telemetry.py
read_recent(n=10, *, user_id=None)
¶
Read the last n snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Maximum number of snapshots to return. |
10
|
user_id
|
str | None
|
Scope to a specific user ( |
None
|
Returns:
| Type | Description |
|---|---|
list[TelemetrySnapshot]
|
List of :class: |
Source code in src/taskclf/core/telemetry.py
read_range(start, end, *, user_id=None)
¶
Read snapshots whose timestamp falls within [start, end].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
datetime
|
Inclusive lower bound. |
required |
end
|
datetime
|
Inclusive upper bound. |
required |
user_id
|
str | None
|
Scope to a specific user ( |
None
|
Returns:
| Type | Description |
|---|---|
list[TelemetrySnapshot]
|
Matching snapshots ordered by timestamp. |
Source code in src/taskclf/core/telemetry.py
SuggestionTracker
dataclass
¶
In-memory counter of suggestion events grouped by calendar date.
Used to enforce the decision-#4 guardrail: a loaded model must
produce at least one suggestion per active day. The tray or
online loop calls :meth:record for each non-rejected prediction
surfaced to the user. At end-of-day (or on shutdown),
:meth:check_zero_suggestions logs a warning if the count is zero.
Source code in src/taskclf/core/telemetry.py
record(ts)
¶
count_for_date(date_str)
¶
check_zero_suggestions(date_str, *, model_loaded)
¶
Log a warning if model_loaded and zero suggestions were recorded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_str
|
str
|
Calendar date to check ( |
required |
model_loaded
|
bool
|
Whether a model was loaded during the day. |
required |
Source code in src/taskclf/core/telemetry.py
compute_telemetry(features_df, *, labels=None, confidences=None, core_probs=None, user_id=None, reject_label=MIXED_UNKNOWN)
¶
Compute a telemetry snapshot from features and prediction outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features_df
|
DataFrame
|
Feature DataFrame (one row per bucket). |
required |
labels
|
Sequence[str] | None
|
Predicted labels (post-reject). |
None
|
confidences
|
ndarray | Sequence[float] | None
|
|
None
|
core_probs
|
ndarray | None
|
Full probability matrix |
None
|
user_id
|
str | None
|
Optional user to scope the snapshot. |
None
|
reject_label
|
str
|
Label used for rejected predictions. |
MIXED_UNKNOWN
|
Returns:
| Type | Description |
|---|---|
TelemetrySnapshot
|
A populated :class: |
Source code in src/taskclf/core/telemetry.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |