fix(desktop): relink Codex thread across providers - #3543
Conversation
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5dd4d7000
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
| Filename | Overview |
|---|---|
| apps/desktop/src/main/maker-ipc/register.ts | 新增 thread relink 的数据库读取、Codex fork、owner/epoch 校验、CAS 更新与广播;当前 fork 使用了目标而非源 thread 的凭证上下文。 |
| apps/desktop/src/main/maker-ipc/runtimeSetModel.ts | 即时和 busy-deferred 切换接入 relink,但即时失败恢复旧 pending 时会丢失 rebuild 标记。 |
| apps/desktop/src/main/maker-ipc/pendingCredentialSwitch.ts | 延迟切换在路由落地和队列唤醒前执行 relink,并在失败时保留 pending 继续 gated。 |
| apps/desktop/src/main/maker-ipc/codexProviderThreadRelink.ts | 纯协调层正确执行 source 读取、fork、CAS commit,并在 owner 竞争失败时 fail closed。 |
| apps/desktop/src/main/maker-ipc/tests/codexProviderThreadRelink.test.ts | 覆盖成功、无 native thread 和 CAS 被抢占,但没有验证 fork 必须采用源 thread 的 provider/model 身份。 |
Sequence Diagram
sequenceDiagram
participant UI as 模型选择入口
participant Runtime as RuntimeSetModel
participant Live as Live Codex Session
participant Fork as Codex Fork Host
participant DB as Sessions DB
participant Queue as 输入队列
UI->>Runtime: 切换 provider/model
Runtime->>Queue: 保持 gated
Runtime->>Live: close session
Runtime->>Fork: 按源 thread 身份安全 fork
Fork-->>Runtime: newSdkSessionId
Runtime->>DB: CAS 替换 sdkSessionId
DB-->>Runtime: commit 成功
Runtime->>Runtime: 落地目标 provider
Runtime->>Queue: wake
Comments Outside Diff (1)
-
apps/desktop/src/main/maker-ipc/runtimeSetModel.ts, line 284-286 (link)已有 pending 的空闲切换在 close 成功但 relink 失败时,这里只恢复
model/providerId,丢失跨凭证族所需的rebuildCodexThread。后续重试会跳过 relink,直接落地新 provider 并唤醒队列,使sdkSessionId仍指向旧凭证族 thread,下一条消息因此会在不兼容来源下 resume 旧 thread。Context Used: 使用和PR描述相同的语言进行评论 (source)
Knowledge Base Used: Agent runtime
Prompt To Fix With AI
This is a comment left during a code review. Path: apps/desktop/src/main/maker-ipc/runtimeSetModel.ts Line: 284-286 Comment: **恢复时丢失重建标记** 已有 pending 的空闲切换在 close 成功但 relink 失败时,这里只恢复 `model/providerId`,丢失跨凭证族所需的 `rebuildCodexThread`。后续重试会跳过 relink,直接落地新 provider 并唤醒队列,使 `sdkSessionId` 仍指向旧凭证族 thread,下一条消息因此会在不兼容来源下 resume 旧 thread。 **Context Used:** 使用和PR描述相同的语言进行评论 ([source](https://app.greptile.com/review/custom-context?memory=instruction-0)) **Knowledge Base Used:** [Agent runtime](https://app.greptile.com/xindong/-/custom-context/knowledge-base/makecindy/cindy/-/docs/agent-runtime.md) --- For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Prompt To Fix All With AI
### Issue 1
apps/desktop/src/main/maker-ipc/register.ts:3143-3151
**Fork 凭证身份错误**
跨凭证族切换时,这里把目标 `model/providerId` 传给 `forkSdkSession`,但 Codex 的隔离 fork 契约要求使用源 thread 的身份解析 credential mode。这样 fork host 会按新来源启动后再 fork 旧来源 thread,导致缺少对应凭证时直接报未登录,或无法生成与源历史兼容的新 thread,使即时切换失败、延迟切换持续阻塞输入队列。
### Issue 2
apps/desktop/src/main/maker-ipc/runtimeSetModel.ts:284-286
**恢复时丢失重建标记**
已有 pending 的空闲切换在 close 成功但 relink 失败时,这里只恢复 `model/providerId`,丢失跨凭证族所需的 `rebuildCodexThread`。后续重试会跳过 relink,直接落地新 provider 并唤醒队列,使 `sdkSessionId` 仍指向旧凭证族 thread,下一条消息因此会在不兼容来源下 resume 旧 thread。
---
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): relink Codex thread across..." | Re-trigger Greptile
|
@zqchris 👋 这个 PR 还有 4 条 review conversation 没 resolve(apps/desktop/src/main/maker-ipc/register.ts / apps/desktop/src/main/maker-ipc/pendingCredentialSwitch.ts / apps/desktop/src/main/maker-ipc/runtimeSetModel.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。 如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。 |
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
cindy/apps/desktop/src/main/maker-ipc/pendingCredentialSwitch.ts
Lines 498 to 499 in 239d279
When a user replaces or cancels the pending switch after the relink CAS has completed, this stale finalizer returns without invoking relinkReceipt.rollback(). The new CAS guard only covers changes during the commit itself; fresh evidence is that generation changes during the subsequent persistRoute() await also reach this return with the abandoned thread already installed. Because this finalizer closed the live session, the replacement path can see no session and skip another relink, causing its route to resume the thread forked for the superseded provider.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
MagicLizi
left a comment
There was a problem hiding this comment.
独立审查(standard)有 1 条 P1,不能合并。
- [P1]
apps/desktop/src/main/maker-ipc/pendingCredentialSwitch.ts:498—finalizeApply在 relink CAS 成功后await persistRoute()。persist 失败会relinkReceipt.rollback(),但 persist 成功后若pending.get(sessionId) !== target直接return,不 rollback。register/clear不被applying挡住,所以 persist 窗口里取消或改选是可达的。结果:被放弃目标的 thread 仍写在sessions.sdk_session_id;shouldRelinkCodexThread在sess缺失时为 false,下一次发送会接着用已作废的 family thread。relink 进行中的取消已有测试,persist 成功后被 supersede 没有。请在 post-relink 的 generation 变化路径上await relinkReceipt.rollback()再 return,并补单测。
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
|
已在
验证:
@MagicLizi 请按最新 head 复核这一条 changes-requested。 |
…ad-reset Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3cb26b12ee
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
最新 head 验证:
@MagicLizi 请按最新 head 重新复核原 changes-requested。@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c9b5c36d4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7319ce02e0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
|
@codex review 最新批次 |
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b4f45e9ac
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
命中 UI 路径(apps/desktop/src/renderer/components/new-chat/ChatInput.tsx)但 description 未附界面效果证据——建议补充改动后效果:截图/录屏,或改动后界面的 HTML 页面(```html 代码块、.html 附件或在线预览链接),便于确认界面符合 DESIGN.md 设计规范 |
MagicLizi
left a comment
There was a problem hiding this comment.
独立审查(standard)有 1 条 P1,不能合并。上一轮 persist-supersede 的 rollback 已在当前 head 覆盖并有回归测试。
- [P1]
apps/desktop/src/main/windowsPackagedInstanceBarrier.ts:11— 相对main夹带92404b169b(fix(desktop): stabilize Windows startup barrier)及其测试。PR 描述范围是本地 Codex 跨 XD/OpenAI 包月换 thread,未包含 Windows 单例启动。请拆到独立 PR,或从本分支拿掉该 commit;若必须同批合入,在 Description 写清理由。验证:git log origin/main..HEAD --oneline -- apps/desktop/src/main/windowsPackagedInstanceBarrier.ts应为空。
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
9528e8c to
04663bf
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 04663bf7f9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1bdaa900b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0fc8d8e8e1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06f8b79eb1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@zqchris 👋 这个 PR 还有 3 条 review conversation 没 resolve(apps/desktop/src/main/maker-ipc/codexProviderThreadRelink.ts / apps/desktop/src/main/maker-ipc/pendingCredentialSwitch.ts / apps/desktop/src/main/maker-ipc/register.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。 如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。 |
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27922225e4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
这次改了什么
摘要
Codex 任务在 XD 网关与 OpenAI 包月来源之间切换时,不再直接续接由另一来源创建的原生 thread。切换会先关闭当前 live session,把旧 rollout 安全 fork 成不含供应商私有 reasoning payload 的新 thread,以 CAS 更新同一个 Cindy 任务的
sdkSessionId,再落地新来源并恢复排队输入。变更类型
feat新功能fix缺陷修复refactor/perf重构或性能优化docs/test/chore文档、测试或工程维护范围
UI 变化
怎么验证的
自动验证
手工验证
不涉及:未启动 Desktop DEV,未触碰真实模型账号或授权状态。
未执行的验证
pnpm test:unit曾执行:除本 PR 触发并已修正、重验通过的一条 Desktop 源码契约断言外,packages/maker-core仍有两条与本 PR 无关的 Pi 集成失败(xAI 用例 60 秒超时;BYOM 临时配置目录数量竞态)。本 PR 未改packages/maker-core。风险
风险分类
影响与回滚