feat: support independent SQLite home across CLI and desktop apps - #55
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 153b067e6c
ℹ️ 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".
Dailin521
left a comment
There was a problem hiding this comment.
感谢提交。我们已经针对当前提交 7769705 在真实的 Windows 11、WSL 2.7.11 和 Ubuntu 24.04 环境中完成了 Windows GUI 与 Core 实测。
本地独立 SQLite Home 场景验证通过:状态读取、显式路径隔离、禁止回退到 stale database、同步、v2 备份及恢复均正常。因此,SQLite Home 与 Codex Home 分离的主体实现是有效的。
但 PR 当前明确宣称支持 Windows GUI 通过 \\wsl.localhost\<distro>\... 直接处理 WSL 文件系统中的 SQLite,这一核心场景实测未通过:
- GUI 能正确接受并解析 WSL UNC 路径,也没有回退到 Windows Codex Home 中的 stale database;
- 读取状态会等待约 60–65 秒,随后报告
state_5.sqlite is currently in use; - 测试期间没有 Windows 或 WSL 进程占用该数据库,WSL 内部可以正常读取;
- 关闭 GUI 后,直接调用当前 PR 的 Core 代码仍能稳定复现相同结果。
这些证据表明该错误并非实际的数据库占用,而是 Windows 进程通过 WSL UNC/9P 访问 SQLite 时的文件锁兼容问题。SQLite 依赖可靠的文件锁语义,直接对该路径执行写入、备份或恢复不能视为安全支持。微软也建议让工具和文件位于同一操作系统文件系统,SQLite 官方则明确提醒网络文件系统的锁实现可能不可靠:
- https://learn.microsoft.com/en-us/windows/wsl/setup/environment
- https://sqlite.org/faq.html
- https://www.sqlite.org/howtocorrupt.html
因此,请在合并前至少完成以下修改:
- 检测
\\wsl.localhost\.../\\wsl$\...SQLite Home,并禁止 Windows 进程直接执行sync、switch、backup和restore等写入操作; - 对此场景提供准确的诊断信息,避免误导用户去关闭 Codex 后重复尝试;
- 相应修正 PR 描述、Windows GUI 文档和支持范围;
- 增加真实 Windows + WSL ext4 SQLite 集成测试,覆盖读取超时以及写入、备份、恢复的安全边界,而不仅是 UNC 路径解析。
如要保留“Windows GUI 直接管理 WSL SQLite Home”的支持声明,建议改为检测发行版与 Linux 路径后,通过 wsl.exe -d <distro> 在 WSL 内部执行 SQLite 操作,并为同步、备份及恢复增加端到端验证。该完整实现也可以拆分为后续 PR;但当前 PR 应先建立安全阻断并缩小支持声明,再继续合并审查。
|
感谢实测和说明。确认这个问题不是数据库被占用,而是 Windows 通过 WSL UNC 路径访问 SQLite 时,文件锁语义不可靠。 我已经按建议调整:
另外增加了真实 Windows + WSL ext4 SQLite 测试。测试会从 WSL 创建数据库,再调用 Windows Core,确认状态查询可以快速返回,相关写操作会提前停止,并且数据库、配置、rollout 和备份目录都保持不变。 本地测试结果:
|
Dailin521
left a comment
There was a problem hiding this comment.
已对提交 a770f339 完成真实 Windows 11 + WSL 2.7.11 + Ubuntu 环境验证。Windows GUI 使用真实 \\wsl.localhost\\Ubuntu\\... SQLite Home 时约 256ms 返回专用安全诊断,同步与恢复按钮正确禁用;有效 SQLite 数据库哈希未变化,配置、rollout 与备份目录均无副作用。本地独立 SQLite Home 的同步、备份、恢复以及 Codex Home A→B override 隔离也已验证通过。macOS Core/Release CI 已通过;由于暂无 Mac 设备,真实 macOS GUI 手测按约定保留为未完成项,不作为本次合并阻塞。
背景
当 Codex Desktop 使用 WSL agent 时,Codex Home 与 SQLite Home 可能位于不同的文件系统中。例如:
现有实现默认从 Codex Home 下查找
state_5.sqlite,没有把 SQLite Home作为独立存储位置处理。这会同时影响两种使用方式:
在这些场景下,
status、sync、switch、backup和restore可能找不到实际数据库,或者错误处理 Codex Home 中遗留的 stale database。
本 PR 将 SQLite Home 从 Codex Home 中独立出来,让 CLI、Windows GUI
和 macOS GUI 使用统一的路径解析与安全策略。
Related: #50
改动内容
统一 SQLite Home 解析
CLI 和桌面端现在采用相同的优先级:
--sqlite-home/ GUI overrideconfig.toml根级sqlite_homeCODEX_SQLITE_HOME<Codex Home>/sqlite只有默认布局允许回退到旧路径
<Codex Home>/state_5.sqlite。显式指定的 SQLite Home 如果缺少
state_5.sqlite:status/ GUI“刷新”只显示诊断信息sync、switch和restore直接失败CLI
status、sync、switch、watch、backup和restore增加独立 SQLite Home 支持watch在配置变化后重新解析 SQLite Home,并动态重绑 DB、WAL 和 SHM watcher备份与恢复
sqliteHome和sqliteDbFilesdbFilesconfig.toml--sqlite-home和--allow-sqlite-home-relocationWindows 与 macOS GUI
config.tomlWindows GUI 支持通过\\wsl.localhost\<distro>\...选择位于 WSL 文件系统中的 SQLite Home。CI 与文档
验证
win-x64self-contained single-file publishstatus真实环境验证命令: