Files
Matt Van Horn 6507c56597 fix: normalize Posit Assistant inferred cache writes (#1489)
Posit Assistant persists all model usage in an Anthropic-shaped set of token
buckets, including a `cacheWriteTokens` field. For GLM, Gemma, and Kimi
records, the observed files put the uncached prompt remainder in
`cacheWriteTokens` while leaving `inputTokens` at zero. Those model families
have no separately billed cache-write category in the pricing catalog, so
Agentsview priced that remainder as cache creation instead of ordinary input.

This extends the Posit Assistant token-normalization path to classify the
persisted buckets by model family before emitting Agentsview's snake-case
token fields. For recognized GLM, Gemma, and Kimi identities, the persisted
cache-write remainder is folded into uncached input. Claude records keep real
cache-write semantics, and missing or unrecognized model identities preserve
Posit Assistant's original buckets unchanged. Full context remains the sum of
the persisted input, cache-read, and cache-write fields in every case.

Because existing archives were already stored with the old accounting, the data
version moves 90 → 91 so those rows are re-parsed through the normal
non-destructive resync path.

**Tests**

- Table-driven parser tests over representative GLM, Gemma, and Kimi model IDs
  assert the inferred cache-write remainder is added to uncached input, and
  that Claude and unrecognized identities are left untouched.
- A data-version test pins 91 for the Posit Assistant cache accounting; the
  previous exact-equality assertion on 90 is relaxed to a boundary check so it
  no longer breaks on every subsequent bump.
- `docs/internal/session-format-sources.md` records the reverification against
  the samples in #1466.

Closes #1466

AI was used for assistance.


Co-authored-by: Matt Van Horn <mvanhorn@users.noreply.github.com>
2026-08-23 20:01:58 +02:00
..