Skip to content

fix(desktop): hide custom provider SDK costs by default - #2878

Open
A1aZ wants to merge 63 commits into
makecindy:mainfrom
A1aZ:fix/issue-2855-custom-provider-billing
Open

fix(desktop): hide custom provider SDK costs by default#2878
A1aZ wants to merge 63 commits into
makecindy:mainfrom
A1aZ:fix/issue-2855-custom-provider-billing

Conversation

@A1aZ

@A1aZ A1aZ commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

这次改了什么

摘要

自定义 Provider 的 SDK costUSD 来源与计价口径无法由 Cindy 验证,不能默认当作可对账的真实支出。本 PR 将它改为:

  • 默认不展示 SDK 金额,仅展示输入、输出及总 Token;
  • 用户主动开启「显示 SDK 估算」后,SDK 金额只按 value-estimate 展示,仍不进入消息 / 会话 / 今日支出的 actual-cost 账本;
  • 用户自定义价格和 Provider 参考价继续作为独立估算保留,不会被该开关一并清空;
  • Cindy AI Gateway 等已有可信结算路径继续按真实费用处理。

「设置 → Providers」中的开关默认关闭,并明确提示该数字不是供应商账单、可能与最终扣费不一致。设置采用默认值 + override;用户修改后可看到「已自定义」并恢复默认,恢复时删除 override。

变更类型

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

范围

  • 关联 Issue / 需求:Closes 自定义模型服务的费用估算与实际计费不一致,建议仅统计 Token #2855;产品确认讨论 维护者确认:自定义 Provider SDK 费用默认隐藏(PR #2878) #2884
  • 本 PR 包含:Desktop 设置 store、受信任 IPC、preload、renderer hook/UI;Claude / Codex / Pi 路由;消息、会话、今日支出、Scheduler 的估值投影。历史数据只做展示投影,不改写账本。Device link / Mobile 读取被控 Desktop 的只读偏好并使用同一投影。Scheduler 对升级前缺少逐轮归属的记录,使用持久化 Provider 与版本化 bundled Gateway 模型证据重建 actual / independent estimate / SDK 子账本,歧义项 fail closed。侧栏费用改为 main 侧批量投影,避免逐会话全历史扫描。新增 append-only、幂等守卫的 0095_ancient_gorilla_man migration;0093 / 0094 历史 snapshot 保持不变。Desktop 和 Mobile 的英文、简中、繁中、日文、韩文。
  • 明确不包含:替供应商维护真实账单规则、承诺 SDK 估值可对账、修改供应商最终扣费。
  • 用户可见变化:默认关闭时,消息、侧栏、状态栏、Mobile 与 Scheduler 均优先展示 Token 或保留的其他可信 / 独立估价;开启后 SDK 金额按估算展示。
  • 是否存在 breaking change:无。变化只在默认展示与费用分类;用户仍可显式查看 SDK 估算。

UI 变化

  • 「设置 → Providers」新增「显示 SDK 估算」开关、风险说明、「已自定义」状态和「恢复默认」入口。

  • 默认关闭时,消息、侧栏、状态栏、Mobile 与 Scheduler 均优先展示 Token 或保留的其他可信 / 独立估价。

  • 已完成 Light / Dark × 默认关闭 / 手动开启四种脱敏运行时截图并做视觉复核
    Light · 默认关闭 provider-billing-light-default
    Dark · 默认关闭 provider-billing-dark-default
    Light · 手动开启 provider-billing-light-enabled
    Dark · 手动开启 provider-billing-dark-enabled

  • 引用的设计规范:docs/design-rules/DESIGN.md §2 Layer System、§3 Typography、§4 Cards & Forms、§10 Light/Dark dual-mode and theme tokens、§11 Voice & Content。控件复用现有设置卡片、Switch 和语义化主题 token;提示文案直接说明来源、不可控性和开启后果。

怎么验证的

自动验证

vitest run
  src/shared/__tests__/customProviderBilling.test.ts
  src/main/__tests__/patchMessageAgentMeta.test.ts
  src/renderer/__tests__/makerTransportRouting.test.ts
  src/renderer/features/cc-agent/sidebar/__tests__/sidebarSessionUsageStore.test.tsx
  src/main/right-sidebar-window/__tests__/preload-contract.test.ts
  src/renderer/lib/__tests__/customProviderCostPresentation.test.ts
结果:6 files / 57 tests passed

vitest run packages/device-link/src/__tests__/allowlist.test.ts
结果:1 file / 42 tests passed

git diff --check
结果:通过

最终提交已重新通过根目录 pnpm test:unit:related、Desktop / Mobile typecheck、git diff --check 与 DCO;此前 migration validate 与 i18n 对齐检查也已通过。定向覆盖包括:旧 Host 逐轮兼容投影 3 文件 / 34 项、Desktop partial-page mixed cumulative 8/8、无版本 projection 权威性 7/7,以及 Mobile 同口径累计费用 12/12。

