Skip to content

fix(harness): render memory-ledger entry timestamps in the ledger's zone (#3433) - #3718

Open
aiyili wants to merge 1 commit into
agentscope-ai:mainfrom
aiyili:fix/memory-ledger-zone
Open

aiyili wants to merge 1 commit into
agentscope-ai:mainfrom
aiyili:fix/memory-ledger-zone

Conversation

@aiyili

@aiyili aiyili commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3433

Problem

A daily memory ledger's file name and its entry heading used different time bases. The file was named for the date in the request clock's zone, while the heading printed a UTC instant. At UTC+09:00, a flush at 22:30Z on 1 March lands in memory/2026-03-02.md with the heading ## Memory Flush — 2026-03-01T22:30:00Z: a day apart from its own file.

Fix

The heading is taken from the same Clock as the file name and rendered in that clock's zone (ISO-8601 with offset): 2026-03-02T07:30:00+09:00.

The zone is configured by supplying a zoned Clock in the RuntimeContext, which MemoryFlushManager has read since #4154 (clock(rc)). There is no separate setting. An earlier revision of this PR added a ledgerZone constructor parameter instead; it was never reachable from any builder and duplicated that clock, so it is dropped.

Tests

MemoryFlushManagerClockTest, 5 cases:

  • the ledger is filed under the clock zone's date;
  • the heading is rendered in that zone;
  • a clock in another zone files under its own local date;
  • two flushes in the same zone land in one ledger;
  • with no clock supplied, the JVM default zone is used, as before.

Against unmodified main, only the heading case fails.

@jujn jujn added the P2 重要不紧急 label Nov 3, 2026
每日记忆账本(memory/YYYY-MM-DD.md)的文件名与条目标题此前使用不同的
时间基准:文件名取请求 Clock 所在时区的日期,标题却是 UTC 瞬时
(Instant.toString(),以 Z 结尾)。在 UTC+09:00 的部署里,22:30 UTC 的
一次 flush 归入次日(03-02)的账本,条目标题却写着 03-01T22:30:00Z——
与文件名相差一天(agentscope-ai#3433)。

修复:标题与文件名取自同一个 Clock,并以该 Clock 的时区渲染
(ISO-8601 带偏移,如 2026-03-02T07:30:00+09:00)。

时区通过 RuntimeContext 中的 Clock 配置(agentscope-ai#4154 引入,durable 运行时
恢复一轮对话时也是这样还原其时区),不另增配置项。本 PR 早期版本
提出的 ledgerZone 构造参数从未接入任何 builder,且会与 Clock 形成两套
时间来源,故移除。

测试:MemoryFlushManagerClockTest 共 5 例——账本按 Clock 时区的日期
归档、条目标题按该时区渲染、另一时区归入其本地日期、同一时区连续
flush 汇入同一账本、未提供 Clock 时沿用 JVM 默认时区。
@aiyili
aiyili force-pushed the fix/memory-ledger-zone branch from d76f145 to e6d45ea Compare November 26, 2026 14:16
@aiyili

aiyili commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Reworked on current main as a single commit (e6d45ea0); title and description updated. The old head is kept on backup/pr-3718-before-rework.

What changed in the approach. The first version added a ledgerZone constructor parameter to MemoryFlushManager. That was wrong on two counts: it was never wired to any builder, so nobody could actually set it, and it competed with a time source the framework already has. Since #4154, MemoryFlushManager takes its time from the Clock in the RuntimeContext (MemoryFlushManager.clock(rc)), and a Clock carries its zone — the durable runtime restores a turn's zone the same way.

So the zone is configured by supplying a zoned Clock; there is no separate knob.

What main already did. The ledger file already followed that clock's zone: with a clock fixed at 2026-03-01T22:30Z in Asia/Tokyo, the entry is filed under memory/2026-03-02.md. That was true before this change, but nothing tested it and nothing documented it.

What was still wrong. The entry's heading printed a UTC instant: ## Memory Flush — 2026-03-01T22:30:00Z, next to a file named for the next day. That is the part #3433 is about. The heading now comes from the same clock as the file name and is rendered in its zone: 2026-03-02T07:30:00+09:00.

Tests. New MemoryFlushManagerClockTest (5 cases): ledger filed under the clock zone's date; heading rendered in that zone; a clock in another zone files under its own local date; two flushes in the same zone land in one ledger; no clock supplied → JVM default zone, as before. Run against unmodified main, exactly one of the five failed (the heading), which matches the analysis above. agentscope-harness suite passes on current main.

@aiyili aiyili changed the title fix(harness): configurable memory-ledger timezone (#3433) fix(harness): render memory-ledger entry timestamps in the ledger's zone (#3433) Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 短期记忆Memory Flush 时间格式如何修改默认不是utc时间 — 2026-10-07T08:15:40.992228Z

2 participants