Skip to content

fix(desktop): safely rebuild Codex thread across credential providers - #3586

Merged
MagicLizi merged 7 commits into
makecindy:mainfrom
zqchris:codex-provider-thread-relink-clean
Aug 29, 2026
Merged

fix(desktop): safely rebuild Codex thread across credential providers#3586
MagicLizi merged 7 commits into
makecindy:mainfrom
zqchris:codex-provider-thread-relink-clean

Conversation

@zqchris

@zqchris zqchris commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

这次改了什么

摘要

重新实现本地 Codex 任务在 XD 与 OpenAI 包月之间切换时的 thread 安全重建,替代已关闭且范围失控的 #3543。fork 始终使用源 thread 的凭证身份;新 sdk_session_id 与目标 model/provider/effort/fast 在同一条 SQLite CAS 中提交。任务忙碌或提交条件变化时直接失败,不建立 deferred/pending 状态机。

变更类型

  • feat 新功能
  • fix 缺陷修复
  • refactor / perf 重构或性能优化
  • docs / test / chore 文档、测试或工程维护
  • 其他:

范围

  • 关联 Issue / 需求:替代已关闭的 fix(desktop): relink Codex thread across providers #3543
  • 本 PR 包含:本地 Codex、用户主动选择、已有持久 thread、仅 XD ↔ OpenAI 包月两个方向;源身份 fork、完整路由原子 CAS、忙碌/竞态 fail-closed。
  • 明确不包含:Device Link、IM model:pick、agent/fallback/scheduler、远程 host、其它 provider/agent、授权与模型目录、Windows 启动屏障、通用 pending 恢复状态机。
  • 用户可见变化:空闲本地 Codex 任务跨上述两类凭证切换时会创建兼容的新 thread;忙碌时明确失败并要求稍后重试,不会后台延迟切换。
  • 是否存在 breaking change:无。

UI 变化

  • 引用的设计规范:不涉及;纯 main-process 逻辑与单测,无视觉、交互或文案变化。

怎么验证的

自动验证

pnpm --filter desktop exec vitest run src/main/maker-ipc/__tests__/codexProviderThreadRelink.test.ts src/main/maker-ipc/__tests__/runtimeSetModelCodexRelink.test.ts src/main/maker-ipc/__tests__/runtimeSetModel.test.ts
结果:3 files / 36 tests passed

pnpm --filter desktop run --if-present typecheck
结果:通过

pnpm check:dco
结果:1 commit signed off

pnpm test:unit:related
结果:Desktop、Mobile 及其余已执行 workspace 通过;总命令被未改动的 packages/maker-core 两条 Pi 集成测试拦截(xAI baseline 60s 超时;BYOM 临时配置目录期望 1 个但发现 2 个)。精确重跑同一未改动测试文件仍复现,本 PR 未修改 maker-core。

手工验证

不涉及;未启动 Desktop DEV。

未执行的验证

未做实机切换;遵守本仓禁止未经明确授权启动 Desktop DEV 的约束。完整 CI 交由 PR 门禁执行。

风险

风险分类

  • 无已知风险
  • SQLite / migration
  • system prompt
  • 协议兼容
  • 权限 / 安全 / 用户数据
  • 存量插件兼容(批准状态 / 指纹 / manifest 校验 / 安装布局 / 包格式)
  • 原生层 / fingerprint / OTA
  • 跨平台差异
  • 其他:

