Skip to content

fix(desktop): preserve custom OAuth route on first Claude turn - #3289

Open
nothingyuancando wants to merge 4 commits into
makecindy:mainfrom
nothingyuancando:fix/3279-custom-provider-oauth-route
Open

fix(desktop): preserve custom OAuth route on first Claude turn#3289
nothingyuancando wants to merge 4 commits into
makecindy:mainfrom
nothingyuancando:fix/3279-custom-provider-oauth-route

Conversation

@nothingyuancando

Copy link
Copy Markdown
Contributor

这次改了什么

摘要

修复 Claude Code 新会话首个 turn 尚未产生 SDK session id 时,显式选择的自定义 OAuth 供应商可能回落到 XD 网关的问题。

变更类型

  • fix 缺陷修复

范围

  • 关联 Issue / 需求:bug: 自定义供应商模型被错误回退路由到官方 XD 网关导致间歇性 400 报错 #3279
  • 本 PR 包含:为本地 Claude Code 会话注入主进程签发的短期路由证明;代理验证该证明后直接使用 Cindy session 的 provider 路由;所有请求在出站前移除内部 headers。
  • 明确不包含:OAuth 刷新策略、标题 one-shot 路由及远端 Claude Code 会话。
  • 用户可见变化:自定义 OAuth 供应商的首个 Claude Code turn 不再错误发送到 XD。
  • 是否存在 breaking change:无。

UI 变化

  • 引用的设计规范:不涉及:仅修改 Desktop main、代理和 Agent 环境组装,没有 UI 变化。

怎么验证的

自动验证

pnpm --filter @cindy/maker-core exec vitest run src/agents/claude-code/__tests__/env-builder.test.ts
结果:34 passed

pnpm --filter desktop exec vitest run src/main/maker-host/__tests__/claudeSessionRouteObservation.test.ts
结果:10 passed

pnpm --filter desktop typecheck
结果:passed

pnpm test:unit:related
结果:passed

pnpm check:dco
结果:passed

手工验证

不涉及:需要真实 Kimi OAuth 的 Windows 环境,已用代理路由回归覆盖首轮无 SDK id 的时序。

未执行的验证

Windows + Kimi Code OAuth 真实请求未执行;该环境需要用户账号与系统代理。

风险

风险分类

  • 权限 / 安全 / 用户数据
  • 跨平台差异

影响与回滚

  • 影响范围:本地 Claude Code 会话请求的内部路由 header;仅当本地兼容代理已就绪才注入,且代理在转发前剥离。
  • 回滚 / 降级方式:回滚本 PR 后恢复原有 SDK session id 反查路径;代理不可用时本 PR 保持既有直连降级,不注入 header。

提交前检查

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

Signed-off-by: nothingyuancando <1579035512@qq.com>
@nothingyuancando
nothingyuancando requested a review from a team as a code owner August 23, 2026 08:00

@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: 37b3e55d31

ℹ️ 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-host/anthropic-compat-proxy-host.ts Outdated
Comment thread apps/desktop/src/main/maker-host/anthropic-compat-proxy-host.ts Outdated
@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown

Greptile Summary

本次变更为本地 Claude Code 会话增加由主进程签发的短期路由证明,使首个尚无 SDK session id 的请求仍能使用 Cindy 会话选定的自定义 OAuth provider。

  • 在 Desktop 主进程中注册、验证、替换并撤销每会话路由证明
  • 通过 Claude Code 环境变量向本地兼容代理传递内部路由头
  • 在代理所有出站路径统一剥离内部头,并拒绝无效或过期的证明
  • 补充首次路由、实例替换、启动失败、崩溃清理及非 JSON 转发测试

Confidence Score: 5/5

当前实现已覆盖先前指出的令牌生命周期缺口,未发现仍会阻止合并的故障。

未发现阻塞性故障仍然存在。

Important Files Changed

Filename Overview
apps/desktop/src/main/maker-host/anthropic-compat-proxy-host.ts 新增每会话路由证明的签发、恒时验证、实例替换保护及代理级内部头剥离配置。
packages/maker-core/src/agents/claude-code/index.ts 本地会话启动时取得路由证明,并在正常关闭、启动失败和失效 handle 清理路径撤销注册。
packages/maker-core/src/agents/claude-code/env-builder.ts 将主进程提供的路由证明安全地组装进本地 Claude Code 子进程环境。
packages/anthropic-compat-proxy/src/server.ts 在统一上游请求构造阶段删除配置的内部 headers,覆盖 JSON、非 JSON及恢复重试。
packages/anthropic-compat-proxy/src/types.ts 扩展代理选项以声明所有转发请求都必须删除的内部 headers。
packages/maker-core/src/agents/claude-code/tests/forward-loop-crash-teardown.test.ts 验证启动失败、流循环崩溃及自然终止时路由证明均被正确撤销。

Sequence Diagram

sequenceDiagram
    participant Host as Desktop 主进程
    participant Agent as Claude Code 会话
    participant Proxy as 本地兼容代理
    participant Provider as 自定义 OAuth Provider
    Host->>Host: 签发 session id + 短期 token
    Host->>Agent: 通过环境变量注入内部请求头
    Agent->>Proxy: 首个请求(尚无 SDK session id)
    Proxy->>Proxy: 验证 token 并解析 Cindy session 路由
    Proxy->>Proxy: 删除内部 session/token 头
    Proxy->>Provider: 使用选定 provider 的上游与凭证转发
    Host->>Host: 会话关闭、启动失败或崩溃时撤销注册
Loading

Reviews (4): Last reviewed commit: "fix(maker-core): revoke proxy auth on st..." | Re-trigger Greptile

Comment thread apps/desktop/src/main/maker-host/anthropic-compat-proxy-host.ts Outdated
@MagicLizi

Copy link
Copy Markdown
Contributor

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

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

@MagicLizi MagicLizi added the touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) label Aug 23, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

这条 PR 触发了维护者确认(架构)。它在 maker-core 的 AgentDeps、Claude Code 环境变量和 Desktop 本地代理之间加了一套新的会话路由证明,不只是单文件 bugfix。

请维护者在 PR 上 Approve 放行;若要改,请 Request Changes。讨论 issue:#3292

@MagicLizi MagicLizi added the awaiting-discussion 等待维护者讨论(review-pr) label Aug 23, 2026
Signed-off-by: nothingyuancando <1579035512@qq.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: 38193d2f35

ℹ️ 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 packages/maker-core/src/agents/claude-code/index.ts
Signed-off-by: nothingyuancando <1579035512@qq.com>
Comment thread packages/maker-core/src/agents/claude-code/index.ts Outdated
Signed-off-by: nothingyuancando <1579035512@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-discussion 等待维护者讨论(review-pr) touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants