Pin the Clock Before You Merge an Agent Patch
Описание и применение
Патч агента использовал неявный datetime.now без часового пояса, что привело к ошибкам биллинга. Добавлен слой фиксации времени через фикстуры pytest, обеспечивающий детерминированное поведение независимо от окружения.
Задача
Agent patches that use the system clock without timezone awareness can cause incorrect billing when daylight saving changes or different environments have different timezones.
Результат
The patch now deterministically calculates billing windows regardless of environment timezone or daylight saving changes, preventing future billing errors.
Рабочий процесс
- Identify all calls to datetime.now, time.time, random, uuid4, os.listdir, locale.setlocale, and bare open in the codebase.
- Create a short seam log documenting these hits for human review.
- Define a Clock protocol and a SystemUtcClock implementation that returns timezone-aware UTC time.
- Add a FrozenClock fixture that reads ISO timestamps from a committed JSON fixture file.
- Replace calls to datetime.now in the helper with clock.now() and validate tzinfo is present.
- Add unit tests that use the FrozenClock fixture to assert deterministic window IDs.
- Ensure the fixture JSON contains required fields (id, iso, window) and is committed as data only.
- Review and approve the seam log and fixture changes before merging the agent patch.
Доказательства
The helper called datetime.now with no timezone. The agent's sandbox lived entirely in UTC. The production batch box lived in US/Eastern.
The suite must freeze every world the patch can see. Humans own that freeze for the life of the repo.
- Дата записи: 2026-09-09T12:30:09.876Z