🩹 fix: surface projections as estimates, not authoritative snapshots

A first-cut projection carries the SDK's windowing but omits instruction/tool
overhead, so rendering it as `isEstimate: false` showed a confident under-count
for snapshot-less branches. Mark projection-sourced views `isEstimate: true` +
`snapshotActive: false` (and drop the snapshot field) so they present as a
better estimate than sumBranch — improved used/window number, estimate framing,
no misleading granular breakdown with ~0 tools. Real snapshots stay
authoritative. (Codex round 3, projection.ts:139.)
This commit is contained in:
Danny Avila 2026-06-16 16:02:17 -04:00
parent 536d2ca46f
commit 0e521390af
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956

View file

@ -249,12 +249,18 @@ export default function useTokenUsage({
* slots in ahead of the estimate when no snapshot exists. Snapshot and
* projection share the render-relevant fields, so they render uniformly. */
let effective: ContextSnapshot | TContextUsageEvent | null = null;
/** A server projection is the SDK's windowing but, in this first cut, omits
* instruction/tool overhead — so it's surfaced as an ESTIMATE (a better one
* than sumBranch), never a false-authoritative number. Real snapshots stay
* authoritative. */
let projected = false;
if (currentActive) {
effective = snapshot;
} else if (branchSnapshot != null) {
effective = branchSnapshot;
} else if (projection != null) {
effective = projection;
projected = true;
}
if (effective != null) {
@ -274,9 +280,9 @@ export default function useTokenUsage({
usedTokens,
maxTokens,
percent: maxTokens > 0 ? Math.min((usedTokens / maxTokens) * 100, 100) : 0,
isEstimate: false,
snapshot: effective as ContextSnapshot,
snapshotActive: true,
isEstimate: projected,
snapshot: projected ? null : (effective as ContextSnapshot),
snapshotActive: !projected,
branchTotals,
branchUsage,
totalUsage,