fix(core): 修复 P0-2/3/4 (DB 释放 / lock race / state db schema)
- query: 引入 withReadDb 统一收口读连接生命周期,findSessions /
getMessageRange / getMessagePage / listSessionSummaries / collectStats
在异常路径下不再泄漏连接 (P0-2)
- sync-lock: 抽出 tryRemoveStaleLock,删除 stale lock 前二次比对
pid+createdAt,避免 TOCTOU 误删另一进程刚抢到的新 lock (P0-3)
- current: codex state db 缺 threads 表时抛 CurrentStateDbError,CLI
在 --json 下输出 {error:{code,message}} 并以非零退出 (P0-4)
测试: query.test.ts +1, cli.test.ts +2, 新建 sync-lock.test.ts (4 cases),
bun run check 通过 (37 pass)。
文档: 标记 P0-1 已在 be75d87 修复。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Entire-Checkpoint: dd6f619c0078