[Bug]: _process_local_tz() freezes the current UTC offset, shifting transcript timestamps by the DST delta
Component
Console / Chat transcript
Description
Summary
_process_local_tz() resolves the process timezone with
datetime.now().astimezone().tzinfo, which returns a fixed-offset
datetime.timezone describing the current moment — not a zone that carries
DST rules. It is then attached to every naive transcript timestamp.
On a host whose timezone observes DST, any message recorded in the opposite DST half-year is displayed one hour off. No exception is raised; the value is silently wrong.
Location
src/qwenpaw/app/chats/utils.py:42-44
def _process_local_tz():
"""Return the process-local timezone used by ``datetime.now()``."""
return datetime.now().astimezone().tzinfo or timezone.utcUsed by _normalize_msg_timestamp() (utils.py:58), which is called for both
timestamp and finished_at in agentscope_msg_to_message()
(utils.py:574 and utils.py:585), so the affected value is what the console
renders for every message.
Why the offset is frozen
Msg.created_at is written by AgentScope as datetime.now().isoformat(), i.e. a
naive process-local wall clock (confirmed in agentscope/message/_base.py:80,
and settled in #7399). Interpreting it as process-local is therefore correct —
but the tzinfo being attached cannot answer "what was the offset on that
date":
>>> proc = datetime.now().astimezone().tzinfo # TZ=America/New_York
>>> proc
datetime.timezone(datetime.timedelta(days=-1, seconds=72000), 'EDT')
>>> proc.utcoffset(datetime(2026, 7, 15, 12))
datetime.timedelta(days=-1, seconds=72000) # -04:00
>>> proc.utcoffset(datetime(2026, 1, 15, 12))
datetime.timedelta(days=-1, seconds=72000) # -04:00 <-- should be -05:00Steps to Reproduce
Host timezone observes DST (e.g. America/New_York), user_timezone is
Asia/Shanghai. Open a conversation that was recorded during the other DST
half of the year.
import os, time
from datetime import datetime
from zoneinfo import ZoneInfo
os.environ["TZ"] = "America/New_York"
time.tzset()
from qwenpaw.app.chats.utils import _normalize_msg_timestamp
# recorded in January -> EST (-05:00)
written = "2026-01-15T09:00:00"
_normalize_msg_timestamp(written, ZoneInfo("Asia/Shanghai"))
# actual : '2026-01-15T21:00:00+08:00'
# expected : '2026-01-15T22:00:00+08:00'The same value comes out of the public path:
from types import SimpleNamespace
from unittest.mock import patch
from agentscope.message import Msg
from qwenpaw.app.chats.utils import agentscope_msg_to_message
msg = Msg(name="user", role="user",
content=[{"type": "text", "text": "hi"}],
created_at="2026-01-15T09:00:00")
with patch("qwenpaw.app.chats.utils.load_config",
return_value=SimpleNamespace(user_timezone="Asia/Shanghai")):
[message] = agentscope_msg_to_message(msg)
message.metadata["timestamp"]
# '2026-01-15T21:00:00+08:00' (one hour early)Expected vs Actual
| value | |
|---|---|
| true instant | 2026-01-15T09:00:00-05:00 |
| expected transcript timestamp | 2026-01-15T22:00:00+08:00 |
| actual | 2026-01-15T21:00:00+08:00 |
Drift equals the DST delta, so it is not always one hour: Europe/* is 1h,
Australia/Lord_Howe is 30min.
Two controls behave correctly, which narrows the cause:
- a DST-free process timezone (
Asia/Shanghai) — no drift; - an aware input (
2026-01-15T09:00:00-05:00) — correct, because the offset travels with the value.
Only the naive path on a DST-observing host is affected.
Relationship to #6855 / #6871
This is the residual surface of #6855, not a repeat of it.
#6871 reported a +8h double offset when re-rendering a view, caused by a UTC
process being treated as user-local. #6855 fixed that by interpreting naive
timestamps as process-local, which is correct. What #6855 did not address is
that the tzinfo it resolves has no DST rule, so the same code path is wrong by
the DST delta once the host timezone is one that observes DST.
The two differ in root cause location, trigger condition and magnitude. #7399
concluded that _normalize_msg_timestamp "already handles this correctly" —
this report is the case that assumption misses.
Test coverage gap
The existing timestamp tests pass on current main. They patch
_process_local_tz with ZoneInfo("UTC") (tests/unit/app/chats/test_utils.py:372)
and ZoneInfo("Asia/Shanghai") (:385, :422, :457, :483) — both DST-free,
where a frozen offset and a real zone are indistinguishable. The only direct
test, test_process_local_tz in tests/integration/test_channels_manager_module.py:114,
asserts only is not None.
A regression test using a DST-observing zone fails on current main:
def test_process_local_tz_carries_dst_rule():
proc_tz = _process_local_tz()
assert proc_tz.utcoffset(datetime(2026, 7, 15, 12)) != \
proc_tz.utcoffset(datetime(2026, 1, 15, 12))E AssertionError: assert '2026-01-15T21:00:00+08:00' == '2026-01-15T22:00:00+08:00'Suggested direction
Resolve an IANA zone name instead of a fixed offset, so the attached tzinfo
answers the question for the timestamp's own date. src/qwenpaw/config/timezone.py
already has _probe_env() / _probe_python() for resolving the process-local IANA
name, and reusing them would keep the naive→aware attachment in
_normalize_msg_timestamp unchanged.
Worth checking before merging: on Windows $TZ is usually unset and tzname
returns non-IANA names such as China Standard Time, so the fallback path needs
to be validated on that platform rather than assumed.
The broader fix suggested in #7399 — making Msg.created_at an aware value —
would remove the ambiguity entirely, but it is a much larger change and out of
scope for a focused report.
Environment
- QwenPaw: current
main(b944e1d5) - OS: macOS (Darwin 25.6.0, arm64), Python 3.12.14
- Process timezone:
America/New_York;user_timezone:Asia/Shanghai - No credentials, no network, no running backend required
Source: agentscope-ai/QwenPaw