-
Notifications
You must be signed in to change notification settings - Fork 38
fix(result): normalize result artifact timestamps #928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bingran-you
wants to merge
4
commits into
main
Choose a base branch
from
codex/fix-result-schema-timestamps-528
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4a8baae
fix(result): normalize artifact timestamps
bingran-you d285ba9
fix(deps): clear pip-audit advisories
bingran-you ba7686f
fix(result): source native artifact timestamps in UTC
bingran-you 089022b
fix(deps): bump mcp for pip audit
bingran-you File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """Timestamp formatting helpers for persisted artifacts.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import UTC, datetime | ||
|
|
||
|
|
||
| def artifact_timestamp(value: datetime | None) -> str | None: | ||
| """Return a timezone-aware ISO 8601 timestamp for JSON artifacts. | ||
|
|
||
| Runtime paths should pass UTC-aware values at source. Legacy tests and | ||
| artifact repair paths may still pass naive ``datetime`` values; treat those | ||
| as already-UTC for compatibility and emit a compact ``Z`` suffix. | ||
| """ | ||
| if value is None: | ||
| return None | ||
| if value.tzinfo is None or value.tzinfo.utcoffset(value) is None: | ||
| value = value.replace(tzinfo=UTC) | ||
| else: | ||
| value = value.astimezone(UTC) | ||
| return value.isoformat().replace("+00:00", "Z") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| """Artifact timestamp serialization regressions.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from datetime import UTC, datetime, timedelta, timezone | ||
|
|
||
|
|
||
| def test_result_timestamps_are_timezone_aware_iso8601(tmp_path): | ||
| """Guards PR #928 / issue #528: result.json timestamps are UTC ISO.""" | ||
| from benchflow.rollout import _build_rollout_result | ||
|
|
||
| rollout_dir = tmp_path / "trial" | ||
| rollout_dir.mkdir() | ||
| _build_rollout_result( | ||
| rollout_dir, | ||
| task_name="t1", | ||
| rollout_name="trial-1", | ||
| agent="test", | ||
| agent_name="openhands", | ||
| model="m", | ||
| n_tool_calls=0, | ||
| prompts=[], | ||
| error=None, | ||
| verifier_error=None, | ||
| trajectory=[], | ||
| partial_trajectory=False, | ||
| rewards={"reward": 1.0}, | ||
| started_at=datetime(2026, 3, 24, 10, 0), | ||
| timing={}, | ||
| ) | ||
|
|
||
| data = json.loads((rollout_dir / "result.json").read_text()) | ||
| assert data["started_at"] == "2026-03-24T10:00:00Z" | ||
| assert data["finished_at"].endswith("Z") | ||
| assert " " not in data["finished_at"] | ||
| assert datetime.fromisoformat(data["finished_at"].replace("Z", "+00:00")) | ||
|
|
||
|
|
||
| def test_result_timestamps_normalize_offsets_to_utc(tmp_path): | ||
| """Guards PR #928 / issue #528: aware result timestamps serialize in UTC.""" | ||
| from benchflow.rollout import _build_rollout_result | ||
|
|
||
| rollout_dir = tmp_path / "trial" | ||
| rollout_dir.mkdir() | ||
| _build_rollout_result( | ||
| rollout_dir, | ||
| task_name="t1", | ||
| rollout_name="trial-1", | ||
| agent="test", | ||
| agent_name="openhands", | ||
| model="m", | ||
| n_tool_calls=0, | ||
| prompts=[], | ||
| error=None, | ||
| verifier_error=None, | ||
| trajectory=[], | ||
| partial_trajectory=False, | ||
| rewards={"reward": 1.0}, | ||
| started_at=datetime(2026, 3, 24, 3, 0, tzinfo=timezone(timedelta(hours=-7))), | ||
| timing={}, | ||
| ) | ||
|
|
||
| data = json.loads((rollout_dir / "result.json").read_text()) | ||
| assert data["started_at"] == "2026-03-24T10:00:00Z" | ||
|
|
||
|
|
||
| def test_native_rollout_started_at_is_utc_aware_at_source(tmp_path, monkeypatch): | ||
| """Guards PR #928: native rollout timestamps are not local naive values.""" | ||
| from benchflow.rollout import _setup as rollout_setup | ||
| from benchflow.rollout._setup import _init_rollout | ||
|
|
||
| task_dir = tmp_path / "task" | ||
| task_dir.mkdir() | ||
| (task_dir / "instruction.md").write_text("Do it.\n") | ||
| (task_dir / "task.toml").write_text('version = "1.0"\n') | ||
|
|
||
| local_wall_time = datetime(2026, 7, 23, 5, 10, 58) | ||
| utc_instant = datetime(2026, 7, 23, 12, 10, 58, tzinfo=UTC) | ||
|
|
||
| class FakeDateTime: | ||
| @classmethod | ||
| def now(cls, tz=None): | ||
| if tz is None: | ||
| return local_wall_time | ||
| assert tz is UTC | ||
| return utc_instant | ||
|
|
||
| monkeypatch.setattr(rollout_setup, "datetime", FakeDateTime) | ||
|
|
||
| _, _, _, started_at, job_name, _ = _init_rollout( | ||
| task_dir, | ||
| job_name=None, | ||
| rollout_name=None, | ||
| jobs_dir=tmp_path / "jobs", | ||
| ) | ||
|
|
||
| assert job_name == "2026-07-23__05-10-58" | ||
| assert started_at == utc_instant |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.