Skip to content

refactor(sessions): 拆分会话读取与分页视图 - #4

Closed
kzheart wants to merge 1 commit into
mainfrom
codex/session-read-consolidation
Closed

kzheart wants to merge 1 commit into
mainfrom
codex/session-read-consolidation

Conversation

@kzheart

@kzheart kzheart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

会话读取模块同时承担参数校验、游标身份、元数据组装、消息分片和搜索摘要,分支点逻辑也重复遍历可见消息。此次拆分这些职责,集中维护读取视图和分页相关逻辑。

  • 提取 ContextOptions、SearchOptions 与 ReadScope,统一读取参数和游标绑定。
  • 提取 SessionView,集中处理可见轮次、页面位置、检查点摘要及派生元数据。
  • 将 DTO 元数据、UTF-8 block 分片与搜索文本窗口分别移入独立模块。
  • 保留既有公开读取函数和调用入口,并补充参数默认值与边界校验用例。

验证:会话模块 137 个测试、分页集成 3 个测试、cargo clippy --all-targets -- -D warnings、cargo fmt --check、生成契约一致性检查均通过。

@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-10T06:25:07.178382Z 47ab7c3 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.

@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: 47ab7c3925

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

Comment on lines +99 to +102
projected
.blocks
.retain(|block| block.kind != BlockKind::Tool);
projected

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 保留工具块参与分支点摘要

checkpoint_messages 删除了全部 BlockKind::Tool,因此签发分支点后,只要会话的工具输入或结果被更新而文本块不变,BranchPoint::resolve 仍会接受旧 token。这样 --through 读取或原生 fork 会基于已变化的工具历史继续执行,违反 NATIVE-FORK.md 中“前缀被改写会拒绝”且边界包含工具调用及结果的契约;摘要应继续覆盖完整前缀。

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

Useful? React with 👍 / 👎.

Comment on lines +49 to +51
&& last
.turn_complete
.unwrap_or_else(|| last.source_id.as_deref().is_some_and(|id| !id.is_empty()))

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 要求显式的原生完成标记

当 assistant 消息没有完成证据时,Pi、Claude 和 OpenCode reader 会留下 turn_complete = None,但仍通常设置非空 source_id;这里把这种消息判为已完成,会让活跃、截断或旧格式记录出现在 completed_turns 中,并允许 BranchPoint::issue 为不完整回答签发 fork 边界。原实现只接受 Some(true),而 NATIVE-FORK.md 也明确要求缺少原生完成证据时拒绝入口。

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

Useful? React with 👍 / 👎.

Comment on lines +67 to +69
first,
self.outputs,
self.through

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 将 inert 重新加入上下文游标绑定

当调用方用 inert=false 获取第一页、再携同该 next_cursor 以 inert=true 续读(或反向操作)时,这个摘要与原实现不同,未包含 self.inert,所以游标不会因读取参数变化而被拒绝。若游标位于经过 strip_text 改写的 block 分片中,同一字节偏移会被应用到不同的 JSON 编码,造成片段缺失、无法重组或意外的 cursor_invalid;应像 search_binding 一样绑定 inert。

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

Useful? React with 👍 / 👎.

Comment on lines +37 to +40
pub fn char_find(haystack: &str, needle: &str) -> Option<usize> {
haystack
.find(needle)
.map(|byte| haystack[..byte].encode_utf16().count())

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 使用 Unicode 标量计算匹配位置

char_find 现在返回 UTF-16 code unit 数,而 TextWindow::around 和 char_slice 仍按 Rust char 下标切片;命中前存在非 BMP 字符时两个坐标系会分离。例如 300 个 emoji 后的命中会被报告为位置 600,窗口从第 360 个字符开始,直接把真实命中排除在 snippet 外;复用该函数的内容索引摘要同样受影响。这里应恢复按 .chars().count() 计算的位置。

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

Useful? React with 👍 / 👎.

@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