Skip to content

Python: Normalize naive timestamps to UTC in checkpoint selection - #9944

Open
Hardik K (hardikkaurani) wants to merge 2 commits into
microsoft:mainfrom
hardikkaurani:fix/python-checkpoint-mixed-timezone-get-latest
Open

Hardik K (hardikkaurani) wants to merge 2 commits into
microsoft:mainfrom
hardikkaurani:fix/python-checkpoint-mixed-timezone-get-latest

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Motivation & Context

In agent-framework (Python workflows), WorkflowCheckpoint.timestamp is an ISO 8601 timestamp string. While default timestamps generated by WorkflowCheckpoint include timezone information (UTC), timestamps supplied externally or written by tools can be offset-naive (e.g. "2026-01-01T00:00:00").

When storage.get_latest evaluates candidate checkpoints, _select_latest_checkpoint previously invoked datetime.fromisoformat(cp.timestamp) directly inside max(...). In Python, comparing an offset-naive datetime with an offset-aware datetime raises:

TypeError: can't compare offset-naive and offset-aware datetimes

This caused get_latest to fail unexpectedly whenever a storage held a combination of naive and timezone-aware timestamps.

Description & Review Guide

  • What are the major changes?

    1. Added _parse_checkpoint_timestamp helper in _workflows/_checkpoint.py which normalizes naive timestamps by assigning timezone.utc.
    2. Updated _select_latest_checkpoint to use _parse_checkpoint_timestamp for max(...) timestamp calculation and candidate filtering.
    3. Added parameterized regression tests across InMemoryCheckpointStorage and FileCheckpointStorage in packages/core/tests/workflow/test_checkpoint.py verifying that get_latest selects the newest checkpoint without raising TypeError.
  • What is the impact of these changes?

    • Prevents runtime TypeError when selecting latest checkpoints across mixed timestamp formats.
    • Consistent ordering semantics treating naive timestamps as UTC.
    • Zero breaking changes.

Related Issue

Fixes #9941

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change.

cc Eduard van Valkenburg (@eavanvalkenburg)

…t_latest_checkpoint

Normalize ISO 8601 timestamps without timezone offsets to UTC when selecting the latest checkpoint, preventing TypeError when comparing offset-naive and offset-aware datetimes across saved checkpoints.

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…ware timestamps

Add parameterized regression tests for InMemoryCheckpointStorage and FileCheckpointStorage verifying that get_latest correctly selects the newest checkpoint when storages contain a mixture of naive and timezone-aware timestamps without raising TypeError.

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Nov 1, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAF Automated Review — Iteration 1

Result: No findings
Scope: full PR (2 commit(s)): 8cbe2a6de527, f935ace732cb
Model: gpt-5.6-sol

Overview

The PR narrowly normalizes offset-naive checkpoint timestamps to UTC before comparison while preserving aware-offset ordering and the existing lineage/ID tie-breakers. The regression test covers both core storage implementations and verifies both aware-newer and naive-newer selection. No publishable defect was established in the changed core path.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

@hardikkaurani
Hardik K (hardikkaurani) requested a balanced review from Copilot November 2, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@eavanvalkenburg

Copy link
Copy Markdown
Member

/review

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 4, 2026
@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Eduard van Valkenburg (@eavanvalkenburg),

The merge queue run 41804121496 failed due to a pytest-xdist worker crash (node down: Not properly terminated / runner memory pressure) in Python Integration Tests - Foundry during test_agui_provider_matrix.py, which was unrelated to this PR's core workflow checkpoint changes.

I've rebased the branch onto the latest main, verified that all checkpoint unit tests (85 passed) and ruff checks pass cleanly, and updated the branch.

Could you please re-add this PR to the merge queue when you have a moment? Thank you!

This branch was previously deployed

1 inactive deployment
github-app-auth — f935ace7 Deployed Nov 1, 2026 by hardikkaurani via team_check #8264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: get_latest raises TypeError when a storage holds naive and timezone-aware checkpoint timestamps

3 participants