Repository navigation
fix(audit): keep inclusive time bounds precise across ISO timestamp forms (#3555) - #3573
developerjillur wants to merge 8 commits into
Conversation
Exercise all five shared readers and JSON/CSV export on real temporary SQLite. RED: 48 failed, 21 passed before production changes.
Serialize details when cloning read rows into writer fixtures, and pin list pagination and legacy invalid-bound behavior. Final tests on original production source: 49 failed, 24 passed; fixed source: 73 passed.
Pad optional UTC-Z fractions in read-only SQL and normalize bounds with the existing UTC helper. Retain indexable raw-second ranges and legacy malformed-bound behavior without rewriting hash-chain data. Regression suite: 73 passed; audit neighbors: 116 passed. Original-source mutation: 49 failed, 24 passed.
|
merge-train: ejected from this batch. It rides the next train once fixed. The backend fix itself is solid. Reverting The calendar day drill-down now drops events in the last second of the day. Two ways to close it:
Smaller, and mechanical: Your next push removes the |
… bounds An audit end_time with a time part and no fraction now covers the end of the smallest unit it states: T23:59:59Z through :59.999999, T23:59Z through 23:59:59.999999, T23Z likewise. The calendar day drill-down sends <day>T23:59:59Z, so it keeps the last second of the day again. For Z-suffixed bounds this matches the earlier raw string comparison; for spellings such as +00:00 or no suffix that comparison was imprecise, which is what Abilityai#3555 fixes, so they follow the same rule rather than the old result. Date-only bounds, bounds with a fraction and all lower bounds stay exact instants. An offset bound at the edge of the date range (for example 0001-01-01T00:00:00+01:00) raises OverflowError when converted to UTC. Catch it with ValueError so the request keeps the legacy string comparison instead of returning a 500. The normalized bound is now built with isoformat(timespec="microseconds"): strftime("%Y") does not zero-pad years below 1000 on Linux, which broke the fixed-width slices for bounds such as 0999-01-01T00:00:00Z. Tests cover the day window through the readers and the real list and export routes, hour, minute and second upper bounds, date-only and fractional bounds, lower bounds, offset spellings, years before 1000 and the edge offset bounds on every audit read route. The audit-trail flow doc states the rule and that exports sharing a whole-second boundary can overlap.
|
Thanks, both points were right. An upper bound with a time part and no fraction now covers the end of the unit it states. Offset bounds outside the date range no longer raise The bound text is now built with Tests cover the day window through the list and export routes, hour, minute and second bounds, years before 1000 and the edge offsets, and I ran them in Python 3.13 on Linux as well. Could a maintainer remove the |
…time-bounds # Conflicts: # tests/registry.json
|
✅ Nightly unit-suite clean when this PR is merged into |
…time-bounds # Conflicts: # tests/registry.json
…time-bounds # Conflicts: # tests/registry.json
|
Closing this for now as part of a cleanup of my older pending contributions. Thank you for your time and feedback. |
Description
Audit time filters compare stored timestamps as text. A fractional event such as
2026-10-11T10:30:52.741692Zsorts before the whole-second bound2026-10-11T10:30:52Z, so an inclusivestart_timedrops events in its first second, and a whole-secondend_timeincludes events after it.Valid bounds are now normalized to UTC with the existing
to_utc_isohelper and compared against a read-only expression that pads the stored UTC-Z fraction to six digits. A coarse range on the rawtimestampcolumn stays in the query so the index is still used. Stored timestamps and hash-chain fields are never rewritten. Malformed bounds keep their old raw-string comparison; this does not add API validation.The fix is in the shared filter used by list, count, stats, calendar and heatmap, so JSON and CSV export pick it up too. Other filters, ordering, pagination and admin checks are unchanged. The existing audit-trail flow doc now states the bound semantics.
Related Issue
Fixes #3555
Journey Impact
Journey Impact: none: this corrects the existing admin audit time-window query and does not add or extend a journey in tests/journeys/catalog.yaml.
Type of Change
Testing
dev; details below)tests/unit/test_3555_audit_time_bounds.py(73 cases) uses the realaudit_logtable andPlatformAuditOperationson a temporary SQLite database. It also mounts the actual audit router in-process with the realrequire_adminfor JSON/CSV export, list paging and non-admin rejection. Windows cover whole-second, short-fraction and microsecond stored rows, offset bounds and exact microsecond matches.src/backend/db/audit.py.tests/unit/test_847_audit_dashboard.py,tests/unit/test_audit_chain_edges.py) andtests/unit/test_2338_journey_catalog.py, merged locally onto the currentdev(474e00c): 167 passed.devbecause this environment has pyjwt 2.15.1 and the image pins 2.14.0.tests/lint_sys_modules.pyandtests/lint_root_test_placement.pypass.||concatenation on SQLite and PostgreSQL, and SQLiteEXPLAINstill searchesidx_audit_log_timestamp. I did not run it against a live PostgreSQL.Mutation: with
src/backend/db/audit.pyreplaced by thedevversion,test_3555_all_readers_use_inclusive_instants(45 of 60 cases), bothtest_3555_export_uses_real_time_filtered_rowscases,test_3555_other_filters_and_pagination_are_preservedandtest_3555_list_route_keeps_count_and_page_consistentfail: 49 failed, 24 passed. The fixed file was then restored byte-identical.Checklist
No running Trinity instance, live PostgreSQL, enterprise module, agent or model call was used.