手工验证

  • Desktop 设置页完成 Light / Dark、默认关闭 / 手动开启四态验证;开关状态、风险文案、「已自定义」和恢复默认均符合预期。
  • 账本语义通过注入 SDK 估值、Token、用户价格、Provider 参考价与混合历史费用的自动化场景验证;未使用或提交任何供应商凭证。
  • 不把供应商后台金额对比列为 Cindy 可保证的验证项:本修复的目标正是将不可验证的 SDK 数字与真实支出账本隔离。

未执行的验证

  • 未对照供应商后台账单核验 SDK 数字;该数字本身不可由 Cindy 对账。

风险

风险分类

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

影响与回滚

  • 影响范围:SQLite 只追加 schedule_runs.sdk_estimated_value_amount,migration 带列存在性守卫,不修改历史 migration。本地 GET / SET / RESET 继续先校验 trusted app renderer。Device link 仅提供门禁后的只读 GET 投影,以及只读 estimatedSessionValueBatch;不能远程修改偏好。SSH / remote workspace 不读取或修改远端 workdir 文件;费用偏好仍属于被控 Desktop 本地。Mobile / device-link 新增字段与读取路径均为可选 / 向后兼容;旧端费用汇总继续使用非权威 token-only 或逐会话查询,新版控制端会对旧 Host 返回的原始消息做只读逐轮兼容投影。原生层 / fingerprint / OTA 无改动。存量插件影响:无。
  • 回滚 / 降级方式:回滚本 PR 即可;新增列可保留且不会影响旧代码,设置默认值为关闭。老被控端没有 batch channel 时,控制端回退到既有逐会话只读查询。

提交前检查

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

@A1aZ
A1aZ requested a review from a team as a code owner August 17, 2026 07:48
@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown

Greptile Summary

本 PR 默认隐藏自定义 Provider 无法核验的 SDK 费用,并将其与实际支出及独立估值分账。

  • 新增 Desktop 费用展示偏好、受信任 IPC、preload 接口和 Providers 设置界面
  • 统一消息、会话、今日支出、Scheduler 与 Mobile 的费用分类和只读展示投影
  • 新增 Scheduler SDK 估值字段迁移,并扩展 Device Link 的批量估值与兼容回退协议
  • 补充多语言资源及 Desktop、Mobile、Scheduler、IPC 和协议测试

Confidence Score: 5/5

当前没有发现仍需在合并前修复的阻塞性故障,PR 看起来可以安全合并。

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

Important Files Changed

Filename Overview
apps/desktop/src/shared/customProviderBilling.ts 定义可信实际费用、独立估值和自定义 Provider SDK 估值的共享分类规则。
apps/desktop/src/main/localDb/ipc/messages.ts 在主进程中投影消息与会话费用,并提供批量会话估值读取。
apps/desktop/src/main/scheduler-host/runCostLedger.ts 将 Scheduler 运行费用拆分为实际支出、完整估值和 SDK 估值子账本。
apps/desktop/src/renderer/lib/customProviderCostPresentation.ts 根据用户偏好对 Desktop 历史消息和轮次费用执行只读展示投影。
apps/mobile/src/session/sessionBillingProjection.ts 在 Mobile 端应用与 Desktop 一致的远程会话费用投影语义。
packages/device-link/src/allowlist.ts 将新增只读费用查询纳入 Device Link 的显式远程调用边界。
apps/desktop/drizzle/scripts/0096_scheduler_sdk_estimated_value.ts 通过幂等列存在性守卫为 Scheduler 运行记录追加 SDK 估值字段。

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Provider usage metadata] --> B[Desktop classification]
  B --> C[Actual cost ledger]
  B --> D[Independent estimate]
  B --> E[SDK estimate sub-ledger]
  C --> F[Desktop and Scheduler projection]
  D --> F
  E --> G{Show SDK estimates?}
  G -- No --> H[Token or trusted value display]
  G -- Yes --> F
  F --> I[Device Link read-only projection]
  I --> J[Mobile display]
Loading

Reviews (31): Last reviewed commit: "fix(desktop): fail closed session billin..." | Re-trigger Greptile

@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: f4470f0ca1

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/main/maker-ipc/register.ts Outdated
Comment thread apps/desktop/src/renderer/components/settings/CustomProviderBillingSection.tsx Outdated
@MagicLizi

Copy link
Copy Markdown
Contributor

这个 PR 触及产品默认行为变化(自定义 Provider 的 SDK 费用由默认展示改为默认隐藏,并新增设置开关),自动流程已暂停合并,需要维护者确认。

维护者确认方式:直接在 PR 上 Approve;需要修改就 Request Changes,作者改完后再 Approve 即放行。在维护者确认前,这个 PR 会保持在待确认队列中,不会自动合并。

讨论 issue:#2884

@MagicLizi MagicLizi added awaiting-discussion 等待维护者讨论(review-pr) touches:core 改动碰到架构核心路径(review-pr 自动维护,仅展示) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示) labels Aug 17, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

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

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

@MagicLizi

Copy link
Copy Markdown
Contributor

