Skip to content

Commit 729b9d1

Browse files
jay-tauCopilot
andcommitted
docs(adapter/copilot): scrub private review-process metadata from code comments
External PR ccusage#1209 code review identified the single recommended maintainer gate before merge: strip references to ephemeral, private development artifacts ("plan finding #N", "GPT-5.5 R12/R14", "Piece B/C", "round-1/2 finding", "plan round-3 finding", "seq-7 round-1B") from shipped code. These were meaningful to the author during the iterative development + multi-model review process, but read as noise (or confusion) to a future maintainer six months out. Preserve the substance of every comment — what the code does and why — while dropping the development-internal identifiers: - `plan finding ccusage#10` → "Aggregate-only credits path:" - `plan finding from PR ccusage#957 + GPT-5.5 R12` → "Skip rule for per-model metrics rows:" (PR ccusage#957 citation kept — external + persistent) - `plan finding ccusage#7` → "in real session-state data" - `plan finding #2` → (dropped — comment is self-explanatory) - `plan finding for GPT-5.5 R14` → "Dedup key selection:" - `plan finding ccusage#3 / Piece C carry-over from PR ccusage#957` → "carried over from PR ccusage#957's TypeScript implementation" - `round-1/2 finding` → "documented invariant" - `// ----- Piece B (credits) -----` → "AI Credits tests (totalNanoAiu)" - `plan finding #1` → (dropped) - `plan finding ccusage#8` → (dropped — paraphrased into the comment) - `plan round-3 finding` → (dropped — paraphrased into the comment) - `mirrors the seq-7 round-1B parser fixture fix` → (dropped — the preceding sentences already explain the genuinely-absent-vs-Some(0) reasoning standalone) PR ccusage#957 references stay (external, persistent, useful for context). External symbol/test/file references all resolve. No behavioral change. Co-authored-by: Copilot <[email protected]>
1 parent e0d72fd commit 729b9d1

2 files changed

Lines changed: 29 additions & 25 deletions

File tree

‎rust/crates/ccusage/src/adapter/copilot/loader.rs‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn load_entries_inner(
7373

7474
// Loader-side dedup by `dedup_key` (mirrors the codebuff adapter's
7575
// `load_entries_inner` HashMap collapse). Required because content-based
76-
// dedup keys for credit-only rows (Piece B) must collapse before
76+
// dedup keys for credit-only AI Credits rows must collapse before
7777
// aggregation.
7878
let mut deduped: HashMap<String, CopilotUsageEntry> = HashMap::new();
7979
for entry in entries {
@@ -136,8 +136,9 @@ fn usage_entry_to_loaded(
136136
message: UsageMessage {
137137
usage,
138138
// Preserve raw model name in JSON / `modelsUsed` / table for
139-
// source fidelity (plan finding #8). Normalization happens only
140-
// at the pricing call sites below.
139+
// source fidelity. Normalization happens only at the pricing
140+
// call sites below (Copilot routing suffixes are stripped for
141+
// LiteLLM lookup but kept in user-visible output).
141142
model: model_for_data.clone(),
142143
id: Some(entry.dedup_key),
143144
},
@@ -258,7 +259,7 @@ fn usage_entry_to_loaded(
258259
// normalizing at `missing_pricing_model_for_usage`,
259260
// `pricing.find` rejects suffixes like `-1m-internal` and
260261
// emits a contradictory "Missing embedded pricing" warning
261-
// even when cost > 0 (plan round-3 finding).
262+
// even when cost > 0.
262263
//
263264
// Pass `CostMode::Calculate` (NOT the surrounding `mode`,
264265
// which may be `Auto`) into both helpers: this branch is
@@ -528,8 +529,7 @@ mod tests {
528529
// `cost: Some(0.0)` would flatten to the same `$0` in Display via
529530
// `credit_cost.or(premium_cost).unwrap_or(0.0)`, but it routes
530531
// through the `has_premium_data == true` arm and misrepresents the
531-
// genuinely-absent narrative the test claims (mirrors the seq-7
532-
// round-1B parser fixture fix).
532+
// genuinely-absent narrative the test claims.
533533
json!({
534534
"type": "session.shutdown",
535535
"id": event_id,
@@ -739,7 +739,8 @@ mod tests {
739739
let entries = load_entries_inner(&shared_args_default(), &pricing).unwrap();
740740
assert_eq!(entries.len(), 1);
741741
let entry = &entries[0];
742-
// Raw model preserved for display (plan finding #8).
742+
// Raw model preserved for display (normalization happens only at
743+
// the pricing call sites, not on the user-visible field).
743744
assert_eq!(
744745
entry.model.as_deref(),
745746
Some("claude-opus-4.7-1m-internal"),
@@ -753,8 +754,10 @@ mod tests {
753754
);
754755
// missing_pricing_model must be None — otherwise the breakdown
755756
// branch of `UsageAccumulator::add_entry` (summary.rs) would flip
756-
// `breakdown.missing_pricing` and emit a contradictory warning
757-
// (regression pin for plan round-3 finding about BOTH call sites).
757+
// `breakdown.missing_pricing` and emit a contradictory warning.
758+
// Pins the invariant that BOTH the pricing call site AND the
759+
// missing-pricing-detection call site receive the normalized model
760+
// name (loader.rs's token-priced arm).
758761
assert!(
759762
entry.missing_pricing_model.is_none(),
760763
"expected missing_pricing_model None, got {:?}",

‎rust/crates/ccusage/src/adapter/copilot/parser.rs‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,10 @@ pub(super) fn parse_session_state_file(path: &Path) -> Result<Vec<CopilotUsageEn
771771
));
772772
}
773773

774-
// Aggregate-only credits path (plan finding #10): when the shutdown
775-
// event reports a session-level `totalNanoAiu > 0` AND no per-model
776-
// row already carries a priced billing signal (per-model `naiu > 0`
777-
// OR `requests.cost > 0`), emit a synthetic zero-token, model-less
774+
// Aggregate-only credits path: when the shutdown event reports a
775+
// session-level `totalNanoAiu > 0` AND no per-model row already
776+
// carries a priced billing signal (per-model `naiu > 0` OR
777+
// `requests.cost > 0`), emit a synthetic zero-token, model-less
778778
// entry that carries the aggregate credits.
779779
//
780780
// The guard checks for priced billing — not just per-model AIU —
@@ -827,7 +827,7 @@ pub(super) fn parse_session_state_file(path: &Path) -> Result<Vec<CopilotUsageEn
827827
Ok(entries)
828828
}
829829

830-
/// Skip rule (plan finding from PR #957 + GPT-5.5 R12):
830+
/// Skip rule for per-model metrics rows:
831831
///
832832
/// * Skip when all five token fields AND `requests.count` are zero (mirrors
833833
/// PR #957's `data-loader.ts` inline skip-row predicate, extended to
@@ -875,15 +875,15 @@ fn build_session_state_entry(
875875
let usage = &metrics.usage;
876876
// `usage.inputTokens` in this schema is inclusive of BOTH `cacheReadTokens`
877877
// and `cacheWriteTokens` (verified against the per-model `tokenDetails`
878-
// ground truth in plan finding #7). Subtract both to recover the "fresh"
879-
// input bucket; saturating_sub keeps us safe if a future schema variant
880-
// ever publishes inconsistent values.
878+
// ground truth in real session-state data). Subtract both to recover the
879+
// "fresh" input bucket; saturating_sub keeps us safe if a future schema
880+
// variant ever publishes inconsistent values.
881881
let input_only = usage
882882
.input_tokens
883883
.saturating_sub(usage.cache_read_tokens)
884884
.saturating_sub(usage.cache_write_tokens);
885885

886-
// Reasoning semantics differ per provider (plan finding #2):
886+
// Reasoning semantics differ per provider:
887887
// - OpenAI (`gpt-*`) and Anthropic (`claude-*`) include reasoning inside
888888
// `usage.outputTokens`. Adding it again into the summary's
889889
// `TokenCounts` total (`types.rs::TokenCounts::total`) would
@@ -904,7 +904,7 @@ fn build_session_state_entry(
904904
&& usage.cache_write_tokens == 0;
905905
let credit_only = zero_token && metrics.requests.count == 0;
906906

907-
// Dedup key selection (plan finding for GPT-5.5 R14):
907+
// Dedup key selection:
908908
//
909909
// * Normal token-bearing rows use
910910
// `shutdown:{session_id}:{event_id}:{model}`. `event.id` is a UUID
@@ -996,7 +996,7 @@ fn session_id_from_path(path: &Path) -> Option<String> {
996996

997997
/// Normalizes a Copilot model identifier for LiteLLM pricing lookup.
998998
///
999-
/// Rules (plan finding #3 / Piece C carry-over from PR #957):
999+
/// Rules (carried over from PR #957's TypeScript implementation):
10001000
///
10011001
/// 1. Strip Copilot-specific routing suffixes (`-1m-internal`, `-internal`,
10021002
/// `-xhigh`, `-high`, `-1m`) — these are required because
@@ -1599,8 +1599,9 @@ mod session_state_tests {
15991599

16001600
#[test]
16011601
fn subtracts_both_cache_read_and_cache_write_from_input() {
1602-
// Regression pin for the round-1/2 finding that session-state
1603-
// `inputTokens` is inclusive of both cache types.
1602+
// Regression pin for the documented invariant that session-state
1603+
// `inputTokens` is inclusive of both cache-read AND cache-write
1604+
// counts (see `build_session_state_entry`'s `input_only` derivation).
16041605
let (_dir, path) = write_jsonl(&[shutdown_event(
16051606
"evt-cache",
16061607
"2026-05-02T15:27:09.013Z",
@@ -1856,7 +1857,7 @@ mod session_state_tests {
18561857
);
18571858
}
18581859

1859-
// ----- Piece B (credits) -----
1860+
// ----- AI Credits tests (totalNanoAiu) -----
18601861

18611862
fn shutdown_event_with_naiu(
18621863
id: &str,
@@ -1995,8 +1996,8 @@ mod session_state_tests {
19951996
#[test]
19961997
fn token_bearing_rows_keep_event_id_dedup_key_not_content_based() {
19971998
// Two distinct shutdowns producing the same number of tokens MUST
1998-
// stay distinct (per-process snapshots, plan finding #1). Only
1999-
// zero-token credit-only rows use the content-based key.
1999+
// stay distinct (per-process snapshots). Only zero-token
2000+
// credit-only rows use the content-based key.
20002001
let (_dir, path) = write_jsonl(&[
20012002
shutdown_event_with_naiu(
20022003
"evt-A",

0 commit comments

Comments
 (0)