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).
sailist added a commit that referenced this pull request Jun 9, 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 #2 flake).
wintrover added a commit to wintrover/kimy that referenced this pull request Jun 29, 2026
- kimy wrapper: move hash writes after smoke test (MoonshotAI#1)
- kimy wrapper: add public/ to web hash inputs (MoonshotAI#3)
- kimy wrapper: widen vis hash to include config files (MoonshotAI#4)
- kimy wrapper: move lockfile from /tmp to ~/.kimy/bin (MoonshotAI#5)
- kimy wrapper: use explicit package list for native hash (MoonshotAI#7)
- 01-bundle.mjs: skip vis-asset build when already done (MoonshotAI#2)
- justfile: sync deploy with new wrapper, add deploy-full (MoonshotAI#9,MoonshotAI#10,MoonshotAI#11)
- flake.nix: add unpin guidance to nixpkgs comment (MoonshotAI#12)
kermanx added a commit that referenced this pull request Jul 13, 2026
…watch AC #2

- minidb: fuzz-model 10 seeds x 500 steps -> 6 x 250; compaction-race
  heavy-writes 20k/5k -> 10k/2k (still spans five writeSnapshot yields
  and a >64KiB WAL tail); crash-recovery runs 8/4 -> 5/3 (cost is
  subprocess spawn, not rounds); compaction concurrent 10k/2k -> 5k/1k
- replace real-second waits with injected short timeouts or fake timers:
  hooks runner timeout 1s -> 0.05s (both packages), lifecycle-hooks
  printWaitCeilingS 1s -> 0.05s, task-tools block-timeout driven by fake
  timers, mcp connection-manager slow-startup child exits on stdin end,
  kap-server 429 test injects a token-only auth service (12x bcrypt
  ~250ms was the real cost, not the rate limiter)
- fs-watch AC #2: the burst test required chokidar to deliver >500
  events inside one 200ms window, which trickles under CI load. Add an
  fsWatcherOptions seam to ServerStartOptions (default behavior
  unchanged) and run the test with a 500ms window / 100-event threshold,
  which still proves truncation but tolerates 10x slower delivery
7723qqq referenced this pull request in 7723qqq/kimi-code Jul 18, 2026
#2: Batch appendLoopEvent in executeStepTools — collect all tool.call
and tool.result events during for-await, then dispatch once at end.
Eliminates N synchronous context array copies per step.

#3: Wire tryNativeReadBatch into native-tools.ts — existing Rust
nativeBatchRead now callable from the tool layer. Callers fall back
to sequential nativeRead when native module unavailable.

#1: Async-ify native_edit with spawn_blocking — no longer blocks
event loop during parallel tool execution.
asdshuaishuai pushed a commit to d2rabbit/kimi-code that referenced this pull request Jul 21, 2026
…, diff drawer, more rounded corners

Five user-reported issues fixed in this batch:

MoonshotAI#3 Font-size adjustment now actually works
  Root cause: App.svelte's :global(body) used the `font:` shorthand
  with a hardcoded 13px, which won over the global.css
  `body { font-size: var(--ui-font-size) }` rule (same specificity,
  later in cascade). The shorthand resets font-size and the slider had
  no effect.
  Fix: replace shorthand with individual properties
  (font-family/size/line-height), keep font-size: var(--ui-font-size).
  Verified via headless Chromium: default 14px, slider to 20px → 20px,
  back to 14px → 14px.

MoonshotAI#8 Plugin enable/disable ACL error
  Root cause: PluginPanel called Command.sidecar('kimi', ['plugin',
  'disable', id]) which needs shell:allow-execute permission that
  isn't (and shouldn't be) granted in tauri.conf.json.
  Fix: added Rust `toggle_plugin(plugin_id, enabled)` command that
  directly edits ~/.kimi-code/plugins/installed.json (atomic tmp+rename).
  PluginPanel now invoke()s the new command instead of spawning a
  sidecar. No ACL needed.

MoonshotAI#11 Softer UI — bumped radius tokens
  --r-sm 6→8, --r-md 8→10, --r-lg 10→14, --r-xl 12→18.
  Legacy scale bumped in parallel (--radius-xs 6→8, etc.). All
  components using these tokens get the bump automatically.

MoonshotAI#2 Sidebar workspace/session hierarchy
  Workspace headers are now visually bigger (30px tall, 12.5px bold,
  with a top border + subtle bg gradient) and the session rows are
  indented (margin-left: 20px, smaller 11.5px font-weight 400).
  Workspace count badge becomes a pill instead of plain text. The
  hierarchy reads cleanly now.

MoonshotAI#1 Working-directory diff → second-level right drawer
  New DiffDrawer.svelte component (540px, slides in from right with
  spring animation). Clicking a file in the '工作区改动' section of
  RightPanel opens the drawer; inline expansion is gone. Commit-
  history diffs stay inline (only the working-directory section was
  changed per UX request). Esc / ✕ / mask click closes.

MoonshotAI#9 Composer compact moved into the main control row
  '压缩' is now a pill button next to mode/model/thinking instead of
  a separate FAB below. Per UX request: 'mode / model / thinking /
  compact all in one row'.

Verified: svelte-check 0 errors, cargo check 0 warnings.
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