Fix run-history ordering across timezone offsets - #4934
huangruiteng merged 2 commits into
Conversation
Signed-off-by: duanjialing.777 <duanjialing.777@bytedance.com>
Signed-off-by: duanjialing.777 <duanjialing.777@bytedance.com>
huangruiteng
left a comment
There was a problem hiding this comment.
动机
同一 generated_at 在 RFC3339 中可带不同 offset;直接比较文本不能代表 UTC 先后。旧逻辑会选到过时 vision、把已 ACK 的 replan 当作开放,或展示旧的 promotion-readiness 证据。本 PR 当前 exact head 5ce1c31dc098f27325c3dc043a4f8de50eeb7468 把这些相关读者统一到真实时间顺序;目标是修正只读选择和后续准入,不是重写历史账本。
改动思路
将 history 与 agent-scoped evidence log 中重复的时间排序键移到 control_plane.runtime.time.chronology_key,由它按有效 UTC instant 排序,并让无法解析的旧行稳定地落在有效时间之后。refresh、Todo replan guard、Goal amendment、feedback、evidence frontier、history 和 doctor readiness 读者复用这一 owner。doctor 保留原有“runtime ledger 优先于 legacy Goal ledger”的来源规则,仅修正来源内的最新记录选择;无需新增状态或权限契约。
具体改动
关键代码讲解
chronology_key(loopx/control_plane/runtime/time.py:25)提供有效性 rank、UTC 时间和原文 tie-break。history.py保留旧私有别名作兼容,evidence log 删除重复实现。refresh_state_run(loopx/state_refresh.py:774)、_validated_replan_successor_obligation(loopx/cli_commands/todo.py:94)与_derive_open_replan_obligation_inventory(loopx/control_plane/goals/goal_amendment_proposal.py:285)用同一键选择 vision 和结算 ACK。新增测试验证较晚的01:00Z胜过较早的08:30+08,并阻止已结算义务再次准入。latest_promotion_readiness_event(loopx/doctor.py:605,排序在 682)在第二个提交接入共享键;新 doctor 测试覆盖 runtime ledger 的跨 offset 反例。该函数的 status/promotion gate 消费者不再读到旧 readiness。feedback.select_run与 agent-scoped evidence frontier 同样改为共享排序;三处测试文件覆盖这些生产读者的时间边界。没有持久格式、写入者或 CLI 参数变化。
对主干的风险
未发现阻塞项。我先在首个 head 复现出 doctor 仍把较旧 08:30+08 当最新;发布前 head 更新,第二个提交正好修复此遗漏。因此本评审没有沿用旧 SHA 的结论,而是重新检查了完整 base-to-head diff:相同临时账本在当前 head 对 runtime 与 legacy Goal 两种来源都返回较晚的 01:00Z;base 的新增 refresh/Todo 测试失败、当前 head 通过。当前 head 的 79 个相关 pytest、改动文件 Ruff 和 premerge 18/18 均通过。独立 worktree 首次缺少 Node 解析依赖,补齐后同一组 canary 全绿。另一次独立 promotion smoke 因其默认会在最后写入全局运行证据而在写入前中断,不计为通过;没有改写活动 Goal。远端 CI 按 Goal wait_for_ci=false 未拉取。
语义与 CI 对齐
generated_at 的“最新”现在在检查范围内统一为 UTC instant;旧字符串键若用于行身份去重而非排序则保持原样。该变更复用现有时间解析和 readiness 来源优先级,没有新协议、TS 权威分叉或放宽验证。合并就绪与这次代码评审仍是独立判断。
我的整体评价
APPROVE 此 exact head。修复范围与已证实的故障相称;第二个提交收敛了首版留下的同源 doctor 漏洞,新增回归具有实际区分力。后续若出现新的“最新运行”读者,宜直接调用共享 chronology_key,不再复制字符串排序。这里的批准不是自合并授权。
English verdict: APPROVE - head 5ce1c31; UTC ordering now covers refresh/replan and doctor readiness, with 79 focused tests and 18/18 premerge checks passing.
Summary
Root cause
RFC3339 timestamps with different offsets are not chronologically sortable as raw strings. An earlier
+08:00row could outrank a laterZrow, causing stale vision selection, reopening already settled replan obligations, or reporting obsolete promotion-readiness evidence.Validation
102 passedacross planning consumers, amendment admission, evidence log, history chronology, feedback selection, and doctor readinessloopx canary premerge --from-git-diff: 18/18 checks passed