Skip to content

fix(openai): retain cache-write usage telemetry - #666

Merged
zzwong merged 5 commits into
mainfrom
fix/openai-cache-write-telemetry-621
Oct 11, 2026
Merged

zzwong merged 5 commits into
mainfrom
fix/openai-cache-write-telemetry-621

Conversation

@zzwong

@zzwong zzwong commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Refs #621.

Retain the Responses API's usage.input_tokens_details.cache_write_tokens in the existing nullable CacheCreate usage field. Omitted/null counts remain unavailable; an explicit zero remains a reported zero.

  • Preserve OpenAI's inclusive input total and independently reported cache reads.
  • Add nine raw/nullable telemetry cases and six malformed-type/overflow cases.
  • Keep raw negative and overlapping counts unchanged. They are telemetry, not validated billable usage.
  • Verify the bundled OpenAI context-banded estimator remains unavailable and Anthropic's separate cache buckets retain their existing behavior.

The field and inclusive input semantics are documented in OpenAI's prompt-caching guide.

Remaining cost work

This is a telemetry-only slice of #621. It adds no new estimator activation and does not complete OpenAI or Codex cost estimation.

Complete request histories are still needed across validation and transport retries. Context bands and observed service tiers must be selected per request before aggregation; the catalog currently has no numeric context boundary. Ordinary OpenAI input must exclude both cache reads and cache writes before applying rates. Missing, inconsistent, or otherwise incomplete billing evidence must leave future estimates unavailable.

No lifecycle, durable-schema, catalog, pricing-formula, or Codex changes are included.

Focused local validation

The exact proposed source passed bounded offline checks with keyring_nopassage and an isolated cold build cache:

  • Parser/characterization normal: 5 top-level tests, 28 passing test/subtest results.
  • Selected direct-API regression normal: 16 top-level tests, 52 passing test/subtest results.
  • Existing pricing package: 24 passing test/subtest results.
  • The same selected direct-API scope with -race: 16 top-level tests, 52 passing test/subtest results, no race diagnostics.

All nine telemetry cases, six malformed/overflow cases, three bundled-price guards, and the Anthropic bucket regression were observed. No selected tests failed or skipped. Formatting and patch-application checks passed; source stayed unchanged throughout execution.

Full adapter-package tests, repository-wide tests, lint, standalone build, live-provider calls, and a baseline-red execution were not run locally. These focused results do not establish merge readiness.

Source scope

Based on 999e59ddfc74a67ffeef3c4b4a78a8528365afe6. The exact tested Git tree is 1701116532002ffa0c8e3ab1653728d9bf1f15b0; only internal/llmadapters/api.go and internal/llmadapters/api_test.go differ. This remains a draft, and #621 remains open.

Preserve nullable cache-write counts from Responses API usage and characterize raw telemetry without enabling new cost estimates.

Refs #621.

@monit-reviewer monit-reviewer 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.

Automated PR Review

Reviewed commit: 29edd5c6877b
Profile: open-cli-collective-review - Posting as: monit-reviewer

Summary

Reviewer Findings
go:implementation-tests 0

Reviewer Coverage

Complete coverage details are retained in the local coverage.json artifact.

  • go:implementation-tests — complete (broad); scope: 2 files; examples: internal/llmadapters/api.go, internal/llmadapters/api_test.go; body-inspected: 2 files; examples: internal/llmadapters/api.go, internal/llmadapters/api_test.go; skipped: none; context (not coverage): 1 file; examples: internal/pricing/pricing.go; constraints: Static review only; tests were inspected but not executed.

0 PR discussion threads considered. 0 summarized; 0 resolved.


Completed in 27s | $0.03 | openai-codex/gpt-6.1-sol | cr 0.10.328
Field Value
Model openai-codex/gpt-6.1-sol
Reviewers go:implementation-tests
Engine pi_rpc · openai-codex/gpt-6.1-sol
Reviewed by cr · monit-reviewer
Duration 27s wall · 17s compute
Cost $0.03
Tokens 10.2k in / 268 out

Per-workstream usage

  • orchestrator-selection — openai-codex/gpt-6.1-sol
    • In: 5.6k
    • Out: 121
    • Cache read: 0
    • Cache create: 0
    • Cost: $0.01
    • Duration: 3s
  • go:implementation-tests — openai-codex/gpt-6.1-sol
    • In: 977
    • Out: 100
    • Cache read: 19.6k
    • Cache create: 0
    • Cost: $0.00
    • Duration: 10s
  • orchestrator-rollup — openai-codex/gpt-6.1-sol
    • In: 3.6k
    • Out: 47
    • Cache read: 0
    • Cache create: 0
    • Cost: $0.01
    • Duration: 2s

@monit-reviewer monit-reviewer 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.

Automated PR Review

Reviewed commit: 884955e14282
Profile: open-cli-collective-review - Posting as: monit-reviewer

Summary

Reviewer Findings
go:implementation-tests 0

Reviewer Coverage

Complete coverage details are retained in the local coverage.json artifact.

  • go:implementation-tests — complete (constrained); scope: 2 files; examples: internal/llmadapters/api.go, internal/llmadapters/api_test.go; body-inspected: 2 files; examples: internal/llmadapters/api.go, internal/llmadapters/api_test.go; skipped: none; context (not coverage): 2 files; examples: docs/development.md, internal/pricing/pricing.go; constraints: Static inspection only; tests and build commands were not executed.

0 PR discussion threads considered. 0 summarized; 0 resolved.


Completed in 25s | $0.01 | openai-codex/gpt-6.1-sol | cr 0.10.328
Field Value
Model openai-codex/gpt-6.1-sol
Reviewers go:implementation-tests
Engine pi_rpc · openai-codex/gpt-6.1-sol
Reviewed by cr · monit-reviewer
Duration 25s wall · 14s compute
Cost $0.01
Tokens 4.6k in / 130 out

Per-workstream usage

  • go:implementation-tests — openai-codex/gpt-6.1-sol
    • In: 992
    • Out: 80
    • Cache read: 22.9k
    • Cache create: 0
    • Cost: $0.01
    • Duration: 11s
  • orchestrator-rollup — openai-codex/gpt-6.1-sol
    • In: 3.6k
    • Out: 50
    • Cache read: 0
    • Cache create: 0
    • Cost: $0.01
    • Duration: 3s

@zzwong
zzwong marked this pull request as ready for review October 11, 2026 02:19
@zzwong
zzwong merged commit 9c63b3e into main Oct 11, 2026
12 checks passed
@zzwong
zzwong deleted the fix/openai-cache-write-telemetry-621 branch October 11, 2026 02:23
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