A time-updated case history records when each predictor became observable, not merely when its final value appeared in an export.
Time-updated case histories and the observation clock
Keep three clocks separate
A support case is created at elapsed hour zero. An escalation may be effective at hour seven, entered by an agent at hour nine, and loaded into the analytical warehouse at hour eleven. Those are different times. A model run at hour eight cannot use an escalation that had not yet been recorded, even if an eventual backfill assigns it an earlier effective time. Store event time, recorded time and extraction cutoff as separate fields. A reproducible snapshot pins the extraction cutoff.
Define the observation rule first
The ledger below uses the conservative rule that a feature is available only after both its effective time and recorded time. For an action taken at hour eight, it returns the last value satisfying both conditions. That protects an offline training set from an agent note entered at hour nine. If the live serving system genuinely receives an earlier signal, document that delivery path and test it against logs; do not infer availability from a corrected historical table.
Separate state from outcome
A priority flag can change while a case is open. Resolution terminates the history. Do not carry an escalation update after resolution into a preceding open interval, and do not let a status transition generated by resolution predict that same resolution. A late manual correction is useful for label repair but may be unusable as a historical predictor. Landmark analysis offers a fixed prediction time when changing histories are unnecessary.
Make collisions deterministic
Two updates can share an effective hour. Choose a sequence number or a stable recorded-time rule, and flag contradictory values rather than depending on row order from a database query. A missing initial state should remain unknown unless a defensible default exists. In this teaching fixture, the initial priority is known at creation and subsequent updates are sorted by effective time and record time.
Audit coverage by age
Count how many cases have an observable priority state at each planned prediction age. If older cases have richer records simply because agents had more time to annotate them, a model trained on final values will seem better than the live system. Check availability gaps by queue and calendar month before joining a longitudinal feature table to outcomes. Interval construction consumes this vetted history.
Implementation
def state_visible_at(initial_state, updates, prediction_hour):
if prediction_hour < 0 or initial_state not in (0, 1):
raise ValueError("invalid prediction time or initial state")
previous_effective = -1
visible_state = initial_state
for effective_hour, recorded_hour, priority_state in sorted(updates):
if effective_hour < 0 or recorded_hour < 0 or priority_state not in (0, 1):
raise ValueError("invalid update")
if effective_hour == previous_effective:
raise ValueError("conflicting effective-time updates")
previous_effective = effective_hour
if effective_hour <= prediction_hour and recorded_hour <= prediction_hour:
visible_state = priority_state
return visible_state
case_updates = [(7, 9, 1), (14, 14, 0)]
assert state_visible_at(0, case_updates, 8) == 0
assert state_visible_at(0, case_updates, 10) == 1
assert state_visible_at(0, case_updates, 15) == 0Performance and operating cost
Sorting U updates costs O(U log U) time and O(U) temporary space. For repeated as-of queries, sort and validate once, then index by availability time. The expensive production task is recovering what was truly visible at the historical prediction cutoff.
Common Mistakes
- Do not use a corrected event time as proof the feature was visible in real time.
- Do not join the final case state to every prior hour.
- Do not let database row order decide between conflicting updates.
