[Bug] Retry attempts and compaction requests are undercounted in session usage #2426
Replies: 2 comments
|
Retry 和 compaction 请求未计入 session usage——成本统计口径漏了重试和压缩的消耗,会让成本账单偏低。 成本透明化(第 14 章)的前提是统计准确,这类口径问题该修:https://github.com/Electricitysheep/dsh-handbook/blob/main/docs/14-cost.md |
|
Two implementations of this exist now, and they differ in one structural way worth deciding before either is imported. Your rule 2 closes replacement adjacency on I verified 63688b0 against a real corpus rather than against its description: whole log 308,234, child-owned 55,886, bucket for bucket, identical to an independent fold written from the source. Both approaches produce the right number on the retry path. The difference is what they depend on. The finish chunk is already in the stream On your rules 2 and 3 being separate concerns, which I think is the most useful thing in this thread: usage settlement and retry counting are two different quantities and should not share a discriminator. A failure finish settles a billed attempt — that is money. Rules 4 and 5 match what #1886 measured: 3 compaction events, 48,895 tokens, none counted, and the largest was cache-read heavy enough to matter. One boundary that neither implementation exercises yet, now split out as #3126: |
Uh oh!
There was an error while loading. Please reload this page.
Summary / 摘要
The durable token/session projections can under-report provider requests when retries and context compaction are involved:
{turn, step}.compaction/summaryprovider usage is durable but is omitted from whole-session token totals.These are provider-agnostic accounting issues. They became visible while correlating DSH statistics with subscription-backed model usage.
DSH 当前在 Retry 与 Context Compaction 场景下可能低估完整 provider 请求消耗:失败 attempt 的 usage 被成功 retry 覆盖、退避期间取消的 retry 被当成已执行、Compaction 摘要请求未进入会话总计。
Minimal event sequences
1. Failed attempt followed by successful retry
Retries execute inside the same step. If usage identity is only
step:<turn>:<step>, B replaces A. Expected whole-session billing isA + B; last-sample replacement should apply only within one request attempt.2. Cancellation during backoff
No
llm/retry-startedoccurs and no repeated provider request starts. Countingllm/retryreports one retry although only the original attempt ran.3. Compaction summary usage
This is a separate provider request and should contribute to whole-session usage. It should not replace the main model's context-pressure sample because it belongs to the summarizer request.
Proposed accounting rules
llm/retry-started, close/reset replacement adjacency so the next attempt accumulates independently.llm/retry-started, not scheduled backoffs fromllm/retry.compaction/summary.usagetotokenUsage, keyed bycompactionId.contextPressure.Validation
Focused patch validation:
token-meter: failed-attempt usage + successful retry regressionsession-stats: scheduled-but-cancelled retry regressionReference implementation
Focused bug-fix branch and commit:
ccc842215aAn integrated branch that also contains the separately reported Windows fix is available here:
Because external PRs are currently not accepted, this Discussion provides reproducible event sequences, semantics, tests, and a focused patch. I would appreciate confirmation of the intended accounting semantics and whether maintainers would like to import or reimplement it.
All reactions