feat: add session delete command with backup and sqlite cleanup#8
Open
mayii2001 wants to merge 1 commit intoDailin521:mainfrom
Open
feat: add session delete command with backup and sqlite cleanup#8mayii2001 wants to merge 1 commit intoDailin521:mainfrom
mayii2001 wants to merge 1 commit intoDailin521:mainfrom
Conversation
Dailin521
previously requested changes
Apr 17, 2026
Owner
Dailin521
left a comment
There was a problem hiding this comment.
Thanks for putting this together. The feature is useful, but I found two blocking issues in the current implementation.
Blocking:
runDeleteSessions()deletes rollout files before deleting SQLite rows, but there is no rollback path if the SQLite delete fails. I reproduced this locally by holding aBEGIN IMMEDIATElock onstate_5.sqlite: the command throws a locked error, the rollout file is already gone, and the thread row is still present. That leaves the system in the exact partial state this command is supposed to avoid.deleteSqliteThreadsByIds()only deletes fromthread_dynamic_tools,thread_spawn_edges, andthreads. The current realstate_5.sqliteschema also includesstage1_outputs.thread_id, andPRAGMA foreign_keysis off by default. I reproduced this on a temp DB matching the current schema: after delete,threads=0butstage1_outputs=1, so the command leaves orphaned rows behind.
Please make the delete path atomic/recoverable and cover all thread-linked tables that exist in the current schema before this can be merged.
Dailin521
requested changes
Apr 17, 2026
Owner
Dailin521
left a comment
There was a problem hiding this comment.
感谢提交,这个功能方向是对的,但当前实现里有两个阻塞问题。
阻塞问题:
runDeleteSessions()现在是先删除 rollout 文件,再删除 SQLite 行;如果 SQLite 删除失败,没有回滚路径。我本地已经复现过:对state_5.sqlite持有BEGIN IMMEDIATE锁后执行删除,会抛出 locked 错误,但 rollout 文件已经删除,而 thread 行仍然还在。这样会留下这个命令本来想避免的半完成状态。deleteSqliteThreadsByIds()目前只删除了thread_dynamic_tools、thread_spawn_edges和threads。但当前真实state_5.sqliteschema 里还有stage1_outputs.thread_id,而且PRAGMA foreign_keys默认是关闭的。我按当前 schema 做了本地复现:删除后threads=0,但stage1_outputs=1,会留下孤儿数据。
建议在合并前至少补齐两件事:
- 让 delete 路径具备原子性或失败可恢复语义。
- 覆盖当前 schema 中所有与 thread 关联的表,并补对应集成测试。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
当前 Codex 桌面版不能删除 session。
需要一个可按 session id 精确删除的能力,避免手工删文件导致 rollout 与 SQLite 状态不一致。
目标
修改内容
CLI / Node
codex-provider delete <session-id> [more-session-ids...] [--keep N] [--codex-home PATH]~/.codex/sessions、~/.codex/archived_sessionsstate_5.sqlite中threads以及关联表引用status/sync/switch/restore/prune-backups既有逻辑文档
README.md、README_ZH.md、README_EN.md、AGENTS.md验证
npm test(通过,24 passed)<填写><通过/失败>threads.id已删除:<通过/失败>codex-provider statuscodex-provider sync --provider <provider>codex-provider switch <provider>codex-provider prune-backups --keep <n>影响范围
回滚方案
codex-provider restore <backup-dir>