影响与回滚

  • 影响范围:仅本地 Codex 的 XD ↔ OpenAI 包月显式切换;复用现有 sessions 表,不新增 schema 或 migration。
  • 回滚 / 降级方式:回退本提交即可恢复原有行为;CAS 失败时不会提交目标路由。

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名(git commit -s,见 DCO
  • UI 改动已在「UI 变化」注明引用的设计规范章节(不涉及 UI 则跳过)
  • 未提交凭证、令牌或授权文件
  • 已补充必要文档
  • 已确认测试结果或说明未执行原因

Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
@zqchris
zqchris marked this pull request as ready for review August 28, 2026 17:37
@zqchris
zqchris requested a review from a team as a code owner August 28, 2026 17:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f4f4acb49

ℹ️ 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".

Comment thread apps/desktop/src/main/maker-ipc/runtimeSetModel.ts
Comment thread apps/desktop/src/main/maker-ipc/codexProviderThreadRelink.ts Outdated
@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown

Greptile Summary

该 PR 为本地 Codex 在 XD 与 OpenAI 订阅凭证之间切换时增加安全的 thread 重建流程,并通过 SQLite CAS 原子提交新 thread ID 与完整目标路由。

  • 使用源 thread 的模型、provider 和工作目录执行 fork
  • 对忙碌任务采用 fail-closed,不登记 deferred 切换
  • 同时提交 model、provider、effort、fast mode 与新 sdk session ID
  • 增加独立 relink 与运行时切换测试

Confidence Score: 5/5

未发现需要阻止合并的具体缺陷,该 PR 看起来可以安全合并。

新流程在持有 session 路由锁时检查忙碌状态,使用源凭证 fork,并通过 CAS 原子提交新 thread 与完整目标路由;调查到的竞态方向均缺少可达故障链。

Important Files Changed

Filename Overview
apps/desktop/src/main/maker-ipc/codexProviderThreadRelink.ts 新增独立的源 thread 读取、fork 与 CAS 提交编排,失败时保持 fail-closed。
apps/desktop/src/main/maker-ipc/runtimeSetModel.ts 为需要重建的 Codex 跨凭证切换增加忙碌拒绝、关闭会话、relink 和持久化完成标记。
apps/desktop/src/main/maker-ipc/register.ts 接入数据库快照、源凭证 fork、完整路由 CAS 和广播,并避免随后重复持久化。
apps/desktop/src/main/maker-ipc/tests/codexProviderThreadRelink.test.ts 覆盖凭证方向过滤、源身份 fork、无持久 thread 及 CAS 竞争失败。
apps/desktop/src/main/maker-ipc/tests/runtimeSetModelCodexRelink.test.ts 覆盖空闲、忙碌、关闭前竞态以及无 live session 的 relink 行为。

Sequence Diagram

sequenceDiagram
    participant UI as 本地 Renderer
    participant IPC as Desktop IPC
    participant Runtime as RuntimeSetModel
    participant Maker as Codex Runtime
    participant DB as SQLite
    UI->>IPC: 选择目标 model/provider/effort/fast
    IPC->>IPC: 校验本地 Codex、持久 thread、XD↔OpenAI
    IPC->>Runtime: applyRuntimeSetModelChange
    Runtime->>Runtime: 检查任务是否忙碌
    alt 任务忙碌
        Runtime-->>UI: 拒绝并要求稍后重试
    else 任务空闲
        Runtime->>Maker: 关闭 live session
        Runtime->>Maker: 使用源凭证 fork thread
        Maker-->>Runtime: newSdkSessionId
        Runtime->>DB: CAS 提交新 thread 与完整目标路由
        DB-->>Runtime: 提交成功
        Runtime-->>UI: applied / persistedRoute
    end
Loading

Reviews (1): Last reviewed commit: "fix(desktop): rebuild Codex thread acros..." | Re-trigger Greptile

Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2d5489bd7

ℹ️ 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".

Comment thread apps/desktop/src/main/maker-ipc/register.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
@MagicLizi

Copy link
Copy Markdown
Contributor

@zqchris 👋 这个 PR 还有 1 条 review conversation 没 resolve(apps/desktop/src/main/maker-ipc/runtimeSetModel.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

@MagicLizi MagicLizi added status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) labels Aug 28, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6974fc9186

ℹ️ 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".

Comment thread apps/desktop/src/main/maker-ipc/register.ts
Comment thread apps/desktop/src/main/maker-ipc/register.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b5c5afcec

ℹ️ 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".

Comment thread apps/desktop/src/main/maker-ipc/register.ts
@MagicLizi

Copy link
Copy Markdown
Contributor

@zqchris 👋 这个 PR 还有 3 条 review conversation 没 resolve(apps/desktop/src/main/maker-ipc/runtimeSetModel.ts / apps/desktop/src/main/maker-ipc/register.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

@MagicLizi MagicLizi added status:ci-failed CI 失败(review-pr 自动维护,仅展示) and removed status:awaiting-bot-review 等外部审查机器人表态(review-pr 自动维护,仅展示) labels Aug 28, 2026
@zqchris

zqchris commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

当前所有 review conversation 已按本 PR 的既定范围处理并 resolve:契约内意见已完成修复;Profile 生命周期串行化、pending/队列恢复与 Device Link 等越界项已按 Chris 的范围裁决不纳入本 PR。当前 head 可继续进行合并审查,请按现有代码与已确认边界重新检查。

@zqchris

zqchris commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

请按当前 head 7b5c5afcec97daecc6ccdac316042a7d9254d542 重新审查本 PR。

本批意见均已在对应 review thread 中逐条公开说明并 resolve:

  • deferred/pending 与队列恢复不属于本 PR;当前保持忙碌任务 fail-closed。
  • Device Link、移动端及跨设备 thread 生命周期不属于本 PR;当前仅覆盖本地 Renderer 的 XD ↔ OpenAI Codex thread relink。
  • Profile owner/epoch 生命周期与 CAS 串行化需要独立的 Profile/数据库边界设计,不属于本 PR。
  • relink 失败的 IPC 错误边界与旧三参数调用路径已按当前实现补齐,并保留相应的结构化错误与完整路由提交语义。

请基于当前 head 和上述已处理边界继续审查。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b5c5afcec

ℹ️ 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".

Comment thread apps/desktop/src/main/maker-ipc/register.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb16ce0a7a

ℹ️ 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".

Comment thread apps/desktop/src/main/maker-ipc/register.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf64fe9119

ℹ️ 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".

Comment thread apps/desktop/src/main/maker-ipc/codexProviderThreadRelink.ts Outdated
Signed-off-by: Chris <4436110+zqchris@users.noreply.github.com>
@MagicLizi MagicLizi removed the status:ci-failed CI 失败(review-pr 自动维护,仅展示) label Aug 29, 2026

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码重审通过:当前 head 未发现 P0/P1。凭证源切换时重建 Codex thread 的 CAS/清理路径,未发现安全/正确性问题。

@MagicLizi
MagicLizi merged commit 2a1dd08 into makecindy:main Aug 29, 2026
10 checks passed
@MagicLizi

Copy link
Copy Markdown
Contributor

合了。换凭证时把 Codex thread 重建成可继续的会话,busy 直接失败、CAS 绑在替换线程上,比留下半截状态要踏实。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants