The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
refactor(traces): clamp context widths with min (#862)
kyle-elliott-asymptotec3b2bf1518a7
diff --git a/cli/beacon/internal/endpoint/dashboard/trace_page_bounds_test.go b/cli/beacon/internal/endpoint/dashboard/trace_page_bounds_test.goindex e8fa8436..790ded66 100644--- a/cli/beacon/internal/endpoint/dashboard/trace_page_bounds_test.go+++ b/cli/beacon/internal/endpoint/dashboard/trace_page_bounds_test.go@@ -2,11 +2,12 @@ package dashboardimport ("encoding/json"- "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema""net/http""net/http/httptest""strconv""testing"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema")func TestTraceListLargePageIsEmpty(t *testing.T) {@@ -28,7 +29,7 @@ func TestTraceListLargePageIsEmpty(t *testing.T) {rec := httptest.NewRecorder()handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/traces?limit=10&page="+strconv.Itoa(page), nil))if rec.Code != http.StatusOK {- t.Fatalf("page%d status%d: %s", page, rec.Code, rec.Body.String())+ t.Fatalf("page %d: status %d: %s", page, rec.Code, rec.Body.String())}var got TraceListResultV1if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {@@ -39,7 +40,7 @@ func TestTraceListLargePageIsEmpty(t *testing.T) {want = 1}if got.Page != page || got.Limit != 10 || got.Returned != want || got.TotalMatched != 1 || len(got.Traces) != want || got.Truncated {- t.Fatalf("page%d: %+v", page, got)+ t.Fatalf("page %d: %+v", page, got)}}})@@ -60,10 +61,10 @@ func TestTraceWindowLargeContextDoesNotOverflow(t *testing.T) {for _, width := range []int{1, int(^uint(0) >> 1)} {got, found, err := ShowTrace(path, "session:claude_code:window-control", TraceQuery{AroundEvent: 1, Before: width, After: width})if err != nil || !found {- t.Fatalf("show: found%v err%v", found, err)+ t.Fatalf("show: found %v, err %v", found, err)}if len(got.Events) != 1 || got.Range.ReturnedEvents != 1 || got.Range.Offset != 1 {- t.Fatalf("width%d: %+v", width, got)+ t.Fatalf("width %d: %+v", width, got)}}})diff --git a/cli/beacon/internal/endpoint/dashboard/traces.go b/cli/beacon/internal/endpoint/dashboard/traces.goindex 9750e7ee..d3b998fa 100644--- a/cli/beacon/internal/endpoint/dashboard/traces.go+++ b/cli/beacon/internal/endpoint/dashboard/traces.go@@ -466,14 +466,7 @@ func traceRange(query TraceQuery, total int) (int, int) {if offset < 1 {offset = 1}- // Bound each side to the available trace before adding them. Context- // widths are user supplied and their sum can otherwise overflow.- limit = 1- if before >= total || after >= total || before >= total-1-after {- limit = total- } else {- limit += before + after- }+ limit = min(before, total) + 1 + min(after, total)}if total == 0 {return 1, 0