Skip to content

fix(chat): claim queued Turns in UTC order - #9539

Open
hhyykk wants to merge 1 commit into
mainfrom
codex/chat-queued-turn-fifo
Open

hhyykk wants to merge 1 commit into
mainfrom
codex/chat-queued-turn-fifo

Conversation

@hhyykk

@hhyykk hhyykk commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Problem

A queued Turn at 10:00:00.000001Z can appear before one at 10:00:00Z because the queue compares timestamp text. Both HTTP readback and automatic claim consume that order, so the newer Turn can run first.

Fix

Sort the rows already selected by Core using the existing UTC chronology key. Preserve timestamp text and Turn ID as tie breakers. Keep the existing expiry, reservation, and admission rules.

Verification

  • The prior code fails a regression through local HTTP and the real store claim. The fix preserves raw timestamps in the response, skips the expired Turn at claim time, and records the earliest eligible Turn as active. The regression starts no provider.
  • 206 Python tests and 9 Core queue tests passed.
  • Lean 4.22.0 verifies that the model preserves the selected rows and, when a fixed eligible candidate is claimed, no other eligible parsed instant is earlier. The model starts after parsing and takes eligibility as an input. The HTTP and store regression covers the actual parsing and claim path.
  • Eight local premerge checks passed on this commit. Remote CI was left asynchronous.

PR #9536 repairs ingress receipt ordering and combines cleanly with this commit. PR #9480 moves the queued Turn reader while retaining timestamp-text order.

Signed-off-by: aihop <4408344+hhyykk@users.noreply.github.com>
@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-27T18:09:53.978343Z 727431e PR opened
ℹ️ 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.

@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

动机 / Motivation

使用原 Chat 排队发送后续输入的人会受此影响。已有 Session 的排队输入同时含整秒、微秒和时区偏移时,旧字串比较会让晚一微秒的消息越过早到消息,快照与后续认领均受影响。 同一文件夹和 HTTP 调用下,基线把 10:00:00.000001Z 放在 10:00:00Z 及等时刻偏移之前,并先认领该微秒消息。 精确头先列最早整秒及等时刻偏移,再列晚一微秒的消息。原 created_at 字串保留,过期项在认领时结算,HTTP 与实际认领时序一致。 同一 Session 保持按 UTC 时刻的 FIFO。时间相同保留原文本和 Turn ID 次序。 范围为既有队列的排序,保留交付和准入规则。 原 Session FIFO 约定

改动思路 / Approach

在现有 queue provider 的读方法复用 chronology_key,使两个既有消费者取得相同顺序,一并复用原时间边界、平局规则及旧值回退。 范围为既有队列的排序,保留交付和准入规则。 Core 仍按原会话、状态和保留条件选出 Turn。认领继续经过原锁和资格校验。

具体改动 / Changes

精确提交 727431eaa11bb1105f57d611cf76ea21d544312b 对照基线 509360fb0d3e9e6e578ddf5c12db587886016b23,三个文件增加 146 行、删除 3 行。现有存储读取复用 UTC 比较,HTTP 和实际认领使用同一有序结果。Lean 模型验证给定成员和资格后的排序。session-fifo 核对同一 Session 的有效排队输入按 UTC 时刻先进先出,original-claim-fence 核对原到期过滤、认领和状态回读均保留。当前改动放在 loopx/chat/ingress.py 的现有排序调用。旧值沿共享比较器的确定性回退。 实际入口回归

关键代码讲解

  • ChatIngressStore.queued_turns。替换成员筛选后的时间排序键。 源码
  • chronology_key。复用既有 UTC、原时间和旧值回退。 源码
  • ChatStore.claim_next_queued_turn。实际状态转换沿原逻辑,从更正顺序得到正确项。 源码

对主干的风险 / Risks

同一文件夹和 HTTP 调用下,基线把 10:00:00.000001Z 放在 10:00:00Z 及等时刻偏移之前,并先认领该微秒消息。 精确头先列最早整秒及等时刻偏移,再列晚一微秒的消息。原 created_at 字串保留,过期项在认领时结算,HTTP 与实际认领时序一致。 过期队列项不会变成活动 Turn。现头的既有保留、撤权拒绝、重放、认领和活动输入不变用例均通过,回归夹具没有启动 Provider。 基线移植同一个回归,1 项按顺序断言失败。现头 42 项 Python 通过,Lean 4.22.0、Ruff 和 git diff --check 均通过。

与 #9536 三方合并模拟通过。#9480 移动同一读方法,按当前提交模拟在 ingress.py 冲突,集成时须保留此排序键并重跑当前回归。 验证使用本地文件回执、真实 loopback HTTP、Core 选择和实际 store 状态转换。未运行浏览器、实时宿主或外部投递。 远端 CI 按现有策略留在异步流程。 同时修改回执排序的 PR 并行迁移

我的整体评价 / Verdict

APPROVE。 真实 HTTP 和 store 复验支持当前候选的 FIFO 修复。读回保留原时间值,过期 Turn 走原超时路径。并行迁移仍需把该比较器留在原队列的共同读取路径。

English verdict: APPROVE at 727431e. The real queue snapshot and claim now use UTC order while preserving raw timestamps, deterministic ties and existing admission checks. Keep the shared comparison when integrating PR #9480.

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