Repository navigation
fix: 隔离草稿 Harness 额度并在 Host 重连后刷新 - #653
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
通用草稿额度查询 packages/renderer-extension/src/renderer-binding-probe.ts, docs/product/usage-metering.md |
Codex 草稿查询当前账号用量;外部 Harness 草稿查询账号积分。系统校验 Host、客户端、Agent、草稿状态和请求代次,并在查询失败或结果不匹配时不应用旧额度。 |
Agent 与 Host 变化时刷新 packages/renderer-extension/src/renderer-binding-probe.ts |
Agent 切换前清除相关 Composer 的额度并递增请求代次,切换后重新查询。Host 重绑定、窗口聚焦和 Adapter 设置等路径也会触发或协调查询。 |
Harness 检查缓存与端到端验证 packages/host-runtime/src/harness-accounts.ts, packages/host-runtime/test/harness-accounts.test.ts, docs/architecture/harness-plugin-runtime.md, tests/e2e/renderer-codex-account-isolation.spec.ts |
显式刷新会启动独立的 Harness 检查;只有当前检查可更新缓存。测试覆盖不同完成顺序,以及草稿重连、Harness 切换、过期响应和 Host 隔离。 |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant Composer
participant refreshDraftUsage
participant CodexAccount as Codex账号用量查询
participant HarnessAccount as Harness账号额度查询
Composer->>refreshDraftUsage: 请求草稿额度
alt 当前 Agent 是 Codex
refreshDraftUsage->>CodexAccount: 查询就绪账户用量
CodexAccount-->>refreshDraftUsage: 返回账号用量
else 当前 Agent 是外部 Harness
refreshDraftUsage->>HarnessAccount: 查询账号积分
HarnessAccount-->>refreshDraftUsage: 返回账号额度
end
refreshDraftUsage-->>Composer: 校验请求并应用有效结果
Possibly related issues
- [Bug] Claude Code:重启后旧聊天剩余额度消失,发送新消息才恢复 #600:该 Issue 涉及 Host 重启后旧聊天的额度入口消失。本次变更覆盖新草稿和重连查询,但未覆盖打开已有聊天的完整路径。
Merge Risk: 
Minimal · up to 748d9
-
Draft quotas refresh by Host and Harness; no concrete merge-blocking issue was identified.
Pre-merge checks: 
4
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af779975cb
ℹ️ 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".
| const result = await client.inspectHarnessAccount({ | ||
| harnessId: harnessIdSchema.parse(agent), | ||
| }); |
There was a problem hiding this comment.
Force a fresh quota read after reconnect
When a Renderer client reconnects while the same Host runtime remains alive, this request omits refresh: true, so HarnessAccountInspectionCache.inspect() can return its pre-reconnect value for up to 15 seconds (packages/host-runtime/src/harness-accounts.ts:109-135) instead of querying the Adapter. The accepted result then records the replacement client in draftUsageClient, and subsequent focus reconciliation does not retry, allowing the stale quota to remain indefinitely. The in-flight reconnect case is also not faithfully covered by the fixture because the real cache coalesces concurrent inspections, whereas the test creates independent reads.
Useful? React with 👍 / 👎.
748d96b to
7504b21
Compare
|
@BytePioneer-AI 感谢贡献,已合并。 深审(含 Codex 机器人的 P1)后,在本分支上追加了修复,并 rebase 到最新 main(
|
Summary
inspectHarnessAccount,不引入 Harness 白名单或专有协议。subscribeThreadUsage,也不在连接未变时重复查询。docs/product/usage-metering.md,增加切换、失败、迟到响应、跨 Host 与重连回归测试。Related issues
无。包含原本的本地修改及审查后的重连修复,仅推送独立分支;未直接推送或合入主分支。
Test plan
本地 macOS,Playwright 隔离客户端;未连接真实 Harness 或真实账号服务,未启动 Codex Desktop 做实机验证。
通过:
npm run typechecknpm run build:renderernpx prettier --check docs/product/usage-metering.md packages/renderer-extension/src/renderer-binding-probe.ts tests/e2e/renderer-codex-account-isolation.spec.tsnpx eslint packages/renderer-extension/src/renderer-binding-probe.ts tests/e2e/renderer-codex-account-isolation.spec.tsgit diff --checknpm run test:e2e -- renderer-codex-account-isolation.spec.ts --grep 'same-Host reconnect':4/4 通过;修复前相同 4 个测试全部失败。覆盖已有额度、在途额度,以及有/无通知通道。未全绿的检查及基线对照:
npm run test:e2e -- renderer-codex-account-isolation.spec.ts:24 通过、5 失败,新增的 11 个测试全部通过。origin/main(5160ad4ae4f1d57143fe8257f219aabf96e93d68)运行同一测试文件:13 通过、相同 5 个失败。失败项为本地/远程 adapter-status 就绪(2 项)、冷启动远端不支持账号 API、跨 Host 迟到账号/额度,以及不支持的远端 Harness 探测。本 PR 未修改这些既有失败的断言,也未将它们标为跳过。renderer-usage-notification.spec.ts和renderer-chat-composer-isolation.spec.ts,测试收集被codexhost-app-icon.svg缺少 esbuild loader 阻塞;原始基线上相同命令亦复现。未扩展本 PR 范围去修复无关测试配置。未运行全量测试或 Windows/Linux 实机检查。