Skip to content

fix: improve ISO datetime parsing#404

Merged
MaojiaSheng merged 1 commit intovolcengine:mainfrom
zztdandan:time-fix-pr
Mar 4, 2026
Merged

fix: improve ISO datetime parsing#404
MaojiaSheng merged 1 commit intovolcengine:mainfrom
zztdandan:time-fix-pr

Conversation

@zztdandan
Copy link
Contributor

Description

Improve ISO 8601 datetime parsing to accept Z-suffix timestamps and trim excessive fractional seconds, then use this parser across core read paths.

Related Issue

Fixes #

Root Cause

Two related parsing gaps caused valid timestamps to fail:

  • datetime.fromisoformat() does not accept Z suffix (e.g., 2026-03-03T01:26:14.481Z).
  • Windows-style timestamps can include more than 6 fractional digits, which fromisoformat() rejects.

These inputs appear in stored context/message timestamps, leading to ValueError during deserialization.

Changes Made

File Change
openviking/utils/time_utils.py Normalize Z -> +00:00 and trim excessive fractional seconds before parsing.
openviking/core/context.py Use parse_iso_datetime() for created_at and updated_at.
openviking/message/message.py Use parse_iso_datetime() for message created_at.
openviking/retrieve/hierarchical_retriever.py Use parse_iso_datetime() when parsing updated_at.
tests/unit/test_time_utils.py Added unit tests for Z-suffix parsing and context deserialization.

Design Decisions

  • Reuse existing utility: parse_iso_datetime() already handled excess fractional seconds; the fix extends it to accept Z.
  • Backward compatible: Inputs already accepted by fromisoformat() still parse correctly.
  • Minimal surface area: Only the affected parsing call sites were updated.

Testing

Before:

  • Context.from_dict({"created_at": "2026-03-03T01:26:14.481Z"}) -> ValueError

After:

  • parse_iso_datetime("2026-03-03T01:26:14.481Z") -> timezone-aware datetime
  • Context.from_dict(...) -> parses without error

Tests:

  • python -m pytest tests/unit/test_time_utils.py

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Checklist

  • My code follows the project coding style
  • I have performed a self-review of my code
  • New and existing unit tests pass locally with my changes
  • My changes generate no new warnings

@CLAassistant
Copy link

CLAassistant commented Mar 4, 2026

CLA assistant check
All committers have signed the CLA.

@MaojiaSheng MaojiaSheng merged commit 62d479b into volcengine:main Mar 4, 2026
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants