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).

Rebase onto main (merge-conflict resolution)

The branch carried 61 commits over a stale base; 59 of them had already landed on main (verified by patch-id / commit-title comparison), which caused the 91-file conflict report. The branch was therefore rebased onto latest main keeping only this PR's two docs commits — no code changes, the effective diff remains the 4 docs files.

Validation (real execution, rebase round)

Environment: Linux x86_64, Rust cargo/rustc 1.96.0.

  1. Build: cargo build -p tokenless-cli — success (0 errors).
  2. Tests:
    • cargo test -p tokenless-stats — 153 passed, 0 failed (2 suites).
    • cargo test -p tokenless-cli — 295 passed, 0 failed, 2 pre-existing #[ignore] (env-check tests, 3 suites).
  3. git diff --check against main — clean; no conflict markers; resulting tree verified docs-only (4 files).

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

Forrest-ly and others added 2 commits August 29, 2026 12:45
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.

Co-authored-by: multica-agent <github@multica.ai>
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.

Co-authored-by: multica-agent <github@multica.ai>
@kongche-jbw
kongche-jbw force-pushed the fix/tokenless-savings-rate-definition-docs branch from 9495560 to 53597dc Compare August 29, 2026 04:46
@KaiLongZhou

Copy link
Copy Markdown
Collaborator

PR #2596 Review 结论:✅ 通过

审查范围

4 个文档文件,共 40 行新增、2 行修改,纯文档变更,无代码改动。

公式准确性验证

已逐一对照 src/tokenless/ 源码验证所有公式声明:

文档声明 源码位置 结论
chars_saved_percent = (before_chars − after_chars) ÷ before_chars × 100% recorder.rs:665, record.rs:300 ✅ 一致
tokens_saved_percent = (before_tokens − after_tokens) ÷ before_tokens × 100% recorder.rs:673, record.rs:309 ✅ 一致
saved_percent (compare) = (baseline_tokens − tokenless_tokens) ÷ baseline_tokens × 100% query.rs:432 ✅ 一致
saved_percent (diff) = (before_tokens − after_tokens) ÷ before_tokens × 100% diff.rs:765 ✅ 一致
文本输出 Saved: N tokens (X%) 对应 tokens_saved_percent query.rs:94 调用 total.tokens_percent() ✅ 一致
savings_rate / cached_tokens / total_cached_tokens 不存在于 tokenless-stats grep -r 全目录零匹配 ✅ 一致

文档质量

  • 结构清晰:新增 "Saving-rate field definitions" / "节省率字段定义" 专节,表格化列出全部百分比字段的来源、公式和含义
  • 中英文一致:EN 和 ZH 版本内容对齐,锚点链接(#saving-rate-field-definitions / #节省率字段定义)正确
  • 交叉引用完整:cli-reference.md 和 measuring-savings.md 的 "正确解释节省率" 节均添加了互相引用
  • 澄清到位:明确区分了 tokenless 压缩节省率 vs 提供商 prompt-cache 命中率(cached_tokens ÷ total_tokens),直接回应了客户反馈的混淆点
  • stats diff --json 覆盖:第二个 commit 补充了 diff 输出中 saved_percent 的 per-chain/per-stage 口径说明,避免了与 --compare 的混淆

结论

文档内容准确、结构合理、中英文对齐,公式与源码实现完全一致。建议合并。

@code-reviewer-leader 请继续委派 code-reviewer-check 进行审核。

@yummypeng
yummypeng removed their request for review August 31, 2026 03:35
@SunnyQjm

Copy link
Copy Markdown
Collaborator

PR number: #2596
head_sha: 53597dc
reviewed_at: 2026-08-31T05:43:39Z

Findings

无。

组织规则核对

本 PR 不触及 cosh-ng/cosh-shell,变更范围仅为 docs/user-guide/{zh,en}/token-saving/tokenless/ 下的用户文档,代码组织规则(owner、public API、大文件、依赖方向)无适用对象。未发现 blocking package/module/public API 组织问题。

内容抽查(静态、仅基于 diff 自洽性)

  • 中英文两版新增的字段定义表逐行对齐:字段、来源、公式、含义一致;saved_percent 两种口径(--compare 运行级总量 vs stats diff --json 每 chain/stage 自身总量)的消歧句两版均保留。
  • 交叉引用锚点自洽:EN #saving-rate-field-definitions、ZH #节省率字段定义 与各自新增小节标题匹配;cli-reference.md 指向 measuring-savings.md 的相对链接路径正确。
  • 历史 P2 意见(diff 输出的 saved_percent 未入表)已在后续 commit 中采纳,diff 中可见对应表格行与消歧说明,无遗留。
  • 文本输出 Saved: N tokens (X%)tokens_saved_percent 的对应关系、以及“不输出 savings_rate/cached_tokens”的澄清声明,与 PR 描述和既有 reviewer 对照源码的验证结论一致。

剩余风险

  • 表格“tokenless stats 输出的全部百分比字段”这一完备性声明依赖源码事实;本评审为静态评审且规则限定不读输入外内容,未独立核对 tokenless-stats 源码,该事实采纳前序 reviewer 的逐项源码对照结论。
  • 若后续 tokenless stats 新增百分比字段,此表需同步更新,否则“全部字段”声明会漂移(文档固有维护成本,非 blocking)。

Validation

  • 未执行任何工具或本地验证(本评审环境不提供工具)。
  • 以 CI 实测为准:📚 Docs LintBuild website🔍 PR Checks📝 Commit Message Lint 均为 SUCCESS;代码类 check 按变更检测合理 SKIPPED。
  • 建议合并前确认 Docs Lint 在最新 head 上仍通过即可,无额外验证要求。

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.

3 participants