Skip to content

fix(steward): preserve retry cooldown timestamp precision - #9543

Open
hhyykk wants to merge 2 commits into
mainfrom
codex/steward-retained-completion-cooldown
Open

hhyykk wants to merge 2 commits into
mainfrom
codex/steward-retained-completion-cooldown

Conversation

@hhyykk

@hhyykk hhyykk commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The Steward retry paths treated equivalent retained UTC timestamps differently. A completion stamp ending in lowercase z could keep a retry unavailable after its cooldown. Converting a valid completion instant near year 9999 to floating-point epoch seconds could also round the instant down and release a retry a microsecond early.

Fix

Both Python retry paths use the shared UTC timestamp parser and compare integer microseconds. The host clock is sampled in nanoseconds. An explicitly supplied finite clock sample is converted from its exact ratio. Receipt eligibility and the two existing cooldown durations are preserved. Unreadable completion timestamps and nonfinite samples withhold retry.

Verification

  • The retained receipt regression covers Z, z, equivalent numeric offsets, an omitted offset, and malformed text. It checks both callers immediately before, at, and after their cutoffs.
  • The far-future regression reproduces early release in both callers on the previous PR head. The fix withholds both retries at one microsecond and one nanosecond before their cutoffs, then permits eligible retries exactly at the cutoff. Injected clock samples on either side of the cutoff and nonfinite samples are also covered.
  • 25 monitor contract and chronology tests, 36 shared timestamp codec tests, and 19 selected retry integrations passed with isolated local fixtures.
  • Lean 4.22.0 checks normalized timestamp parity and exact comparison of native nanoseconds and supplied clock ratios. Rounding up the host clock breaks the last-nanosecond theorem.
  • All nine local premerge checks passed on the submitted commit.

PR #9417 also moves the shared retry parser as part of the Steward Turn refactor. The typed Core admission check has its own millisecond comparison and is tracked separately.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T04:12:56.648257Z a3f7124 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@hhyykk hhyykk changed the title fix(steward): normalize retained retry completion timestamps fix(steward): preserve retry cooldown timestamp precision Nov 27, 2026
loopx-agent
loopx-agent previously approved these changes Nov 27, 2026

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

APPROVE

通过本次精确提交评审。

动机 / Motivation

原生 Follow-up 与 Monitor 通过已持久化的完成回执决定是否恢复。 旧解析会拒绝小写 z,并能提前通过部分越界日期。上一候选统一了解析,但两条入口仍会在远期历史回执的浮点时间舍入下提早重试。 在同一持久化回执中分别以 Z、z 和偏移表示相同时间,在原冷却前、等于边界和越过边界恢复。 相同时间得到一致的冷却结论。实际时钟在最后一纳秒保持等待,到达门槛才允许恢复。坏日期、非有限时钟和已有交付回执仍不触发重试。 范围是读取旧完成回执的时间归一,原重试资格和冷却值由既有路径负责。

改动思路 / Approach

两个调用点复用共享 UTC 解析和整数微秒比较。系统时钟使用整数纳秒,显式有限浮点时钟按实际有理值向下取整。 统一 retained completion 的冷却计算,保留原 Monitor 与 Follow-up 守卫、时长和持久回执。 原生恢复冷却、旧回执和已成功写回的重试守卫。 延迟重试与任何明确写回保持原约束。

具体改动 / Changes

精确提交 cd8d879。目标基线 509360f,复审对照 509360f。6 个文件,增加 224 行、删除 24 行。评审条件 steward-recovery、retained-time-compatibility。 原始契约

关键代码讲解

  • timestamp_age_at_least。将 UTC 时间和当前时钟按整数微秒比较。 源码
  • StewardTurnHost.monitor_restart_request。Monitor 恢复根据原回执和冷却时间决定是否生成重试。 源码
  • _past_precommit_cooldown。未提交 Follow-up 仅在已有回执和冷却资格成立时生成重试。 源码
  • parse_timestamp。统一读取 ISO 日期、时区偏移和 UTC 后缀,并拒绝不可表示的 UTC 时间。 源码

对主干的风险 / Risks

独立写入并重开原生会话回执,复验两个入口的 Z、z、时区偏移、冷却边界正负一微秒。精确头定向 29 项通过,含远期一纳秒和非有限显式时钟。 本头 29 项通过。两项定向复跑在本头与目标基线同样失败,分别是替身干扰 Node 版本探针,以及旧 host_invoked 用例的相同重试 token。

语义与 CI 对齐

目标基线有三个日期兼容性反例。上一候选 c4f3c92 的远期精度回归失败,当前头通过。坏日期、UTC 下溢和已交付 Follow-up 都不会生成新重试。 真实回执与两个 Python 调用入口已验证,时钟由用例控制。未操作在用服务或独立运行 Lean。与并行 #9417 的 steward_turn.py 有实际 Git 内容冲突,若该 PR 先落地,须在移动后的恢复入口复验。

我的整体评价 / Verdict

APPROVE。 两个真实恢复入口对同一时刻的历史表示给出一致结果,同时保持旧回执和坏时间的安全拒绝。 让恢复入口沿用共享时间解析,在目标基线更新后重新执行同一回执矩阵。 对比目标基线和候选,用隔离持久回执在冷却边界及坏日期上验证真正的两个重试调用路径。

English verdict: APPROVE at cd8d879. Both native retry paths honor the cooldown for equivalent retained timestamps and suppress invalid dates.

@mergify

mergify Bot commented Nov 28, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @hhyykk.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 28, 2026
@hhyykk
hhyykk force-pushed the codex/steward-retained-completion-cooldown branch from cd8d879 to a3f7124 Compare November 28, 2026 04:11
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 28, 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants