Commit 41b97a1
Fix current_state.latest_observation sort to use true recency
Fourth dogfood-surfaced bug. Within a single runtime session, multiple
record_observation calls inherit the same episode's event_at, so the
previous step_index-only sort collapsed their order to insertion order
and returned the *oldest* write as "latest_observation" — the opposite
of what the field promises.
Sort now uses (event_at, created_at, step_index) with reverse=True:
- event_at is the primary semantic signal (when the observed event
happened) and wins when it genuinely differs across observations.
- created_at varies per write regardless of episode reuse, so it
breaks event_at ties correctly within a session.
- step_index remains the final tiebreak so trajectory-based ingestion
(where step_index IS the authoritative ordering) keeps working.
Regression test seeds three record_observation calls with 10ms spacing
and asserts the third one surfaces as latest_observation. 14 tests
pass (was 13) — the full pass now covers all four dogfood findings.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent f38d43b commit 41b97a1
2 files changed
Lines changed: 37 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
348 | 359 | | |
349 | | - | |
350 | | - | |
| 360 | + | |
| 361 | + | |
351 | 362 | | |
352 | 363 | | |
353 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
329 | 353 | | |
330 | 354 | | |
331 | 355 | | |
| |||
0 commit comments