Skip to content

Add DeepSeek cache-aware usage accounting - #20

Merged
likun666661 merged 1 commit into
apache:mainfrom
likun666661:deepseek-cost-runtime-phase1
Jun 16, 2026
Merged

Add DeepSeek cache-aware usage accounting#20
likun666661 merged 1 commit into
apache:mainfrom
likun666661:deepseek-cost-runtime-phase1

Conversation

@likun666661

@likun666661 likun666661 commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary

  • normalize DeepSeek/OpenAI-compatible cache hit, cache miss, cache write, reasoning, total, raw usage, and raw finish reason fields at the model-adapter boundary
  • charge input cost from cache-miss tokens while preserving cache-read/cache-write pricing and legacy cached-input aliases
  • propagate richer token usage through SessionEvent, RuntimeEvent, RunTrace, telemetry, settings usage stats, materialized turns, and the Settings usage card

Refs #19. This PR implements only the phase-1 usage/pricing/accounting surface; the broader cost-runtime issue remains open.

Verification

  • npm run typecheck --workspaces --if-present
  • npm --workspace @maka/runtime test (458/458)
  • npm --workspace @maka/core test (614/614)
  • npm --workspace @maka/storage test (81/81)
  • npm --workspace @maka/desktop test (1399/1399)
  • git diff --check
  • real DeepSeek deepseek-chat smoke with local DEEPSEEK_API_KEY: normalized prompt_tokens, completion_tokens, total_tokens, prompt_cache_hit_tokens, and prompt_cache_miss_tokens; cache-hit input observed.

@likun666661
likun666661 merged commit e4a48a5 into apache:main Jun 16, 2026
jackwener pushed a commit that referenced this pull request Jun 21, 2026
Add DeepSeek cache-aware usage accounting
jackwener pushed a commit that referenced this pull request Jun 21, 2026
Add DeepSeek cache-aware usage accounting
jackwener added a commit that referenced this pull request Jun 21, 2026
borrow
- xuan's transparent local MEMORY.md MVP (c06e13f) — two-switch
  shape (enabled + agentReadEnabled), HTML-comment metadata,
  fail-open parser, 0700/0600 perms, 128 KB cap.
- kenji's boundary (19b0996f): local transparent file MUST NOT
  become implicit durable memory; agent-read default OFF.
- kenji's 3-way confirmation (7749c411 #3): no plugin-provider
  abstraction yet — alma is built-in, pilotdeck is single
  provider with embedding selector, only Hermes is true plugin
  registry. Two-of-three is NOT convergence; defer abstraction.

diverge
- This is a contract anchor, NOT code. Freezes field names + status
  semantics so V0.2 / V0.3 PRs extend predictably without breaking
  V0.1 disk format. If reality changes, edit here first.

risk
- None. Documentation only. No file Maka reads/writes references
  this note at runtime.

What
- `notes/maka-memory-whitebox-contract.md`:
    - V0.1 (live): xuan's settings shape, file format, parse output
      with the `status` enum invariants.
    - V0.2 (forward): origin/status/decay/tags/stable-id extensions
      to the HTML-comment metadata. Parser MUST stay fail-open on
      unknown fields so V0.1 readers don't break on V0.2 files.
    - V0.3 (open): provider abstraction / vector search / cross-
      session recall / Dream Mode / multi-workspace memory.
- Decisions log table with date + decision + source-msg pointers.
- Pointers section linking xuan implementation + Hermes / pilotdeck
  deep-dive notes.

Notes
- The `extract_memory` agent tool design is intentionally deferred
  to V0.2; when shipped it is `permissionRequired: true`, gated on
  both `agentReadEnabled` AND a new `extractToolEnabled` switch
  (you cannot extract memory the agent cannot read).
- Contract test surface §"Contract test surface" lists the 5
  invariants the V0.2 implementation will need to lock down.
jackwener pushed a commit that referenced this pull request Jun 21, 2026
Add DeepSeek cache-aware usage accounting
jackwener added a commit that referenced this pull request Jun 21, 2026
borrow
- xuan's transparent local MEMORY.md MVP (c06e13f) — two-switch
  shape (enabled + agentReadEnabled), HTML-comment metadata,
  fail-open parser, 0700/0600 perms, 128 KB cap.
- kenji's boundary (19b0996f): local transparent file MUST NOT
  become implicit durable memory; agent-read default OFF.
- kenji's 3-way confirmation (7749c411 #3): no plugin-provider
  abstraction yet — alma is built-in, pilotdeck is single
  provider with embedding selector, only Hermes is true plugin
  registry. Two-of-three is NOT convergence; defer abstraction.

diverge
- This is a contract anchor, NOT code. Freezes field names + status
  semantics so V0.2 / V0.3 PRs extend predictably without breaking
  V0.1 disk format. If reality changes, edit here first.

risk
- None. Documentation only. No file Maka reads/writes references
  this note at runtime.

What
- `notes/maka-memory-whitebox-contract.md`:
    - V0.1 (live): xuan's settings shape, file format, parse output
      with the `status` enum invariants.
    - V0.2 (forward): origin/status/decay/tags/stable-id extensions
      to the HTML-comment metadata. Parser MUST stay fail-open on
      unknown fields so V0.1 readers don't break on V0.2 files.
    - V0.3 (open): provider abstraction / vector search / cross-
      session recall / Dream Mode / multi-workspace memory.
- Decisions log table with date + decision + source-msg pointers.
- Pointers section linking xuan implementation + Hermes / pilotdeck
  deep-dive notes.

Notes
- The `extract_memory` agent tool design is intentionally deferred
  to V0.2; when shipped it is `permissionRequired: true`, gated on
  both `agentReadEnabled` AND a new `extractToolEnabled` switch
  (you cannot extract memory the agent cannot read).
- Contract test surface §"Contract test surface" lists the 5
  invariants the V0.2 implementation will need to lock down.
jackwener pushed a commit that referenced this pull request Jun 21, 2026
Add DeepSeek cache-aware usage accounting
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.

1 participant