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