Skip to content

fix(opencode): preserve NanoGPT cache writes and billed cost - #48477

Open
huggix wants to merge 1 commit into
anomalyco:devfrom
huggix:nanogpt-accounting
Open

fix(opencode): preserve NanoGPT cache writes and billed cost#48477
huggix wants to merge 1 commit into
anomalyco:devfrom
huggix:nanogpt-accounting

Conversation

@huggix

@huggix huggix commented Sep 11, 2026

Copy link
Copy Markdown

fix(opencode): preserve NanoGPT cache writes and billed cost

Issue for this PR

Closes #48478

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

NanoGPT reports cache writes in usage.cache_creation_input_tokens and the settled charge in x_nanogpt_pricing. The OpenAI-compatible adapter drops these fields, so OpenCode can show zero cache writes and a cost estimate that misses long-context rates or discounts.

Register a NanoGPT metadata extractor for streaming and non-streaming responses. Session accounting uses its cache-write count and valid USD charge, including an explicit zero. When pricing is absent or invalid, the existing estimate still applies. Other providers are unchanged.

How did you verify your code works?

From packages/opencode:

  • New SDK/parser/accounting and loader tests: 6 passed.
  • Existing usage, metadata, and billed-cost regression tests: 18 passed.
  • bun --bun run typecheck: passed.
  • git diff --check: passed.

The regression exercises actual SDK SSE parsing through OpenCode's LLM adapter into session accounting, plus non-streaming responses, separate usage/pricing frames, explicit zero, invalid values, non-USD fallback, excessive cache counts, and provider/stream isolation.

Screenshots / recordings

Not applicable: token/cost accounting only.

Checklist

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

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

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

Copy link
Copy Markdown
Contributor

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

The searches show that PR #48477 is the current PR. The related results mention cache pricing and cost-related fixes, but none appear to be duplicates of the current PR addressing the specific NanoGPT cache writes and billed cost issue.

No duplicate PRs found

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

NanoGPT cache-write usage and billed cost are lost in session accounting

1 participant