Context
#12743 needs final Cloud Billing / service-metrics authority before it can be closed, but the local side of the reconciliation was still reconstructed manually from orchestrator logs and private-content-safe Memory Core length samples.
This ticket captures the narrow implementation leaf: add a reproducible local diagnostic that parses miniSummary backfill logs and computes public-pricing sanity bands from aggregate length statistics, without printing raw Memory Core prompt/response content.
Live latest-open sweep: checked latest 20 open issues at 2026-06-08T11:53:22Z; no equivalent diagnostic-script leaf found. Closest current issue is #12743, which owns the broader billing/token reconciliation and must remain open until Cloud Billing authority lands.
Semantic duplicate sweep: used non-synthesis query_documents(type='ticket') for Gemini incident cost ledger diagnostic script local orchestrator logs because ask_knowledge_base synthesis is part of the active provider-routing/cost-safety incident surface. Results surfaced older/non-equivalent incident and telemetry tickets, not a narrow local ledger diagnostic leaf.
Exact sweep: rg -n "Gemini incident cost ledger|cost ledger diagnostic|miniSummary backfill.*ledger|billing.*token.*ledger|orchestrator.*cost ledger" resources/content/issues resources/content/archive/issues resources/content/discussions returned no matches.
The Problem
The team already has a strong timing/source lead for the 2026-06-08 Gemini spike, but hand-counted log/math evidence is fragile:
- It is easy to mix up one checkout's local log volume with all billable request volume.
- It is easy to leak private memory text if future agents sample prompt/response content directly instead of aggregate lengths.
- It is easy to overstate public-pricing estimates as billing truth, when Cloud Billing SKU/model/token fields remain authoritative.
A small diagnostic script gives future agents a repeatable local ledger and keeps the final #12743 closeout focused on the missing provider-console fields.
The Architectural Reality
ai/daemons/orchestrator/scheduling/memorySummaryBackfill.mjs emits pending-memory-minisummary:<n> reasons that appear in orchestrator logs.
ai/services/memory-core/MemoryService.mjs builds miniSummary prompts from stored prompt/response content, so cost estimates need aggregate input-size statistics.
- The correct repo home for one-shot incident diagnostics is
ai/scripts/diagnostics/, matching existing scripts such as check-retired-primitives.mjs and review-cost-meter.mjs.
- Unit coverage belongs under
test/playwright/unit/ai/scripts/diagnostics/, matching existing diagnostics-script specs.
The Fix
Add a local diagnostics command:
ai/scripts/diagnostics/gemini-incident-cost-ledger.mjs
npm run ai:gemini-incident-cost-ledger -- --log <orchestrator.log> ...
- A focused Playwright unit spec using synthetic logs only.
The script should:
- Accept one or more orchestrator log paths.
- Filter by optional ISO start/end window.
- Count miniSummary backfill starts, completions, pending deferrals, active-task deferrals, and pending-start sums.
- Accept aggregate private-content-safe input character statistics such as mean/p99/max.
- Compute low/base/high sanity estimates from configurable chars/token, input price, output price, and output-token assumptions.
- Optionally compare estimate bands with an operator-supplied billing cost.
- Emit both human-readable output and JSON.
Contract Ledger Matrix
| Target Surface |
Source of Authority |
Proposed Behavior |
Fallback |
Docs |
Evidence |
| Diagnostics script |
#12743 ledger needs + orchestrator log format |
Produce repeatable local miniSummary backfill counts and cost sanity bands |
If billing fields are missing, print residual/authority caveat instead of closure claim |
CLI usage / PR body |
Unit spec + real incident-window run |
| Package script |
package.json script registry |
Expose the diagnostic as ai:gemini-incident-cost-ledger |
Direct node ai/scripts/diagnostics/... invocation |
package.json |
npm-script smoke run |
| Privacy boundary |
Memory Core content sensitivity |
Accept aggregate length stats only; never print prompt/response text |
Caller can omit stats and get counts-only output |
Script JSDoc / PR body |
Unit spec uses synthetic log content only |
Decision Record impact
none. This is incident-forensics tooling, aligned with the local diagnostics script pattern. It does not change provider routing, pricing policy, or AiConfig defaults.
Acceptance Criteria
Out of Scope
- Closing #12743.
- Pulling Cloud Billing data automatically.
- Sampling raw Memory Core prompt/response content.
- Changing provider defaults or miniSummary backfill scheduling.
Avoided Traps
- Do not use the diagnostic's public-pricing estimate as final billing proof.
- Do not copy private memory text into the issue, PR, or command output.
- Do not make this a daemon or background worker; it is an operator/agent-run diagnostic.
Related
Parent forensic ticket: #12743
Parent cost-safety epic: #12740
Related: #12742, #12746, #12748
Origin Session ID: e8f07ef9-ef7e-4815-8ff4-7abe13720621
Handoff Retrieval Hint: Gemini incident cost ledger miniSummary backfill log parser token math
Context
#12743 needs final Cloud Billing / service-metrics authority before it can be closed, but the local side of the reconciliation was still reconstructed manually from orchestrator logs and private-content-safe Memory Core length samples.
This ticket captures the narrow implementation leaf: add a reproducible local diagnostic that parses miniSummary backfill logs and computes public-pricing sanity bands from aggregate length statistics, without printing raw Memory Core prompt/response content.
Live latest-open sweep: checked latest 20 open issues at 2026-06-08T11:53:22Z; no equivalent diagnostic-script leaf found. Closest current issue is #12743, which owns the broader billing/token reconciliation and must remain open until Cloud Billing authority lands.
Semantic duplicate sweep: used non-synthesis
query_documents(type='ticket')forGemini incident cost ledger diagnostic script local orchestrator logsbecauseask_knowledge_basesynthesis is part of the active provider-routing/cost-safety incident surface. Results surfaced older/non-equivalent incident and telemetry tickets, not a narrow local ledger diagnostic leaf.Exact sweep:
rg -n "Gemini incident cost ledger|cost ledger diagnostic|miniSummary backfill.*ledger|billing.*token.*ledger|orchestrator.*cost ledger" resources/content/issues resources/content/archive/issues resources/content/discussionsreturned no matches.The Problem
The team already has a strong timing/source lead for the 2026-06-08 Gemini spike, but hand-counted log/math evidence is fragile:
A small diagnostic script gives future agents a repeatable local ledger and keeps the final #12743 closeout focused on the missing provider-console fields.
The Architectural Reality
ai/daemons/orchestrator/scheduling/memorySummaryBackfill.mjsemitspending-memory-minisummary:<n>reasons that appear in orchestrator logs.ai/services/memory-core/MemoryService.mjsbuilds miniSummary prompts from stored prompt/response content, so cost estimates need aggregate input-size statistics.ai/scripts/diagnostics/, matching existing scripts such ascheck-retired-primitives.mjsandreview-cost-meter.mjs.test/playwright/unit/ai/scripts/diagnostics/, matching existing diagnostics-script specs.The Fix
Add a local diagnostics command:
ai/scripts/diagnostics/gemini-incident-cost-ledger.mjsnpm run ai:gemini-incident-cost-ledger -- --log <orchestrator.log> ...The script should:
Contract Ledger Matrix
package.jsonscript registryai:gemini-incident-cost-ledgernode ai/scripts/diagnostics/...invocationpackage.jsonDecision Record impact
none. This is incident-forensics tooling, aligned with the local diagnostics script pattern. It does not change provider routing, pricing policy, or AiConfig defaults.
Acceptance Criteria
ai/scripts/diagnostics/parses miniSummary backfill log events from one or more orchestrator logs.package.jsonexposes the script via anai:*command.Out of Scope
Avoided Traps
Related
Parent forensic ticket: #12743 Parent cost-safety epic: #12740 Related: #12742, #12746, #12748
Origin Session ID: e8f07ef9-ef7e-4815-8ff4-7abe13720621
Handoff Retrieval Hint:
Gemini incident cost ledger miniSummary backfill log parser token math