[AZ-508] Consolidate _iso_ts_now into helpers/iso_timestamps

Batch 48 / Cycle 1 (greenfield Step 7). Closes cumulative review
batches 31-33 F2 and 28-30 F3 by replacing the duplicated private
_iso_ts_now() one-liners with a single Layer-1 helper:

  src/gps_denied_onboard/helpers/iso_timestamps.py
  iso_ts_now() -> str

Output format matches the canonical FDR _TS fixture
(YYYY-MM-DDTHH:MM:SS.ffffffZ); no FDR schema change.

Migrated call-sites (3): c7_inference/onnx_trt_ep_runtime,
c7_inference/thermal_publisher, plus the 3 c6_tile_cache callers
that previously imported from the local c6_tile_cache/_timestamp
shim (now deleted, superseded by the Layer-1 helper).

Spec drift resolved (Choose A, user-approved): spec listed 5 call
sites + +00:00 regex; on-disk reality at batch start is 3 sites +
Z-suffix matching every existing helper and the FDR _TS fixture.
Spec preamble + AC-2 regex updated in the task file; documented in
batch_48_cycle1_report.md.

Tests: 9 new AC tests (AC-1..AC-7 + Layer-1 invariant +
public-surface defensive); 216 focused tests pass including the
unmodified AZ-272 FDR schema suite and AZ-270 / AZ-507 layering
lints. Verdict: PASS (no findings).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-05-13 23:23:22 +03:00
parent f29897cb3a
commit 5441ea2017
15 changed files with 596 additions and 48 deletions
@@ -1,21 +0,0 @@
"""RFC 3339 UTC timestamp helper shared inside the c6_tile_cache component.
Single source for the FDR record envelope ``ts`` field across
``postgres_filesystem_store``, ``freshness_gate``, and
``cache_budget_enforcer`` — formerly a triplicate ``_iso_ts_now`` per
module (`cumulative_review_batches_28-30` F3). The format is wall-clock
metadata about WHEN the FDR record was emitted; producers that need a
Clock-driven payload field (e.g., ``age_seconds`` derived from an
injected clock) MUST NOT route through this helper.
"""
from __future__ import annotations
from datetime import datetime, timezone
__all__ = ["iso_ts_now"]
def iso_ts_now() -> str:
"""Return an RFC 3339 UTC timestamp with microsecond precision and a ``Z`` suffix."""
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
@@ -34,7 +34,6 @@ from dataclasses import dataclass
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Final
from gps_denied_onboard.components.c6_tile_cache._timestamp import iso_ts_now
from gps_denied_onboard.components.c6_tile_cache._types import (
TileId,
TileMetadata,
@@ -50,6 +49,7 @@ from gps_denied_onboard.components.c6_tile_cache.interface import (
TileStore,
)
from gps_denied_onboard.fdr_client.records import CURRENT_SCHEMA_VERSION, FdrRecord
from gps_denied_onboard.helpers.iso_timestamps import iso_ts_now
if TYPE_CHECKING:
from gps_denied_onboard.components.c6_tile_cache._tile_pixel_handle import (
@@ -47,7 +47,6 @@ from typing import TYPE_CHECKING, Any, Final
import psycopg
from psycopg_pool import ConnectionPool
from gps_denied_onboard.components.c6_tile_cache._timestamp import iso_ts_now
from gps_denied_onboard.components.c6_tile_cache._types import (
Bbox,
FreshnessLabel,
@@ -61,6 +60,7 @@ from gps_denied_onboard.components.c6_tile_cache.errors import (
)
from gps_denied_onboard.config.schema import ConfigError
from gps_denied_onboard.fdr_client.records import CURRENT_SCHEMA_VERSION, FdrRecord
from gps_denied_onboard.helpers.iso_timestamps import iso_ts_now
if TYPE_CHECKING:
from gps_denied_onboard.clock.interface import Clock
@@ -48,7 +48,6 @@ from psycopg_pool import ConnectionPool
from gps_denied_onboard.components.c6_tile_cache._tile_pixel_handle import (
TilePixelHandle,
)
from gps_denied_onboard.components.c6_tile_cache._timestamp import iso_ts_now
from gps_denied_onboard.components.c6_tile_cache._types import (
Bbox,
FreshnessLabel,
@@ -76,6 +75,7 @@ from gps_denied_onboard.fdr_client.records import (
CURRENT_SCHEMA_VERSION,
FdrRecord,
)
from gps_denied_onboard.helpers.iso_timestamps import iso_ts_now
from gps_denied_onboard.helpers.sha256_sidecar import (
SIDECAR_SUFFIX,
Sha256Sidecar,
@@ -46,7 +46,6 @@ from __future__ import annotations
import hashlib
import os
from collections.abc import Callable
from datetime import datetime, timezone
from pathlib import Path
from typing import TYPE_CHECKING, Any, Final, Literal
@@ -79,6 +78,7 @@ from gps_denied_onboard.fdr_client.records import (
CURRENT_SCHEMA_VERSION,
FdrRecord,
)
from gps_denied_onboard.helpers.iso_timestamps import iso_ts_now as _iso_ts_now
from gps_denied_onboard.logging import get_logger
if TYPE_CHECKING:
@@ -166,18 +166,6 @@ def _sha256_of_file(path: Path) -> str:
return digest.hexdigest()
def _iso_ts_now() -> str:
"""RFC 3339 UTC timestamp with microsecond precision and a ``Z`` suffix.
Mirrors :func:`components.c6_tile_cache._timestamp.iso_ts_now` —
consolidation into ``helpers.iso_timestamp`` is intentionally
deferred to the next cross-component hygiene pass (peer imports
between c6 and c7 would violate layer-2 horizontal-import etiquette
documented in ``module-layout.md``).
"""
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
# ----------------------------------------------------------------------
# Runtime.
@@ -53,7 +53,6 @@ from __future__ import annotations
import threading
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Protocol, runtime_checkable
from gps_denied_onboard._types.thermal import ThermalState
@@ -65,6 +64,7 @@ from gps_denied_onboard.fdr_client.records import (
CURRENT_SCHEMA_VERSION,
FdrRecord,
)
from gps_denied_onboard.helpers.iso_timestamps import iso_ts_now as _iso_ts_now
from gps_denied_onboard.logging import get_logger
if TYPE_CHECKING:
@@ -340,11 +340,6 @@ def _default_safe_snapshot(measured_at_ns: int) -> ThermalState:
)
def _iso_ts_now() -> str:
"""RFC 3339 UTC timestamp with microsecond precision and ``Z`` suffix."""
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
class _JtopSource:
"""``jtop`` (jetson-stats) thermal source — Tier-2 production path.
@@ -22,6 +22,7 @@ from gps_denied_onboard.helpers.imu_preintegrator import (
ImuPreintegrator,
make_imu_preintegrator,
)
from gps_denied_onboard.helpers.iso_timestamps import iso_ts_now
from gps_denied_onboard.helpers.lightglue_runtime import (
LightGlueConcurrentAccessError,
LightGlueRuntime,
@@ -83,6 +84,7 @@ __all__ = [
"adjoint",
"exp_map",
"is_valid_rotation",
"iso_ts_now",
"log_map",
"make_imu_preintegrator",
"matrix_to_se3",
@@ -0,0 +1,33 @@
"""UTC ISO-8601 timestamp helper (E-CC-HELPERS / AZ-264 / AZ-508).
Single Layer-1 source for the wall-clock string used in the FDR record
``ts`` envelope across c6_tile_cache and c7_inference. Consolidates what
used to be a private ``_iso_ts_now`` one-liner repeated per module.
The output format is locked to RFC 3339 / ISO 8601 UTC with microsecond
precision and a ``Z`` suffix, matching the canonical FDR ``ts`` fixture
in ``tests/unit/test_az272_fdr_record_schema.py`` (``_TS =
"2026-05-11T00:00:00.000000Z"``) and the format produced by the three
existing local helpers this module replaces. Changing the format would
alter FDR record bit-shape and is explicitly out of scope for AZ-508.
Producers that need a Clock-injected payload field (e.g.
``age_seconds`` derived from an injected wall-clock for testability)
MUST NOT route through this helper — it is purely metadata about WHEN
the FDR record envelope itself was emitted.
"""
from __future__ import annotations
from datetime import datetime, timezone
__all__ = ["iso_ts_now"]
def iso_ts_now() -> str:
"""Return an RFC 3339 UTC timestamp with microsecond precision and a ``Z`` suffix.
Format: ``YYYY-MM-DDTHH:MM:SS.ffffffZ`` (fixed-width, lexicographically
monotonic under a non-decreasing wall clock).
"""
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")