命中 UI 路径(apps/desktop/src/renderer/components/settings/CustomProviderBillingSection.tsx / apps/desktop/src/renderer/components/settings/ProvidersSection.tsx / apps/desktop/src/renderer/hooks/useCustomProviderBillingSettings.ts 等)但 description 未附界面效果证据——建议补充改动后效果:截图/录屏,或改动后界面的 HTML 页面(```html 代码块、.html 附件或在线预览链接),便于确认界面符合 DESIGN.md 设计规范

@A1aZ
A1aZ force-pushed the fix/issue-2855-custom-provider-billing branch from f4470f0 to cb1c617 Compare August 18, 2026 13:06

@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: cb1c6176b6

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/device-link/src/allowlist.ts

@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: a7d280209f

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/mobile/src/session/sessionBillingProjection.ts
Comment thread apps/desktop/src/renderer/components/status/TodaySpendChip.tsx
@A1aZ
A1aZ force-pushed the fix/issue-2855-custom-provider-billing branch from a7d2802 to 7af9436 Compare August 18, 2026 14:05

@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: 7af9436d96

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/main/scheduler-host/storage.ts Outdated
Comment thread apps/desktop/src/renderer/features/cc-agent/sidebar/SessionInfoMeta.tsx Outdated
@MagicLizi MagicLizi added touches:large-diff 改动量较大(review-pr 自动维护,仅展示) touches:redline 改动碰到红线路径(updater / DB schema 等,review-pr 自动维护,仅展示) labels Aug 18, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

@A1aZ 👋 这个 PR 还有 2 条 review conversation 没 resolve(apps/desktop/src/main/scheduler-host/storage.ts / apps/desktop/src/renderer/features/cc-agent/sidebar/SessionInfoMeta.tsx),auto-review 因此暂时跳过、没法继续审查 / 合并。

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

@MagicLizi

Copy link
Copy Markdown
Contributor

@A1aZ 👋 这个 PR 目前与 main 有合并冲突,auto-review 因此暂时跳过、没法继续审查 / 合并。

请在本地 merge 最新的 origin/main 解决冲突后推送;冲突解除后,下一轮 auto-review 会自动重新处理这个 PR。

A1aZ added 4 commits August 21, 2026 15:55
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
…ates

Use the session/schedule provider as a fail-closed fallback when older
custom-provider rows omit turnCostIsCustomProvider, so Scheduler run
history no longer treats those SDK amounts as actual spend. Sidebar cost
rows now share one main-process batch query and listener pair instead of
scanning every session independently.

Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
@A1aZ
A1aZ force-pushed the fix/issue-2855-custom-provider-billing branch from 7af9436 to b5676ee Compare August 21, 2026 07:56

@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: b5676ee2f8

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/main/localDb/ipc/messages.ts Outdated
Comment thread apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx Outdated
A1aZ added 2 commits August 21, 2026 16:23
Require a trusted renderer sender for estimated-session-value IPC while
keeping device-link on its existing async-context path. Desktop remote
sessions now read the controlled host billing preference, sidebar cost
refreshes that arrive mid-query are kept, and the Pi subscription source
contract matches the rebased hot path.

Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Attach Light/Dark default-off and opt-in screenshots so the PR body can
reference checked-in evidence without GitHub comment image upload.

Signed-off-by: Alan Z <3347202+A1aZ@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: f7900a46ff

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/main/localDb/ipc/messages.ts
Signed-off-by: Alan Z <3347202+A1aZ@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: 844d50f7b3

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/mobile/src/session/sessionBillingProjection.ts
@MagicLizi

Copy link
Copy Markdown
Contributor

@A1aZ 👋 这个 PR 目前与 main 有合并冲突,auto-review 因此暂时跳过、没法继续审查 / 合并。

请在本地 merge 最新的 origin/main 解决冲突后推送;冲突解除后,下一轮 auto-review 会自动重新处理这个 PR。

A1aZ added 10 commits August 31, 2026 10:40
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
…-provider-billing

Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
@A1aZ
A1aZ force-pushed the fix/issue-2855-custom-provider-billing branch from 186e349 to be2633f Compare August 31, 2026 09:20
@MagicLizi

Copy link
Copy Markdown
Contributor

@A1aZ 👋 这个 PR 目前与 main 有合并冲突,auto-review 因此暂时跳过、没法继续审查 / 合并。

请在本地 merge 最新的 origin/main 解决冲突后推送;冲突解除后,下一轮 auto-review 会自动重新处理这个 PR。

A1aZ added 3 commits September 2, 2026 15:52
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
Signed-off-by: Alan Z <3347202+A1aZ@users.noreply.github.com>
@MagicLizi

Copy link
Copy Markdown
Contributor

@A1aZ 👋 这个 PR 目前与 main 有合并冲突,auto-review 因此暂时跳过、没法继续审查 / 合并。

请在本地 merge 最新的 origin/main 解决冲突后推送;冲突解除后,下一轮 auto-review 会自动重新处理这个 PR。

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 自动维护,仅展示) touches:large-diff 改动量较大(review-pr 自动维护,仅展示) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示) touches:redline 改动碰到红线路径(updater / DB schema 等,review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

自定义模型服务的费用估算与实际计费不一致,建议仅统计 Token

2 participants