Merge pull request #843 from samcharles93/feat/840-repeated-successful-tool-calls-are-never-collapsed-into-a-co

Repeated successful tool calls are never collapsed into a counted entry (archie)
This commit is contained in:
sam authored and GitHub committed 2026-09-17 21:23:52 +10:00
commit 7a1f1906fa
4 files changed
+68 -8

No files matched your search

@@ -19,6 +19,8 @@ func TestComposeStateStoreClientRequiresTarget(t *testing.T) {
}
func TestComposeStateStoreClientNonLoopbackFailsClosed(t *testing.T) {
// Keep this test independent of credentials inherited from the test runner.
t.Setenv("STATE_STORE_TOKEN", "")
for _, tt := range []struct {
name string
target string
@@ -73,6 +75,8 @@ func TestOpenStateStoreAdapterRequiresTarget(t *testing.T) {
}
func TestOpenStateStoreAdapterRemoteFailsClosed(t *testing.T) {
// Keep this test independent of credentials inherited from the test runner.
t.Setenv("STATE_STORE_TOKEN", "")
b := newBootstrap()
b.secrets = &secret.Registry{}
b.cfg.Services.State = config.ServiceConnection{Target: "0.0.0.0:9090"}
+36
View File
@@ -185,6 +185,42 @@ func TestLiveReplySkipsUnchangedRenders(t *testing.T) {
}
}
func TestLiveReplyCollapsesRepeatedSuccessfulEquivalentToolCalls(t *testing.T) {
live, calls := newTestLiveReply(t, true)
for range 14 {
live.ToolCall(toolEvent("grep", "/src/a.go:12:match\n/src/b.go:40:match", ""))
}
live.finalize(context.Background(), "done")
got := (*calls)[len(*calls)-1].body()
want := "🔧 grep — done ×14\n\n2 matches\n\ndone"
if got != want {
t.Fatalf("repeated successful grep calls rendered as:\n%s\nwant:\n%s", got, want)
}
if strings.Count(got, "🔧 grep") != 1 {
t.Fatalf("repeated successful grep calls should occupy one entry, got %d:\n%s", strings.Count(got, "🔧 grep"), got)
}
}
func TestLiveReplyDoesNotCollapseSuccessfulCallsWithDifferentResults(t *testing.T) {
live, calls := newTestLiveReply(t, true)
live.ToolCall(toolEvent("grep", "/src/a.go:12:match\n/src/b.go:40:match", ""))
live.ToolCall(toolEvent("grep", "/src/a.go:12:match\n/src/b.go:40:match", ""))
live.ToolCall(toolEvent("grep", "/src/a.go:12:match", ""))
live.ToolCall(toolEvent("rg", "/src/a.go:12:match\n/src/b.go:40:match", ""))
live.finalize(context.Background(), "done")
got := (*calls)[len(*calls)-1].body()
if strings.Count(got, "🔧 ") != 3 {
t.Fatalf("successful calls with different tools or summaries were collapsed:\n%s", got)
}
if !strings.Contains(got, "🔧 grep — done ×2") || strings.Contains(got, "×3") {
t.Fatalf("only equivalent successful calls should be counted together:\n%s", got)
}
}
func TestLiveReplySnapshotsToolCallVisibility(t *testing.T) {
live, calls := newTestLiveReply(t, true)
live.g.SetShowToolCalls(false)
+9 -8
View File
@@ -37,13 +37,11 @@ func RenderToolCall(e ToolCallEvent) string {
return toolProgressBlock(e.Name, "done", toolPreview(e.Name, e.Output))
}
// FailureKey identifies equivalent failures for channel adapters that collapse
// retries. Legacy aggregate-output-limit errors deliberately share one key
// across tool names: they are one obsolete turn-level condition, not five
// independently useful failures.
// FailureKey identifies equivalent failures for channel adapters that
// collapse retries. (A function rather than a method because ToolCallEvent
// is a messaging alias: see chat_contract_aliases.go.)
// FailureKey identifies equivalent tool calls for channel adapters that
// collapse repeated activity. Legacy aggregate-output-limit errors deliberately
// share one key across tool names: they are one obsolete turn-level condition,
// not five independently useful failures. (A function rather than a method
// because ToolCallEvent is a messaging alias: see chat_contract_aliases.go.)
func FailureKey(e ToolCallEvent) string {
if _, ok := legacyTurnBudgetLimit(e.Err); ok {
return "legacy-turn-output-limit"
@@ -51,7 +49,10 @@ func FailureKey(e ToolCallEvent) string {
if line := cleanToolError(e.Name, e.Err); line != "" {
return strings.TrimSpace(e.Name) + "\x00" + line
}
return ""
// Successful calls are also eligible for aggregation. Use the same
// compact summary that is shown to the user so equivalent results share a
// key while different result summaries remain distinct.
return "success\x00" + strings.TrimSpace(e.Name) + "\x00" + toolPreview(e.Name, e.Output)
}
func toolProgressBlock(name, status, preview string) string {
+19
View File
@@ -49,6 +49,25 @@ func TestToolCallEventRenderToolCallBoundsOutputAndPreservesFailure(t *testing.T
}
}
func TestToolCallEventSuccessKeysCollapseEquivalentResultsWithoutColliding(t *testing.T) {
equivalent := ToolCallEvent{Name: "grep", Output: "/src/a.go:12:match\n/src/b.go:40:match"}
equivalentCopy := ToolCallEvent{Name: "grep", Output: "/src/a.go:99:different details\n/src/b.go:7:another detail"}
differentSummary := ToolCallEvent{Name: "grep", Output: "/src/a.go:12:match"}
differentTool := ToolCallEvent{Name: "rg", Output: equivalent.Output}
if key := FailureKey(equivalent); key == "" {
t.Fatal("successful tool calls need a non-empty aggregation key")
} else if key != FailureKey(equivalentCopy) {
t.Fatalf("equivalent successful results should share a key: %q vs %q", key, FailureKey(equivalentCopy))
}
if FailureKey(equivalent) == FailureKey(differentSummary) {
t.Fatalf("different successful summaries must not share a key: %q", FailureKey(equivalent))
}
if FailureKey(equivalent) == FailureKey(differentTool) {
t.Fatalf("different successful tools must not share a key: %q", FailureKey(equivalent))
}
}
func TestToolCallEventFailureKeyCollapsesLegacyTurnBudget(t *testing.T) {
first := ToolCallEvent{Name: "read", Err: "tool read: turn budget exceeded (200000 chars)"}
second := ToolCallEvent{Name: "shell", Err: "tool shell: turn budget exceeded (200000 chars)"}