Skip to content

fix: correct Anthropic provider inputOther token counting#2

Closed
hobostay wants to merge 1 commit into
MoonshotAI:mainfrom
hobostay:fix/anthropic-token-counting
Closed

fix: correct Anthropic provider inputOther token counting#2
hobostay wants to merge 1 commit into
MoonshotAI:mainfrom
hobostay:fix/anthropic-token-counting

Conversation

@hobostay
Copy link
Copy Markdown

Summary

  • inputOther was set to raw input_tokens which already includes cache tokens, causing double-counting of non-cache input tokens
  • Subtract cache_read_input_tokens and cache_creation_input_tokens from the total, matching the OpenAI provider's calculation pattern (promptTokens - cached)

Root Cause

In packages/kosong/src/providers/anthropic.ts, _extractUsage assigned usage.input_tokens directly to inputOther. Per the Anthropic API, input_tokens is the total billed input tokens which already includes cache-read and cache-creation tokens. This inflated the reported non-cache input count.

Test plan

  • Verify existing Anthropic provider tests still pass
  • Confirm inputOther + inputCacheRead + inputCacheCreation now sums correctly to input_tokens

🤖 Generated with Claude Code

inputOther was set to raw input_tokens which already includes cache
tokens, causing double-counting. Subtract cache_read_input_tokens and
cache_creation_input_tokens to get the actual non-cache input count,
matching the OpenAI provider's calculation pattern.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@liruifengv
Copy link
Copy Markdown
Collaborator

Thank you for your interest in contributing to kimi-code.
However, we currently do not accept bulk AI-generated submissions that have not undergone thorough human review, so we will be closing these PR.

@liruifengv liruifengv closed this May 23, 2026
sailist added a commit that referenced this pull request Jun 5, 2026
…imentalDecorators (P2.1)

Smoke test for Phase 2 @ifoo migration: switch
`services.set(IConnectionRegistry, new ConnectionRegistry())` to
`services.set(IConnectionRegistry, new SyncDescriptor(ConnectionRegistry))`
so the container drives construction through
`_createAndCacheServiceInstance` and the @ifoo auto-injection path.
ConnectionRegistry has 0 service deps so the auto-inject step is a no-op
— this is the minimum viable proof that the new path replaces ad-hoc
`new C()` registrations cleanly. Logger stays as an externally-built
`PinoLogger` instance (its ctor takes the pino DaemonLogger, not a DI
dependency).

Also enable `experimentalDecorators: true` in
`packages/{daemon,services}/tsconfig.json` — required prerequisite for
`@IFoo`-style parameter decorators landing in P2.2 onwards. The root
tsconfig stays untouched; only the two packages migrating to @ifoo opt
in. esbuild (vitest transpiler) and tsdown (rolldown bundler) both
honor this flag for legacy parameter-decorator emit.

Per phase-1 reviewer handoff #1: this is the smoke test confirming a
single descriptor-based registration migrates cleanly before fan-out.
agent-core/src/di/ untouched (sealed for Phase 2).

Daemon test green (241 pass after one flake-rerun on fs-watch.e2e.test.ts
AC #2 burst window — known flake per phase-1 reviewer handoff #5).

VERDICT: PASS — start.ts:296 descriptor swap + tsconfig
experimentalDecorators=true; 241/241 daemon tests green.
sailist added a commit to sailist/kimi-code that referenced this pull request Jun 8, 2026
…er-domain move

Cleanup tail of the per-domain restructure. Step B.1's atomic move deleted
8 positive-service interfaces and impls but left the 3 broker interfaces
(approval/question/event) and 2 broker adapters in the old layout while
their new domain copies (approval/, question/, event/) were already wired
into the barrel — making the old files dead orphans.

Drop them and let the empty parent directories vanish. The barrel
src/index.ts already points exclusively at the new per-domain folders;
nothing in packages/services or packages/daemon imports the old paths.

Quality gates match the Phase A baseline exactly: services tsc 13
pre-existing errors, daemon tsc 30, services tests 140/140, daemon tests
261/262 (the known fs-watch.e2e.test.ts AC MoonshotAI#2 flake).
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