Skip to content

fix(journal): turn_id DESC tie-break on same-ms turn listings#161

Merged
sweetcornna merged 1 commit into
mainfrom
fix/turn-order-tiebreak
Jul 20, 2026
Merged

fix(journal): turn_id DESC tie-break on same-ms turn listings#161
sweetcornna merged 1 commit into
mainfrom
fix/turn-order-tiebreak

Conversation

@sweetcornna

Copy link
Copy Markdown
Owner

背景

7 个 gap-close PR(#114-#120)合并后,在合并树上跑全量套件时 test_fork_copies_completed_turns_faithfully 偶发失败(单跑/单包跑均通过)。

根因

begin_turn 用同一个 wall-clock ms 生成 turn_idstarted_at_ms,主键冲突重试会 +1 turn_id不改时间戳 —— 同一毫秒内落库的两个 turn 在 started_at_ms 上平局。list_session_turns 已带 turn_id DESC 次级排序(注释里明确写了这是 critical),但 get_session_turn_ids(SQLite + Postgres 两个后端)和 find_resumable_turn 的两条 LIMIT 1 查询都没有 —— 平局时返回顺序退化为自然行序,fork 的 faithful-copy 比较在全量套件的时序下随机翻车。

修复

所有 turn 列表查询统一到 (started_at_ms DESC, turn_id DESC) 契约;新增强制同毫秒平局的回归测试。

验证

  • 新回归测试在无修复时失败、有修复时通过
  • corlinman-server 全包 3030 通过;ruff + mypy 616 文件干净

https://claude.ai/code/session_01TkyhWocv6Kyjym4jsGBnq5

get_session_turn_ids (SQLite + Postgres) and find_resumable_turn
ordered by started_at_ms alone; two turns seeded within one wall-clock
ms tie on the timestamp (begin_turn's integrity-collision retry bumps
turn_id +1 but keeps started_at_ms), so the listing came back in
scrambled natural-row order. Surfaced as a full-suite-only flake in
test_fork_copies_completed_turns_faithfully — fork_session read its
source through list_session_turns (which already carries the critical
secondary sort) while the comparison helper read through
get_session_turn_ids (which didn't).

Aligns every turn listing on the same (started_at_ms DESC, turn_id
DESC) contract + pins it with a forced same-ms regression test.

Claude-Session: https://claude.ai/code/session_01TkyhWocv6Kyjym4jsGBnq5
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added codex:needs-review A Codex review is needed for the current PR head. codex:review-requested A Codex review was requested or should be running automatically. status: 🔁 re-review loop A fresh Codex review was requested after the latest change or comment. codex:reviewed Codex posted a review result or thumbs-up after the latest request. status: 👀 ready for maintainer look No automation blocker is known; a maintainer should inspect the current result. and removed codex:review-requested A Codex review was requested or should be running automatically. codex:needs-review A Codex review is needed for the current PR head. status: 🔁 re-review loop A fresh Codex review was requested after the latest change or comment. labels Jul 20, 2026
@sweetcornna
sweetcornna merged commit dc587e7 into main Jul 20, 2026
10 checks passed
@github-actions github-actions Bot added the status: ✅ merge-ready Evidence and review are clear; normal merge gates may proceed. label Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex:reviewed Codex posted a review result or thumbs-up after the latest request. status: ✅ merge-ready Evidence and review are clear; normal merge gates may proceed. status: 👀 ready for maintainer look No automation blocker is known; a maintainer should inspect the current result.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant