Usage-based token scale can be deflated by providers that exclude cached tokens from prompt_tokens

オープン
#1,830 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

Start with _usage_total in mellea/stdlib/context/compactor.py, which derives the measured token count from total_tokens or prompt_tokens + completion_tokens, then read ChatContext._usage_scale in mellea/stdlib/context/chat.py where the ratio is clamped to _MIN_USAGE_SCALE. The work is investigate-and-guard: choose a plausibility check (budget cross-check, prefer prompt_tokens, or skip the correction when the total is implausibly small). Done means a guard is in place with tests covering an Anthropic-style cache-excluded usage payload.

索引モデルが issue の本文から書いたものです。

説明

enhancement needs-design
What happened?

_usage_total (mellea/stdlib/context/compactor.py) derives the measured
token count from total_tokens, falling back to prompt_tokens + completion_tokens. Through providers whose usage accounting excludes
cache-read tokens from prompt_tokens
(Anthropic-style accounting, common
via LiteLLM routing), the measured total covers only the uncached suffix plus
the completion.

In ChatContext._usage_scale (mellea/stdlib/context/chat.py, from #1760),
every receipt/identity check still passes and estimated >= _MIN_MEASURED_ESTIMATE still passes, so the ratio is computed from the
deflated measurement and clamps to _MIN_USAGE_SCALE (0.5). Every history
item is then costed at half its estimate, so up to ~2x the model's real
context can be admitted within the budget — producing hard context-length API
errors. The pre-#1760 unscaled estimate was inaccurate in the same direction,
but was never multiplied down by a mismeasurement.

Ollama is not affected: its prompt_eval_count includes KV-cached prefix
tokens (verified during the #1760 review).

What did you expect to happen?

The correction should not silently over-admit history based on a measurement
that under-counts the request.

Notes
  • Scope as investigate-and-guard rather than a presumed fix. Options to
    evaluate: cross-check the measured total against the current budget before
    applying the ratio; prefer prompt_tokens as the basis when total_tokens
    is inconsistent with it; or skip the correction when the measured total is
    implausibly small relative to the rendered request.
  • Related to the "overhead is counted twice" discussion in the #1760 review
    (documented, not changed, in the merged code).
主要言語
Python
スター
1.8k
フォーク
161
平均マージ
4日 3時間
マージ済み PR(30日)
45

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

generative-computing/mellea のほかの issue

generative-computing/mellea の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。