Skip to content

refactor(sessions): 统一分页状态和原生消息视图 - #5

Closed
kzheart wants to merge 2 commits into
mainfrom
codex/session-read-state
Closed

kzheart wants to merge 2 commits into
mainfrom
codex/session-read-state

Conversation

@kzheart

@kzheart kzheart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

会话读取中的分页状态、消息视图、摘要窗口和 block 分片分散在同一个模块,原生分支点也各自计算轮次和消息位置。本次将这些职责拆分并集中维护,便于后续扩展读取能力。

  • 提取上下文和搜索读取的参数、元数据及分页状态。
  • 将 block 分片与位置推进独立出来,统一处理跨 block 和跨消息的续读。
  • 将可见消息视图、原生消息锚点及分支点摘要放到同一模块。
  • 搜索文本与摘要窗口单独维护,保留现有公开读取入口及 DTO 字段。

验证:Rust 库的 857 个单元测试、3 个分页集成测试、Clippy(所有目标且告警视为错误)、格式检查及生成契约一致性检查均通过。

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T07:19:35.513970Z 60fdd92 Manual request
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2f88e91ee

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return false;
}
if returned >= self.maximum {
self.next_message.get_or_insert(self.first + returned);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 使用实际溢出命中的消息位置生成搜索游标

当匹配消息之间夹有不匹配消息时,self.first + returned 并不是当前溢出命中的 message_index;例如限制为 1、命中位于消息 11 和 21 时,第一页会把续页位置写成消息 2,后续页面将重复返回消息 11,并逐条推进大量无关消息。这里应保留当前 message_index,否则稀疏搜索结果会出现重复项和异常多的续页请求。

AGENTS.md reference: AGENTS.md:L9-L9

Useful? React with 👍 / 👎.

Comment on lines +89 to +90
.filter(|message| self.visible(message))
.nth(end - 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 不要用可见消息序号索引原始分支终点

当所选轮次之前存在 context_compactions 隐藏的摘要消息,并且所选轮次之后还有历史时,end 仍是原始消息数组的独占下标,但这里先过滤可见消息再执行 nth(end - 1),会把 lastMessageId 指向后续消息。例如隐藏一条摘要后对中间轮次 Fork,OpenCode 可能收到下一轮 user 的 ID 而拒绝请求,其他原生运行时则可能在错误的更晚位置创建分支;锚点应继续使用原始边界 messages[end - 1]。

AGENTS.md reference: AGENTS.md:L9-L9

Useful? React with 👍 / 👎.

Comment on lines +17 to +20
raw_turns_before(
self.session,
self.position.message + usize::from(self.position.offset > 0),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 避免在用户消息分片续读时重复累计轮次

当字节预算把一条 user 消息切成多个 fragment 时,续页游标的 offset > 0,这里已经把当前 user 消息计入 turn_prefix,而 context_page 随后处理该消息时还会再次执行 current_turn += 1。因此同一条消息第一页的 turn 为 N、后续 fragment 却变成 N+1,破坏分页前后稳定的消息轮次映射;前缀应只统计 position.message 之前的 user 消息。

AGENTS.md reference: AGENTS.md:L9-L9

Useful? React with 👍 / 👎.

@kzheart

kzheart commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

@codex fix the issues identified in your review.

请逐项修复本 PR 中你刚刚报告的问题,补充能够复现相应问题的回归测试,并运行相关检查。保留本次模块重构,将修复提交并推送到当前 PR 分支 codex/session-read-state。请用简体中文说明修改与验证结果,不要合并 PR。

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@kzheart

kzheart commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

@codex fix the issues identified in your review.

请逐项修复本 PR 中你刚刚报告的问题,补充能够复现相应问题的回归测试,并运行相关检查。保留本次模块重构,将修复提交并推送到当前 PR 分支 codex/session-read-state。请用简体中文说明修改与验证结果,不要合并 PR。

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@kzheart

kzheart commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

@codex fix the issues identified in your review.

请逐项修复本 PR 中你刚刚报告的问题,补充能够复现相应问题的回归测试,并运行相关检查。保留本次模块重构,将修复提交并推送到当前 PR 分支 codex/session-read-state。请用简体中文说明修改与验证结果,不要合并 PR。

@chatgpt-codex-connector

Copy link
Copy Markdown

修改总结

验证结果

  • ✅ cargo test --manifest-path crates/ferry-engine/Cargo.toml page_state::tests --lib(2 个测试通过)
  • ✅ cargo test --manifest-path crates/ferry-engine/Cargo.toml branch_point::tests --lib(5 个测试通过)
  • ✅ cargo test --manifest-path crates/ferry-engine/Cargo.toml --lib(860 个测试全部通过)
  • ✅ cargo fmt --manifest-path crates/ferry-engine/Cargo.toml -- --check
  • ✅ git diff --check
  • ✅ cargo clippy --manifest-path crates/ferry-engine/Cargo.toml --all-targets -- -D warnings -A clippy::unnecessary-cast
  • ⚠️ cargo clippy --manifest-path crates/ferry-engine/Cargo.toml --all-targets -- -D warnings(当前 Linux/Rust 工具链对仓库既有 src/adapters/codex/writer.rs:102 报告平台相关 clippy::unnecessary_cast;本次修改文件无 Clippy 问题)
  • ⚠️ git push -u origin codex/session-read-state(环境未配置 origin:fatal: 'origin' does not appear to be a git repository)

View task →

@kzheart

kzheart commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 60fdd92e93

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kzheart kzheart closed this Oct 10, 2026
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.

1 participant