Skip to content

feat(observer): add cache-aware token accounting - #3781

Merged
djm204 merged 9 commits into
mainfrom
feat/cache-aware-token-accounting-3727
Jul 26, 2026
Merged

feat(observer): add cache-aware token accounting#3781
djm204 merged 9 commits into
mainfrom
feat/cache-aware-token-accounting-3727

Conversation

@djm204

@djm204 djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • add cache-read and cache-creation token fields across shared provider usage, observer counters, span metadata, and orchestrator aggregation
  • translate real Anthropic and OpenAI SDK cache usage without estimating unsupported fields
  • price cache tiers with prompt-rate fallback, export a cache-hit ratio helper, and document the accounting model
  • preserve safe-integer validation and atomic overflow rejection across counters and aggregators

Test plan

  • npm --workspace @franken/orchestrator test -- tests/unit/providers/anthropic-api-adapter.test.ts tests/unit/providers/openai-api-adapter.test.ts tests/unit/providers/token-aggregator.test.ts tests/unit/adapters/observer-adapter.test.ts tests/unit/skills/cli-skill-executor.test.ts test/adapters/cli-observer-bridge.test.ts
  • npm --workspace @franken/observer test -- src/cost/TokenCounter.test.ts src/cost/CostCalculator.test.ts src/core/SpanLifecycle.test.ts
  • npm --workspace @franken/types test -- tests/provider.test.ts
  • npx turbo run typecheck --filter=@franken/types --filter=@franken/observer --filter=@franken/orchestrator
  • npx turbo run lint --filter=@franken/types --filter=@franken/observer --filter=@franken/orchestrator
  • npx turbo run build --filter=@franken/types --filter=@franken/observer --filter=@franken/orchestrator

Closes #3727

@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 7e1366961a

ℹ️ 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 thread packages/franken-observer/src/cost/CostCalculator.ts
Comment thread packages/franken-observer/src/cost/TokenCounter.ts
@djm204
djm204 force-pushed the feat/cache-aware-token-accounting-3727 branch from 7e13669 to 3b6ba7b Compare July 25, 2026 16:19
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@djm204
djm204 force-pushed the feat/cache-aware-token-accounting-3727 branch from 3b6ba7b to 06acd2b Compare July 25, 2026 16:27
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 06acd2bc72

ℹ️ 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 thread packages/franken-observer/src/cost/defaultPricing.ts
Comment thread packages/franken-orchestrator/src/providers/openai-api-adapter.ts
Comment thread packages/franken-observer/src/cost/TokenCounter.ts
Comment thread packages/franken-observer/src/core/SpanLifecycle.ts
@djm204
djm204 force-pushed the feat/cache-aware-token-accounting-3727 branch from 06acd2b to ddae0ec Compare July 25, 2026 16:42
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: ddae0ec49f

ℹ️ 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 thread packages/franken-observer/src/cost/TokenCounter.ts
Comment thread packages/franken-observer/src/cost/TokenCounter.ts
Comment thread packages/franken-observer/src/cost/CostCalculator.ts
Comment thread packages/franken-observer/src/cost/defaultPricing.ts
@djm204
djm204 force-pushed the feat/cache-aware-token-accounting-3727 branch from ddae0ec to 6d51ad8 Compare July 25, 2026 17:03
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 6d51ad8f8b

ℹ️ 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 thread packages/franken-orchestrator/src/providers/token-aggregator.ts Outdated
Comment thread packages/franken-observer/src/cost/TokenCounter.ts
Comment thread packages/franken-mcp-suite/src/shared/sqlite-store.ts
Comment thread packages/franken-mcp-suite/src/shared/tool-registry.ts
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 26e4634bce

ℹ️ 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 thread packages/franken-orchestrator/src/skills/cli-skill-executor.ts
Comment thread packages/franken-observer/src/adapters/prometheus/PrometheusAdapter.ts Outdated
Comment thread packages/franken-mcp-suite/src/adapters/observer-adapter.ts
Comment thread packages/franken-observer/src/cost/ModelAttribution.ts
Comment thread packages/franken-observer/src/cost/TokenCounter.ts
Comment thread packages/franken-observer/README.md Outdated
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 69539be5c1

ℹ️ 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 thread packages/franken-orchestrator/src/adapters/cli-observer-bridge.ts
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: c95814fbac

ℹ️ 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 thread packages/franken-orchestrator/src/adapters/observer-adapter.ts
Comment thread packages/franken-mcp-suite/src/adapters/governor-adapter.ts
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 4488a4f128

ℹ️ 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".

@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 01ac5549ba

ℹ️ 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 thread packages/franken-mcp-suite/src/shared/tool-registry.ts Outdated
Comment thread packages/franken-orchestrator/src/adapters/observer-adapter.ts
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: 0314063e10

ℹ️ 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 thread packages/franken-mcp-suite/src/shared/tool-registry.ts Outdated
Comment thread packages/franken-types/src/provider.ts
@djm204

djm204 commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: bbabdc329e

ℹ️ 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 thread packages/franken-orchestrator/src/network/chat-attach.ts Outdated
Comment thread packages/franken-mcp-suite/src/adapters/observer-adapter.ts
@djm204
djm204 merged commit 3d526f5 into main Jul 26, 2026
4 checks passed
@djm204
djm204 deleted the feat/cache-aware-token-accounting-3727 branch July 26, 2026 03:35
@github-actions github-actions Bot mentioned this pull request Jul 26, 2026
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.

Brain Vitals 1/8: Cache-aware token accounting (cache-hit/cache-creation tracking + pricing)

1 participant