avoid subagent token share overflow · Entire
avoid subagent token share overflow
a033c20·
peyton-alt·3w ago·2 files·+27 added/-1 removed
Sessions
5e8f1bad75adView transcript
Changes
2
cmd/entire/cli
Msessions_tokens.go+8/-1
Msessions_test.go+19
300 unmodified lines
301
302
303
304
304
305
306
307
29 unmodified lines
337
338
339
340
341
342
343
344
345
346
347
348
349
300 unmodified lines
Signals: []string{"api_call_count"},
},
}
if signals.Tokens != nil && signals.Tokens.SubagentTotal > 0 && signals.Tokens.SubagentTotal*100 >= signals.Tokens.Total*10 {
if signals.Tokens != nil && tokenShareAtLeastOneTenth(signals.Tokens.SubagentTotal, signals.Tokens.Total) {
recs = append(recs, sessionTokensRecommendation{
ID: "subagent-heavy",
Severity: "medium",
29 unmodified lines
return recs
}
func tokenShareAtLeastOneTenth(part, total int) bool {
if part <= 0 || total <= 0 {
return false
}
return part >= (total-1)/10+1
}
func tokenPercent(value, total int) float64 {
if total <= 0 {
return 0
Mcmd/entire/cli/session_tokens.go+8/-1
1046 unmodified lines
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1046 unmodified lines
}
}
func TestRecommendationRulesSubagentHeavyAvoidsOverflow(t *testing.T) {
t.Parallel()
maxInt := int(^uint(0) >> 1)
recs := recommendationRules(tokenRecommendationSignals{
Tokens: &sessionTokensUsage{
Total: maxInt,
SubagentTotal: maxInt,
},
})
for _, rec := range recs {
if rec.ID == "subagent-heavy" {
return
}
}
t.Fatalf("expected subagent-heavy recommendation, got %+v", recs)
}
func TestTokensCmd_JSONOutputReportsLimitations(t *testing.T) {
setupStopTestRepo(t)