Commit 51e533d
committed
🤖 fix: correct context usage display for multi-step tool calls
The Context Usage UI was showing inflated cachedInputTokens for plan
messages with multi-step tool calls (e.g., ~150k instead of ~50k).
Root cause: contextUsage was falling back to cumulative usage (summed
across all steps) when contextUsage was undefined. For multi-step
requests, cachedInputTokens gets summed because each step reads from
cache, but the actual context window only sees one step's worth.
Changes:
- Backend: Refactor getStreamMetadata() to fetch totalUsage (for costs)
and contextUsage (last step, for context window) separately from AI SDK
- Backend: Add contextProviderMetadata from streamResult.providerMetadata
for accurate cache creation token display
- Frontend: Remove fallback from contextUsage to usage - only use
contextUsage for context window display
The fix ensures context window shows last step's inputTokens (actual
context size) while cost calculation still uses cumulative totals.1 parent 4eef087 commit 51e533d
File tree
5 files changed
+48
-21
lines changed- src
- browser
- stores
- stories
- common/orpc/schemas
- node/services
5 files changed
+48
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
486 | 486 | | |
487 | 487 | | |
488 | 488 | | |
489 | | - | |
| 489 | + | |
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| 202 | + | |
202 | 203 | | |
203 | 204 | | |
204 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
79 | 80 | | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
338 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
339 | 347 | | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
346 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
347 | 365 | | |
348 | | - | |
| 366 | + | |
349 | 367 | | |
350 | 368 | | |
351 | 369 | | |
352 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
353 | 373 | | |
354 | 374 | | |
355 | 375 | | |
| |||
1071 | 1091 | | |
1072 | 1092 | | |
1073 | 1093 | | |
1074 | | - | |
1075 | | - | |
1076 | | - | |
1077 | | - | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
1078 | 1106 | | |
1079 | 1107 | | |
1080 | | - | |
1081 | | - | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | 1108 | | |
1086 | 1109 | | |
1087 | 1110 | | |
| |||
1090 | 1113 | | |
1091 | 1114 | | |
1092 | 1115 | | |
1093 | | - | |
| 1116 | + | |
1094 | 1117 | | |
1095 | 1118 | | |
1096 | 1119 | | |
| |||
0 commit comments