Skip to content

Add reconciled token usage bridge - #1688

Open
QingJunXue wants to merge 1 commit into
BigPizzaV3:mainfrom
QingJunXue:feature/reconciled-token-usage
Open

Add reconciled token usage bridge#1688
QingJunXue wants to merge 1 commit into
BigPizzaV3:mainfrom
QingJunXue:feature/reconciled-token-usage

Conversation

@QingJunXue

Copy link
Copy Markdown

Summary

  • add a single local /token-usage/events bridge without a price endpoint or billing-provider dependency
  • reconcile MessagePort, rollout JSONL, subagent rollout files, and protocol-proxy Usage events
  • capture Input, Cached Input, Cache Write, Output, Reasoning, request status, retries, and Usage-missing responses
  • follow the dynamically selected Helper port and prevent local proxy URLs from becoming upstream URLs
  • add bounded stream lifetimes, downstream-disconnect resilience, ledger rotation, and diagnostic-log rotation

Disk and privacy behavior

  • rollout files are read fully once, then tailed incrementally
  • proxy ledger rotates at 20 MB and retains three archives
  • diagnostic logs rotate at 20 MB and retain three archives
  • high-frequency successful bridge events are not persisted
  • the Usage ledger stores no prompts, response text, API keys, or upstream URLs

Verification

  • cargo fmt --all -- --check
  • Token Usage tests: 13/13
  • Bridge route tests: 27/27
  • Protocol proxy tests: 48/48
  • Relay configuration tests: 103/103
  • Launcher tests: 74/74, with one unrelated Windows symlink-privilege test skipped
  • Diagnostic log tests: 3/3
  • scoped Clippy: 0 warnings in the new Token Usage implementation
  • cargo build --release -p codex-plus-launcher

The skipped launcher test requires Windows symbolic-link privilege and fails with OS error 1314 independently of this change.

Capture terminal Responses usage and retry attempts in a bounded local ledger, reconcile it with rollout tails through a single bridge route, follow the selected helper port, and rotate high-volume diagnostics. Includes privacy-focused documentation and regression coverage.
@BigPizzaV3

Copy link
Copy Markdown
Owner

维护者审查:token usage 对账方向有价值,但当前 PR 不能直接合并。分支与最新 main 冲突,且一次改动同时接入 MessagePort、主/子 agent rollout、协议代理 usage、持久化 ledger 与日志轮转,重复事件的幂等边界是核心风险。请先 rebase 最新 main,补充同一请求同时出现在 rollout 与 proxy/MessagePort 时只计一次、进程重启后不重复计数、截断/损坏 JSONL 与并发写入的回归测试,并明确 ledger 的默认启用、保留期限和脱敏策略。更新后再复审。

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.

2 participants