Skip to content

fix(chat): use exact UTC recency for Session selection - #9534

Open
hhyykk wants to merge 1 commit into
mainfrom
codex/chat-session-recency-chronology
Open

hhyykk wants to merge 1 commit into
mainfrom
codex/chat-session-recency-chronology

Conversation

@hhyykk

@hhyykk hhyykk commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

Chat sorted some Session update times as text. A whole-second or offset timestamp could rank ahead of a later fractional-second update. The same mismatch affected the ordinary resume selector and the exact Goal-instance selector.

The Session list and both resume paths now compare parsed UTC instants at microsecond precision. The existing Goal, Agent, channel, resumability and Goal-instance filters still determine which sessions are eligible. Equal instants use the existing source-order or Session-ID tie rule for each selector.

Author Declaration

  • Written by model_agent, OpenAI Codex (GPT-6 family).
  • Reproduced on main at 509360fb0 using disposable local Session records and the real loopback list route, runtime opening path and TypeScript lifecycle decision.
Criterion Disposition Evidence
Show the latest update first in a scoped list implemented The loopback HTTP test covers whole seconds and offset timestamps against a later fractional-second record.
Resume the newest eligible Session implemented The real runtime reuses the correct existing Session. Newer closed and out-of-scope records remain excluded.
Keep exact Goal-instance filtering and deterministic ties implemented TypeScript tests cover an older Goal instance, equivalent encodings and unreadable legacy timestamps.

Validation

Check Result Evidence
Baseline regression passed Two loopback cases and two exact-selector cases fail on main and pass with the fix.
Python Chat and attached-session regressions 82 passed tests/test_chat_codex_home.py, tests/test_attached_session_goal_instance.py and tests/test_chat_reasoning_selection.py.
TypeScript lifecycle and routing tests 46 passed tests/control_plane_ts/chat_session_lifecycle.test.ts and tests/control_plane_ts/effect_runtime_handlers.test.ts.
Control-plane typecheck passed npm run typecheck:control-plane.
Lean 4.22.0 passed lean -DwarningAsError=true regression/ChatSessionRecency.lean. The model proves that a selected Session is eligible and precedes every eligible alternative. Removing the scope predicate makes the proof fail.
Local premerge 8 checks passed python3 -m loopx.entrypoint canary premerge --from-git-diff --git-diff-base origin/main --tier quick.
Ruff passed Both changed Python files.

The Lean model starts with parsed UTC values and models the existing eligibility filters. The runtime regressions check timestamp parsing and the actual selection paths. Test Sessions and adapters are local fixtures.

Scope And Continuation

The change corrects recency for the scoped Session list and both scoped resume paths. Stored timestamps and Session identities remain intact. Explicit Session selection continues to use the original exact identity path.

Frontend / Visual Evidence

The visible effect is the order of the Session list and the resumed selection. The loopback API regression verifies the first entries and selected Session. Browser rendering was outside this validation run.

Type Of Change

  • Bug fix
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Host or runtime integration

Shared-authority RFC fixture impact

N/A.

Boundary Checklist

  • Diff and evidence use public-safe synthetic data.
  • The change is scoped to the reproduced Session recency defect.
  • No paired RFC changed.
  • The commit includes a DCO Signed-off-by trailer.

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-27T17:37:17.208750Z db1ec76 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 用户在查看会话或恢复已有工作时,需要找到当前 Goal、Agent 和频道可用的最新会话。 按更新时间的原始文本比较,整秒、带偏移或跨本地日期的旧记录会抢占后来更新的会话。 会话列表和两个 resume 路径按可解析的 UTC 微秒确定先后,同刻沿原排序规则,旧无效时间保留确定次序。 本次交付范围为会话读取和已有会话的选择。

改动思路 / Approach

普通列表和恢复沿 Python 会话存储使用原 chronology_key。精确分支沿 TypeScript lifecycle 使用原微秒解析,在原 GoalRef 和候选范围过滤后排序。 本次交付范围为会话读取和已有会话的选择。 实际改变是读取次序和恢复选中的会话。原 scope、显式会话选择、存盘更新时间与执行权限由原路径处理。

具体改动 / Changes

审查精确提交 db1ec761ef46618ec1bc2f2c5163725dd5621f86,当前比较基线 509360fb0d3e9e6e578ddf5c12db587886016b23。五个文件增加 224 行、删除 6 行。两处生产模块复用各自既有时间解析,其余为 Python、TypeScript 验证和 Lean 模型。 current-goal-instance-only 已验证实例感知的 Goal 不能使用过期、缺失或非当前绑定授予执行权限。 现有 Goal 身份约束

关键代码讲解

  • _session_recency_key。按 UTC 时刻比较可读值,等时刻沿源顺序,旧坏值保持文本后备。 源码
  • ChatSessionStore.latest_session。使用 UTC 排序选取最新合格项,原候选范围保持。 源码
  • decideSelection。先筛精确 GoalRef,解析微秒,等时刻保持 Session ID 的顺序。 源码

对主干的风险 / Risks

真实 loopback HTTP 回包和原开会话入口使用最新合格更新时间。严格读取用精确 GoalRef 对照新旧两个生命周期,更新过的旧实例、其他 Agent 或频道以及已关闭会话均不能抢占当前项,选中后原 Session 元数据逐字节保留。 基线在四项实际 Python 输入及三项 TypeScript 例中失败。现头的严格读取对旧实例与跨本地日期覆盖通过,等时刻分别保留源和 Session ID 的优先顺序。 84 项 Python、46 项 TypeScript、控制面类型检查、Ruff 和 Git diff 检查通过。Lean 4.22.0 验证选择的资格与排序,移除范围约束后资格证明失败。 验证覆盖本地合成会话、实际 Chat HTTP 与原生命周期入口。浏览器、已安装真实外部宿主和远端 CI 未运行。

我的整体评价 / Verdict

APPROVE。 会话列表和两个 resume 路径按可解析的 UTC 微秒确定先后,同刻沿原排序规则,旧无效时间保留确定次序。 真实入口和两版对照均已独立复验。验证覆盖本地合成会话、实际 Chat HTTP 与原生命周期入口。浏览器、已安装真实外部宿主和远端 CI 未运行。

English verdict: APPROVE at db1ec76. The real Session list and both resume selectors choose the newest eligible UTC instant. Paired tests preserve exact Goal-instance and scope filtering, deterministic ties, and the existing Session records.

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