Skip to content

docs(tokenless): clarify savings-rate field definitions - #2596

Open
Forrest-ly wants to merge 2 commits into
alibaba:mainfrom
Forrest-ly:fix/tokenless-savings-rate-definition-docs
Open

docs(tokenless): clarify savings-rate field definitions#2596
Forrest-ly wants to merge 2 commits into
alibaba:mainfrom
Forrest-ly:fix/tokenless-savings-rate-definition-docs

Conversation

@Forrest-ly

@Forrest-ly Forrest-ly commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Why

Customer feedback reported a savings_rate field computed as cached_tokens / total_tokens, attributed to the tokenless-stats program, and asked to either fix the numeric definition of the field or clarify the documentation.

Investigation against current main and the full history of the tokenless component:

  • tokenless-stats has never emitted a savings_rate, cached_tokens, or total_cached_tokens field — verified by searching the complete history of src/tokenless (git log -S) and inspecting every output path (stats summary text/JSON, --compare text/JSON, stats diff, SLS JSONL records).
  • Every percentage tokenless-stats reports already follows the definition the customer expects ("saved tokens ÷ original uncompressed tokens"):
    • chars_saved_percent = (before_chars − after_chars) ÷ before_chars × 100%
    • tokens_saved_percent = (before_tokens − after_tokens) ÷ before_tokens × 100%
    • saved_percent (compare) = (baseline_tokens − tokenless_tokens) ÷ baseline_tokens × 100%
  • cached_tokens / total_tokens style fields are model-provider prompt-cache metrics surfaced by other observability tooling; they are not tokenless compression savings and are not produced by this component.

There is therefore no savings_rate definition to fix in code; the right remedy is explicit documentation, which this PR adds.

What changed (docs only)

  • docs/user-guide/{zh,en}/token-saving/tokenless/measuring-savings.md
    • New "Saving-rate field definitions" section: a formula table for every percentage field emitted by tokenless stats; clarification that the text-output percentage (Saved: N tokens (X%)) uses before_tokens (the original, uncompressed size) as denominator — not the session total and not any provider-side cache metric; and an explicit note that savings_rate / cached_tokens / total_cached_tokens are not tokenless-stats output (prompt-cache hit share ≠ tokenless compression savings).
    • Cross-reference added in the existing "Interpret the saving rate correctly" section.
  • docs/user-guide/{zh,en}/token-saving/tokenless/cli-reference.md
    • Short note in the stats section pointing to the field-definition table.

Validation (real execution)

Environment: Linux x86_64, Rust cargo/rustc 1.94.1.

  1. Build: cargo build -p tokenless-cli — success (0 errors).
  2. Tests:
    • cargo test -p tokenless-stats — 143 passed, 0 failed.
    • cargo test -p tokenless-cli — 255 passed, 0 failed, 2 pre-existing #[ignore] (env-check tests, unrelated).
  3. Targeted verification of every documented formula against real CLI output (isolated data directory via TOKENLESS_DATA_DIR, synthetic payload):
    • stats summary --json: chars_saved_percent = 12343/25300×100 = 48.7866% ✓; tokens_saved_percent = 3086/6326×100 = 48.7828% ✓; text output prints Saved: 3086 tokens (48.8%)
    • stats summary --compare baseline-run active-run --json: saved_percent = (3163−1626)/3163×100 = 48.5931% ✓
    • Summary output contains no savings_rate / cached_tokens fields ✓
  4. git diff --check — clean.

Not run: none skipped — the repository has no dedicated lint gate for these Markdown docs.

Risk and compatibility

  • Public CLI, API, configuration, or documented behavior changed
  • Privileged or security-sensitive behavior changed
  • Cross-component contract changed
  • Migration or rollback guidance is needed

Docs-only change; no behavior, schema, or CLI output changes. Revert the commit to undo.

Follow-up: review round 1 (stats diff percentages)

