pi-cache-optimizer 2.6.11 → 2.6.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.ts +12 -0
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -6481,6 +6481,18 @@ export default function (pi: ExtensionAPI) {
6481
6481
  const adapter = selectAdapterForAssistantMessage(event.message, ctx.model);
6482
6482
  if (!adapter) return;
6483
6483
 
6484
+ // Skip stats for error/aborted messages (network retries, user aborts).
6485
+ // Pi's auto-retry emits message_end for the failed attempt before
6486
+ // removing it and retrying. The error message carries zero-usage fields
6487
+ // ({ input: 0, cacheRead: 0, cacheWrite: 0 }) that normalizeUsage
6488
+ // returns as a valid (non-undefined) snapshot, which would inflate
6489
+ // totalRequests and skew cache hit-rate accuracy. The final successful
6490
+ // response is emitted as a separate message_end with real usage data.
6491
+ const msgRecord = asRecord(event.message);
6492
+ if (msgRecord?.stopReason === "error" || msgRecord?.stopReason === "aborted") {
6493
+ return;
6494
+ }
6495
+
6484
6496
  const usage = adapter.normalizeUsage(event.message);
6485
6497
 
6486
6498
  // Completed message metadata is request-local and authoritative for virtual
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cache-optimizer",
3
- "version": "2.6.11",
3
+ "version": "2.6.12",
4
4
  "description": "Improve Pi prompt/KV cache hit rates with stable prompts, OpenAI-compatible cache keys, proxy compat warnings, and footer cache stats.",
5
5
  "keywords": [
6
6
  "pi-package",