Skip to content

fix(console): openai usage normalization and tier threshold config - #47342

Merged
MrMushrooooom merged 2 commits into
anomalyco:devfrom
heimoshuiyu:pricing-tier-threshold
Sep 5, 2026
Merged

fix(console): openai usage normalization and tier threshold config#47342
MrMushrooooom merged 2 commits into
anomalyco:devfrom
heimoshuiyu:pricing-tier-threshold

Conversation

@heimoshuiyu

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #

Type of change

  • Bug fix

What does this PR do?

  • OpenAI's input_tokens already includes cached_tokens and cache_write_tokens; normalizeUsage now subtracts both (clamped at zero) so each category is priced once.
  • The cost200K tier threshold is now a per-model config field (default 200_000) instead of a hardcoded constant.

How did you verify your code works?

Updated/added tests for usage normalization and the threshold default; bun typecheck + bun test pass in packages/console/core and packages/console/app.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No issue referenced. Please add Closes #<number> linking to the relevant issue.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potentially related PR:

fix(zen): OpenAI cache-write tokens are part of input_tokens, not extra (#44229)
#44229

This PR appears to address the same underlying issue about OpenAI's cache-write tokens being included in input_tokens rather than counted separately. It may have context or implementation details relevant to the current PR's fix for usage normalization.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 4, 2026
@github-actions github-actions Bot closed this Sep 4, 2026
@MrMushrooooom MrMushrooooom reopened this Sep 5, 2026
@MrMushrooooom
MrMushrooooom enabled auto-merge (squash) September 5, 2026 03:23
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 5, 2026
@MrMushrooooom
MrMushrooooom merged commit e289456 into anomalyco:dev Sep 5, 2026
8 checks passed
1056674754 added a commit to 1056674754/opencode that referenced this pull request Sep 9, 2026
Upstream v1.18.29 (1674747, merged at 18a4845) -> v1.18.30 (3104c14),
28 commits / 105 files. Staged delta vs pre-merge fork HEAD is identical to
the upstream tag-to-tag diff (105 files, +1676/-403), confirming a clean
adoption.

Functional changes:
- feat(opencode): port Astra system prompt from v2 (anomalyco#48057) — new
  session/prompt/gpt-astra.txt wired through system.ts; fork's system
  transforms live in the openchamber plugin, no overlap.
- fix: preserve Bedrock DeepSeek model ids (anomalyco#34441) — provider.ts Bedrock
  loader passes arn: model ids through unmodified and tightens the
  cross-region prefix match from "deepseek" to "deepseek.r1"; inside the
  custom Azure/Bedrock loader region, disjoint from the fork snapshot
  architecture.
- fix(provider): preserve explicit OpenAI service tiers (anomalyco#47671).
- fix(opencode): add GitLab reasoning variants (anomalyco#47306) — transform.ts
  reasoningEffort now routes gitlab gpt-family to reasoningEffort and
  claude-family to adaptive thinking; disjoint from the fork GLM/ZhiPu
  normalization block, which remains intact (+77 fork-only lines).
- SDK bumps: @ai-sdk/openai 3.0.88, @ai-sdk/azure 3.0.93,
  gitlab-ai-provider 6.15.0 (8 packages installed via bun install).
- console: oauth client metadata document (anomalyco#47737), Chatwoot enterprise
  form (anomalyco#47488), openai usage normalization + tier threshold (anomalyco#47342),
  localized refund FAQs, zen model table updates (muse spark); go.mdx
  client session compatibility docs incl. zh translation.

Conflicts resolved: 29 package.json version bumps (rebranded 1.18.30-sscity
with a version-generic pattern after the v1.18.27 incident), bun.lock (took
upstream, rebranded workspace entries via bun install). Fork deltas
verified intact vs v1.18.30: ProviderSnapshot architecture (+492 in
provider.ts), deferred snapshot init, GLM normalization (+77 in
transform.ts), config getFresh/commitFresh (+14). Tests: provider,
transform, bedrock, config, v2, azure plugin, session retry/llm — 1058
pass / 0 fail across 15 files (22 new upstream tests included); typecheck
clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants