Skip to content

fix: 隔离草稿 Harness 额度并在 Host 重连后刷新 - #653

Merged
BytePioneer-AI merged 3 commits into
mainfrom
fix/draft-harness-quota-isolation
Oct 30, 2026
Merged

BytePioneer-AI merged 3 commits into
mainfrom
fix/draft-harness-quota-isolation

Conversation

@BytePioneer-AI

Copy link
Copy Markdown
Owner

Summary

  • 新 Thread 草稿按当前 Host 和所选 Harness 查询额度:Codex 保留官方账号查询,外部 Harness 使用公共 inspectHarnessAccount,不引入 Harness 白名单或专有协议。
  • 切换 Harness 时清空旧用量/额度,完成后重新查询;按 Host、客户端、Harness、请求代次及草稿生命周期拒绝迟到响应。查询失败、不支持或没有百分比额度时隐藏控件。
  • 修复审查发现的同一 Host 重连问题:客户端替换后清空旧额度并补发查询,不依赖 subscribeThreadUsage,也不在连接未变时重复查询。
  • 同步 docs/product/usage-metering.md,增加切换、失败、迟到响应、跨 Host 与重连回归测试。

Related issues

无。包含原本的本地修改及审查后的重连修复,仅推送独立分支;未直接推送或合入主分支。

Test plan

本地 macOS,Playwright 隔离客户端;未连接真实 Harness 或真实账号服务,未启动 Codex Desktop 做实机验证。

通过:

  • npm run typecheck
  • npm run build:renderer
  • npx prettier --check docs/product/usage-metering.md packages/renderer-extension/src/renderer-binding-probe.ts tests/e2e/renderer-codex-account-isolation.spec.ts
  • npx eslint packages/renderer-extension/src/renderer-binding-probe.ts tests/e2e/renderer-codex-account-isolation.spec.ts
  • git diff --check
  • npm 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 个测试全部通过。
  • 在独立 worktree 的原始 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 实机检查。

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T16:22:44.456722Z af77997 PR opened
🔒 Security Review ✅ Completed 2026-10-29T16:23:31.560907Z af77997 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5160ad4 and af77997.

Files selected for processing: 3
  • docs/product/usage-metering.md
  • packages/renderer-extension/src/renderer-binding-probe.ts
  • tests/e2e/renderer-codex-account-isolation.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details
Context from checks skipped due to timeout: 4
  • GitHub Check: Check macos-14
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check windows-latest
Additional context used
Code guidelines: 1
AGENTS.md — auto-discovered
Path-based instructions: 1
Source excerpt: `codexhost` runs external Agent Harnesses as independent Threads inside Codex Desktop, preserving the official shell and native Codex path.

CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/product/usage-metering.md
  • tests/e2e/renderer-codex-account-isolation.spec.ts
  • packages/renderer-extension/src/renderer-binding-probe.ts
Learnings: 1
Common learnings
Learnt from: CR
Repo: BytePioneer-AI/codex-host

Timestamp: 2026-10-29T16:22:17.198Z
Learning: Applicability reference:
AGENTS.md: # Repository Guidelines
## Repository Skills
| Task | Skill |
| --- | --- |
| Reviewing a PR or local diff for correctness and boundaries | [codexhost-code-review](.agents/skills/codexhost-code-review/SKILL.md) |

Source excerpt:
# codexhost 代码审查

## 阻断项

4. **文档与实现一致**:改动核心逻辑或契约时,对应 `docs/` 功能文档、`docs/index.md` 链接已同步;没有把变更报告当功能文档写。
Learnt from: CR
Repo: BytePioneer-AI/codex-host

Timestamp: 2026-10-29T16:22:17.198Z
Learning: Applicability reference:
AGENTS.md: # Repository Guidelines
## Repository Skills
| Task | Skill |
| --- | --- |
| Reviewing a PR or local diff for correctness and boundaries | [codexhost-code-review](.agents/skills/codexhost-code-review/SKILL.md) |

Source excerpt:
# codexhost 代码审查

## 人工检查

- **生命周期与并发**:异步初始化、回调、子进程、会话、CDP 连接的发布前竞态、await 期间取消、重复输入、过期结果、重连与恢复、完整清理。
Additional comments: 1
docs/product/usage-metering.md: 1

80-81: LGTM!

📝 Summary

Summary by CodeRabbit

  • 新功能
    • 新建 Thread 草稿时,可查看 Codex 及支持额度查询的外部 Harness 的账户额度。
    • 切换 Harness 或 Host 后会重新查询额度,并确保显示的额度与当前选择对应。
  • 问题修复
    • 查询失败、额度不可用或切换账户时,不再显示旧额度;过期的查询结果也不会覆盖当前信息。
    • 不支持额度查询或未提供百分比额度时,额度控件会隐藏。
    • 外部 Harness 额度查询失败后,重新聚焦窗口时可重试。

新 Thread 草稿现在按当前 Agent 查询账号额度。Agent、Host 或客户端状态变化时,系统会清除旧额度或重新查询。Host 级缓存支持显式刷新,并避免旧请求覆盖新缓存。

Changes: 草稿额度查询与隔离

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: Pending latest changes

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: 校验请求并应用有效结果
Loading

Possibly related issues

Merge Risk: Minimal · up to 748d9

Draft quotas refresh by Host and Harness; no concrete merge-blocking issue was identified.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed 标题“fix: 隔离草稿 Harness 额度并在 Host 重连后刷新”概括了主要变更:新 Thread 草稿按所选 Harness 隔离额度查询,并在同一 Host 重连后刷新额度。变更集中的 renderer-binding-probe.ts、usage-metering.md 和 E2E 测试均与此相符。标题未涵盖切换 Harness 清空额度等细节,但这属于可接受的范围。
Description check Passed 描述列出了按 Host 和 Harness 查询额度、切换时清空旧数据、同一 Host 重连后刷新、文档同步及新增回归测试,与变更集一致。描述还包含测试计划与基线对照,内容具体。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@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: 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".

Comment on lines +1236 to +1238
const result = await client.inspectHarnessAccount({
harnessId: harnessIdSchema.parse(agent),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@BytePioneer-AI
BytePioneer-AI force-pushed the fix/draft-harness-quota-isolation branch from 748d96b to 7504b21 Compare October 30, 2026 15:51
@BytePioneer-AI
BytePioneer-AI merged commit 8154105 into main Oct 30, 2026
3 of 4 checks passed
@BytePioneer-AI

BytePioneer-AI commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner Author

@BytePioneer-AI 感谢贡献,已合并。

深审(含 Codex 机器人的 P1)后,在本分支上追加了修复,并 rebase 到最新 main(7504b21):

  • Renderer 仅在响应通过校验后才记录客户端,查询中去重,失败后可通过 focus 重试。
  • Host 的显式刷新会跳过缓存和失效前的在途查询,旧响应不会覆盖新缓存;普通查询仍合并。
  • e2e 接入真实缓存,覆盖重连、Pi→Grok→Pi、迟到响应与跨 Host 隔离,并同步文档。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant