Skip to content

Commit cd1443b

Browse files
Copilotpelikhan
andauthored
Lower precision in ET rendering: round sub-1000 values to nearest 10
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/421a2320-dc20-44d9-b8a7-f45b05335d6c Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 7122e61 commit cd1443b

4 files changed

Lines changed: 55 additions & 6 deletions

File tree

actions/setup/js/effective_tokens.cjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,22 @@ function computeEffectiveTokens(model, inputTokens, outputTokens, cacheReadToken
186186
/**
187187
* Formats an ET number in a compact, human-readable form.
188188
*
189+
* Effective tokens are estimates, so sub-1000 values are rounded to the nearest 10.
190+
*
189191
* Ranges:
190-
* < 1,000 → exact integer (e.g. "900")
192+
* < 10 → exact integer (e.g. "7")
193+
* 10–999 → rounded to nearest 10 (e.g. "40", "120", "900")
191194
* 1,000–999,999 → Xk with one decimal when non-zero (e.g. "1.2K", "450K")
192195
* >= 1,000,000 → Xm with one decimal when non-zero (e.g. "1.2M", "3M")
193196
*
194197
* @param {number} n - Non-negative ET value (should be rounded before passing)
195198
* @returns {string} Compact string representation
196199
*/
197200
function formatET(n) {
201+
// Round to nearest 10 for values in [10, 1000) — effective tokens are estimates
202+
if (n >= 10 && n < 1000) {
203+
n = Math.round(n / 10) * 10;
204+
}
198205
if (n < 1000) return String(n);
199206
if (n < 1_000_000) return `${(n / 1000).toFixed(1).replace(/\.0$/, "")}K`;
200207
return `${(n / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;

actions/setup/js/effective_tokens.test.cjs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,24 @@ describe("effective_tokens", () => {
302302
});
303303

304304
describe("formatET", () => {
305-
test("returns exact string for values under 1000", () => {
305+
test("returns exact string for values under 10", () => {
306306
expect(formatET(0)).toBe("0");
307307
expect(formatET(1)).toBe("1");
308+
expect(formatET(9)).toBe("9");
309+
});
310+
311+
test("rounds values in [10, 1000) to nearest 10", () => {
312+
expect(formatET(10)).toBe("10");
313+
expect(formatET(14)).toBe("10");
314+
expect(formatET(15)).toBe("20");
315+
expect(formatET(42)).toBe("40");
316+
expect(formatET(123)).toBe("120");
308317
expect(formatET(900)).toBe("900");
309-
expect(formatET(999)).toBe("999");
318+
});
319+
320+
test("rounds values near 1000 up to 1K", () => {
321+
expect(formatET(995)).toBe("1K");
322+
expect(formatET(999)).toBe("1K");
310323
});
311324

312325
test("formats values in the thousands as K", () => {

pkg/cli/health_metrics.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,23 @@ func GroupRunsByWorkflow(runs []WorkflowRun) map[string][]WorkflowRun {
235235
return grouped
236236
}
237237

238-
// formatTokens formats token count in a human-readable format
238+
// formatTokens formats token count in a human-readable format.
239+
// Values in [10, 1000) are rounded to the nearest 10 — token counts are estimates.
239240
func formatTokens(tokens int) string {
240241
if tokens == 0 {
241242
return "-"
242243
}
243-
if tokens < 1000 {
244+
if tokens < 10 {
244245
return strconv.Itoa(tokens)
245246
}
247+
if tokens < 1000 {
248+
// Round to nearest 10 — token counts are estimates
249+
rounded := (tokens + 5) / 10 * 10
250+
if rounded >= 1000 {
251+
return "1K"
252+
}
253+
return strconv.Itoa(rounded)
254+
}
246255
if tokens < 1000000 {
247256
return fmt.Sprintf("%.1fK", float64(tokens)/1000)
248257
}

pkg/cli/health_metrics_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,30 @@ func TestFormatTokens(t *testing.T) {
233233
expected: "-",
234234
},
235235
{
236-
name: "small tokens",
236+
name: "single digit kept exact",
237+
tokens: 7,
238+
expected: "7",
239+
},
240+
{
241+
name: "rounds to nearest 10",
242+
tokens: 42,
243+
expected: "40",
244+
},
245+
{
246+
name: "rounds up to nearest 10",
247+
tokens: 45,
248+
expected: "50",
249+
},
250+
{
251+
name: "multiple of 10 unchanged",
237252
tokens: 500,
238253
expected: "500",
239254
},
255+
{
256+
name: "rounds near 1000 to 1K",
257+
tokens: 999,
258+
expected: "1K",
259+
},
240260
{
241261
name: "thousands",
242262
tokens: 5000,

0 commit comments

Comments
 (0)