fix(skills): replace deprecated utcnow in skill timestamp helper#5777
Open
husamemadH wants to merge 1 commit into
Open
fix(skills): replace deprecated utcnow in skill timestamp helper#5777husamemadH wants to merge 1 commit into
husamemadH wants to merge 1 commit into
Conversation
_now_iso() builds the 'created' value in skill frontmatter. datetime.utcnow() returns a naive datetime and has been deprecated since Python 3.12, scheduled for removal. Switch to the timezone-aware datetime.now(timezone.utc), keeping the serialized YYYY-MM-DDTHH:MM:SSZ shape unchanged so existing skill files keep parsing. timezone.utc is used rather than the datetime.UTC alias, which is 3.11+ only. Adds regression tests covering the deprecation, the serialized shape, and UTC correctness under a non-UTC local timezone -- the last guards against a bare datetime.now(), which yields the same shape but local wall time. Fixes odysseus-dev#5697
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
_now_iso()inservices/memory/skill_format.pybuilds thecreatedtimestamp written into every skill's frontmatter. It useddatetime.utcnow(), which returns a naive datetime and has been deprecated since Python 3.12 and scheduled for removal:This switches the helper to the timezone-aware
datetime.now(timezone.utc)while keeping the serializedYYYY-MM-DDTHH:MM:SSZshape byte-for-byte, so skill files written by earlier versions keep parsing unchanged.timezone.utcis used rather than thedatetime.UTCalias from the warning text, since the alias is only available on Python 3.11+ andtimezone.utcworks everywhere with no behavioural difference. This also matches the fix suggested in the issue.Target branch
dev, notmain.Linked Issue
Fixes #5697
Type of Change
Checklist
devScope
utcnow()appears 177 times across 39 files in the tree. This PR deliberately changes only the helper named in the issue, which asks for a small scoped cleanup. Converting the rest would be a large mechanical diff better handled separately, and several of the other call sites feed comparisons against naive datetimes that need checking individually rather than blanket-replacing.How to Test
Confirm the deprecation on current
dev:With this patch the same snippet reports no warnings, and
_now_iso()still returns e.g.2026-07-26T20:19:34Z.Round-trip through the code path that actually writes frontmatter:
Tests:
Tests added
tests/test_skill_format_timestamp.pypins three properties:test_now_iso_emits_no_deprecation_warningdevtest_now_iso_keeps_serialized_shapetest_now_iso_is_utc_not_local_timedatetime.now()produces the identical shape but emits local wall timeThe third is not decorative: patched to
datetime.now(), it fails by exactly the local UTC offset. It forces a non-UTC timezone (Asia/Amman) so the two visibly diverge, since under a UTC-configured test runner a naivenow()would otherwise pass unnoticed.Visual / UI changes
Files changed
services/memory/skill_format.py— importtimezone;_now_iso()usesdatetime.now(timezone.utc).tests/test_skill_format_timestamp.py— new regression tests (see table above).Disclosure
The patch was drafted with Claude Code. I reproduced the deprecation warning in my own instance, reviewed the change, and confirmed the new tests fail against unpatched
devbefore they pass with it. Flagging it per CONTRIBUTING.md's note on agent-generated PRs — this is a single targeted change against an existing issue, not a bulk submission.