fix(desktop): use .run() for CAS clear of stale sdk_session_id (#3496) - #3525
fix(desktop): use .run() for CAS clear of stale sdk_session_id (#3496)#3525Battleplus wants to merge 2 commits into
Conversation
|
| Filename | Overview |
|---|---|
| apps/desktop/src/main/maker-host/session-storage.ts | 使用代理明确支持的 .run().changes 判断条件 UPDATE 是否命中,生产实现与现有数据库代理契约一致。 |
| apps/desktop/src/main/maker-host/tests/sessionStorageRemoteHostId.test.ts | mock 已适配 .run(),但新增并发用例通过手动切换返回值模拟结果,未验证 CAS 条件或数据库状态转换。 |
Prompt To Fix All With AI
### Issue 1
apps/desktop/src/main/maker-host/__tests__/sessionStorageRemoteHostId.test.ts:179-185
**并发测试未验证状态**
当前用例通过手动切换 `runResult` 来决定两次调用的结果,且 mock 的 `where()` 不检查条件表达式,因此即使实现遗漏 `sdkSessionId = expectedSdkSessionId` 谓词,该测试仍会通过。建议让第一次调用实际改变模拟数据库状态,并由第二次调用的条件匹配自然返回未命中,以覆盖旧恢复请求不得清除并发写入的新 ID 这一 CAS 契约。
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "fix(desktop): use .run() for CAS clear o..." | Re-trigger Greptile
| it('concurrent path: hit then miss, each call correct', async () => { | ||
| const storage = new DesktopSessionStorage(); | ||
| h.runResult = { changes: 1 }; | ||
| await expect(storage.compareAndClearSdkSessionId('s1', 'sdk-a')).resolves.toBe(true); | ||
| h.runResult = { changes: 0 }; | ||
| await expect(storage.compareAndClearSdkSessionId('s1', 'sdk-a')).resolves.toBe(false); | ||
| }); |
There was a problem hiding this comment.
当前用例通过手动切换 runResult 来决定两次调用的结果,且 mock 的 where() 不检查条件表达式,因此即使实现遗漏 sdkSessionId = expectedSdkSessionId 谓词,该测试仍会通过。建议让第一次调用实际改变模拟数据库状态,并由第二次调用的条件匹配自然返回未命中,以覆盖旧恢复请求不得清除并发写入的新 ID 这一 CAS 契约。
Context Used: 使用和PR描述相同的语言进行评论 (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/main/maker-host/__tests__/sessionStorageRemoteHostId.test.ts
Line: 179-185
Comment:
**并发测试未验证状态**
当前用例通过手动切换 `runResult` 来决定两次调用的结果,且 mock 的 `where()` 不检查条件表达式,因此即使实现遗漏 `sdkSessionId = expectedSdkSessionId` 谓词,该测试仍会通过。建议让第一次调用实际改变模拟数据库状态,并由第二次调用的条件匹配自然返回未命中,以覆盖旧恢复请求不得清除并发写入的新 ID 这一 CAS 契约。
**Context Used:** 使用和PR描述相同的语言进行评论 ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…indy#3496) The drizzle proxy over IPC does not serialize .returning() for UPDATE queries — it always returns []. This caused compareAndClearSdkSessionId() to report CAS failure even when the UPDATE succeeded, blocking the self-healing path for old Claude sessions that hit "No conversation found". Replace .returning() with .run() and check result.changes, matching the existing pattern in sessions.ts:1323. Also update the test mock to use .run() and split into three focused regression tests: CAS hit, CAS miss, and concurrent hit-then-miss. Fixes makecindy#3496 Signed-off-by: Battleplus <3559424769@qq.com> 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
701138d to
1073aef
Compare
|
@Battleplus 👋 这个 PR 还有 1 条 review conversation 没 resolve(apps/desktop/src/main/maker-host/tests/sessionStorageRemoteHostId.test.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。 如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。 |
MagicLizi
left a comment
There was a problem hiding this comment.
格式门未通过,请按仓库 PR 模板补全 Description 后再请求审查。
缺段落:这次改了什么 / 怎么验证的 / 风险
当前描述无法确认改动范围、验证证据和回滚风险。补全三个段落后推送或编辑 PR 即可重新进入审查。
Signed-off-by: Battleplus <3559424769@qq.com>
073370f to
bffb7ed
Compare
Battleplus
left a comment
There was a problem hiding this comment.
Updated PR description with required sections (这次改了什么/怎么验证的/风险). Re-requesting format gate review.
这些问题已在当前 head 的后续 commit 中修复(格式门/安全门已通过),自动 dismiss 旧的 CHANGES_REQUESTED 以解除合并阻塞。
问题
重开旧 Claude 会话时偶发 "No conversation found" 终态错误。根因是
compareAndClearSdkSessionId()通过 drizzle IPC 代理使用.returning(),但代理对 UPDATE 语句的 RETURNING 子句未实现,始终返回[],导致 CAS(compare-and-swap)即使 UPDATE 成功也报告失败,阻断了 invalid-resume 自愈路径。改动
session-storage.ts: 将.returning({ id })替换为.run(),按result.changes > 0判断 CAS 命中sessionStorageRemoteHostId.test.ts: 更新 mock 从.returning()改为.run(),拆分为3个回归测试(命中/未命中/并发)此模式与
sessions.ts:1323中已有的.run()用法一致。这次改了什么
2 个文件:
apps/desktop/src/main/maker-host/session-storage.ts— CAS 判定逻辑从.returning()改为.run()(3 行变化)apps/desktop/src/main/maker-host/__tests__/sessionStorageRemoteHostId.test.ts— mock 更新 + 新增 3 个回归测试怎么验证的
风险
.run()模式与现有sessions.ts:1323一致,非新模式result.changes在 IPC 层异常,行为与修复前相同(自愈失败),不会引入新问题Fixes #3496