Adopted the review comment: tokenless stats diff --json also serializes saved_percent for every chain and stage, using that object's own before_tokens/after_tokens. Added the diff variants to the saving-rate field table (both languages) plus a sentence disambiguating the two saved_percent scopes (--compare run totals vs per-chain/stage totals), keeping the "every percentage field" claim exhaustive. Reply posted in the review thread.

Validation (real execution, follow-up round)

Environment: Linux x86_64, Rust cargo/rustc 1.94.1.

  1. Tests: cargo test -p tokenless-stats — 143 passed, 0 failed.
  2. Build: cargo build -p tokenless-cli — success (0 errors).
  3. Targeted verification against real CLI output (isolated data directory via TOKENLESS_DATA_DIR, synthetic payloads):
    • stats diff <record-id> --json: chain saved_percent = (4380 − 3444) ÷ 4380 × 100% = 21.3698630137% ✓ (matches serialized value exactly); the stage row uses the same formula on the record's own totals ✓
    • stats diff --session <session-id> --json (multi-chain output): every chain and every stage carries saved_percent; all values match (before_tokens − after_tokens) ÷ before_tokens × 100% recomputed from the same object's own totals ✓
  4. git diff --check — clean.

Not run: none skipped — the repository has no dedicated lint gate for these Markdown docs (Docs Lint runs in CI).

@Forrest-ly
Forrest-ly requested a review from casparant as a code owner August 17, 2026 03:22
@github-actions github-actions Bot added the scope:documentation ./docs/|./*.md|./NOTICE label Aug 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52952401b7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


## Saving-rate field definitions

Tokenless always expresses a saving rate as “saved tokens as a share of the original, uncompressed tokens”; only the aggregation scope differs. Every percentage field emitted by `tokenless stats` is defined as follows:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include stats diff percentages in the field table

The table is not exhaustive: tokenless stats diff ... --json also serializes saved_percent for every chain and stage (src/tokenless/crates/tokenless-stats/src/diff.rs:108-127 and 148-162), using that object's before_tokens and after_tokens. A consumer following this new table could therefore treat saved_percent solely as a comparison-schema field with baseline/tokenless totals, even though diff output uses the same key with a different scope. Add the diff variants and formula, or narrow the claim that this defines every percentage field.

Useful? React with 👍 / 👎.

@Forrest-ly Forrest-ly Aug 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — adopted. tokenless stats diff --json does serialize saved_percent for every chain and stage, computed from that object's own before_tokens/after_tokens rather than the --compare run totals.

Fixed in 157bb0c: added the diff variants to the field table in both language versions of measuring-savings.md, plus a sentence disambiguating the two saved_percent scopes, so the table stays exhaustive for every percentage field emitted by tokenless stats.

Verified against real CLI output with synthetic records (isolated data dir): stats diff <id> --json and stats diff --session <sid> --json both emit saved_percent per chain and per stage, and every value matches (before_tokens − after_tokens) ÷ before_tokens × 100% recomputed from that same object's own totals exactly.

@qoderai qoderai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本次审查范围内未发现需要修改的问题。


🤖 Generated by QoderView workflow run

Customer feedback reported a savings_rate field computed
as cached_tokens / total_tokens and attributed it to
tokenless-stats. tokenless-stats has never emitted savings_rate or
cached_tokens: every percentage it reports is saved amount divided
by the original, uncompressed amount. Document the exact formula for
each percentage field (chars_saved_percent, tokens_saved_percent,
saved_percent), state that the text output percentage uses
before_tokens as the denominator, and note explicitly that prompt-cache
fields such as savings_rate / cached_tokens / total_cached_tokens
are provider-side metrics not produced by tokenless-stats.
@Forrest-ly
Forrest-ly force-pushed the fix/tokenless-savings-rate-definition-docs branch 3 times, most recently from 84b7838 to 3931626 Compare August 17, 2026 04:12
tokenless stats diff --json serializes saved_percent for every chain and
stage, computed from that object's own before_tokens and after_tokens.
Add these variants to the saving-rate field table in both languages and
note how their scope differs from the --compare saved_percent, so the
table remains exhaustive for every percentage field emitted by
tokenless stats.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:documentation ./docs/|./*.md|./NOTICE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant