Skip to content

fix: 删除会话后清理 session_index.jsonl 并移除 scheduleScan 残留调用 - #1887

Open
xiaoyang-1999 wants to merge 2 commits into
BigPizzaV3:mainfrom
xiaoyang-1999:fix/session-delete-index-and-hover-actions
Open

fix: 删除会话后清理 session_index.jsonl 并移除 scheduleScan 残留调用#1887
xiaoyang-1999 wants to merge 2 commits into
BigPizzaV3:mainfrom
xiaoyang-1999:fix/session-delete-index-and-hover-actions

Conversation

@xiaoyang-1999

Copy link
Copy Markdown

修复两个从 v1.2.47 开始就存在的问题

问题一:删除会话后列表残留(Windows 环境复现)

Windows 上删完会话,列表里还挂着,点进去提示 no rollout found,再删一次又提示 Thread not found in local storage

查下来是删除时只清了 SQLite 里的 threads 表和相关 rollout 文件,但 ~/.codex/session_index.jsonl(新版 Codex 的会话列表索引)里对应的那行没动,列表自然清不干净。

这次把删除流程补齐了:

  • SQLite 删除成功后,同步把 session_index.jsonl 里对应的条目移除,写入走原子写,避免把文件写坏
  • 被删掉的索引行会一起放进备份里,撤销删除(undo)时能把索引也恢复回来,不会出现"数据回来了但列表里看不到"的情况
  • 加了一个回归测试,覆盖删除 + undo 的完整往返

问题二:会话行操作按钮不显示

v1.2.47 移除 pluginAutoExpand 功能时,函数定义删了,但 scheduleScan 里漏了一处调用没删干净。结果每次 DOM 变化,MutationObserver 回调都先抛 TypeError: schedulePluginAutoExpand is not a function,后面的自动重扫根本执行不到。表现就是启动后鼠标悬停会话行不出现删除/导出按钮,必须点一下右上角 Codex++ 菜单(菜单会直接触发一次 scan)按钮才出来。

修复就是把 scheduleScan 里那行残留调用删掉。

验证

  • Windows 本地 + WSL 跑 cargo test -p codex-plus-data,全部通过(含新增用例)
  • jsdom 复现确认 MutationObserver 不再抛 schedulePluginAutoExpand is not a function

@BigPizzaV3

Copy link
Copy Markdown
Owner

感谢修复。当前删除/undo 逻辑还有一个会操作错误路径的问题,暂时不能直接合并:

SQLiteStorageAdapter 通过 self.db_path.parent() 推断 Codex home,然后把该目录传给 session_index_*。当数据库使用新版布局 ~/.codex/sqlite/codex-dev.db 时,这里得到的是 ~/.codex/sqlite,最终会读写 ~/.codex/sqlite/session_index.jsonl;实际索引位于 ~/.codex/session_index.jsonl。undo 恢复也有同样问题。

现有测试把数据库和 session_index.jsonl 都放在临时目录根部,因此没有覆盖这个真实布局。请改为复用项目现有的 Codex home/数据库路径解析逻辑,并补一个 <home>/sqlite/codex-dev.db + <home>/session_index.jsonl 的删除和 undo 回归测试。

移除残留 schedulePluginAutoExpand() 调用这一部分是正确的;路径问题修正后可以继续合并评估。

xiaoyang added 2 commits August 19, 2026 09:54
When a Codex thread is deleted, the DB row and rollout file were removed
but the matching line in ~/.codex/session_index.jsonl was left behind, so
the session kept appearing in the Codex sidebar (and reopening it failed
with "no rollout found").

- Keep the removed session_index lines in the backup (__session_index)
  so undo restores them.
- Remove the index entry atomically after the delete commits; failures
  are reported in the result message but do not fail the delete.
- Resolve the Codex home explicitly (default_codex_home_dir) instead of
  deriving it from the DB path parent, so the new <home>/sqlite/codex-dev.db
  layout updates <home>/session_index.jsonl as well.
- Add regression tests covering delete + undo for both the legacy
  <home>/state_5.sqlite and the <home>/sqlite/ layouts.
v1.2.47 removed the pluginAutoExpand feature (function definition and the
call inside scanDeferred) but left a dangling call in scheduleScan.
Every MutationObserver callback then threw
"schedulePluginAutoExpand is not a function" before scan() could be
scheduled, so session-row action buttons were never attached until
something called scan() directly (e.g. opening the Codex++ menu).
@xiaoyang-1999
xiaoyang-1999 force-pushed the fix/session-delete-index-and-hover-actions branch from 2f13775 to 5decfe0 Compare August 19, 2026 02:01
@xiaoyang-1999

xiaoyang-1999 commented Aug 19, 2026

Copy link
Copy Markdown
Author

感谢修复。当前删除/undo 逻辑还有一个会操作错误路径的问题,暂时不能直接合并:

SQLiteStorageAdapter 通过 self.db_path.parent() 推断 Codex home,然后把该目录传给 session_index_*。当数据库使用新版布局 ~/.codex/sqlite/codex-dev.db 时,这里得到的是 ~/.codex/sqlite,最终会读写 ~/.codex/sqlite/session_index.jsonl;实际索引位于 ~/.codex/session_index.jsonl。undo 恢复也有同样问题。

现有测试把数据库和 session_index.jsonl 都放在临时目录根部,因此没有覆盖这个真实布局。请改为复用项目现有的 Codex home/数据库路径解析逻辑,并补一个 <home>/sqlite/codex-dev.db + <home>/session_index.jsonl 的删除和 undo 回归测试。

移除残留 schedulePluginAutoExpand() 调用这一部分是正确的;路径问题修正后可以继续合并评估。

感谢建议!已按 review 意见改好了:

  • SQLiteStorageAdapter 不再用 db_path.parent() 推断 Codex home,改为显式传入 default_codex_home_dir()(launcher 的 delete / undo 和 manager 的 delete_local_session 都已传入)
  • 删除和 undo 恢复 session_index.jsonl 共用同一份 home,兼容新版 <home>/sqlite/codex-dev.db 布局
  • 新增 <home>/sqlite/codex-dev.db + <home>/session_index.jsonl 的删除 + undo 回归测试,旧布局测试也保留并同样显式传 home

验证:cargo test -p codex-plus-data 全部通过(storage 22 个、provider_sync 32 个),cargo check -p codex-plus-launcher 通过。

麻烦再帮忙看下,谢谢。

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