Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(v4): sort deprecated API callers by recency (#16755)

Hassieb Pakzad4fa96117a622
diff --git a/web/src/features/v4-migration/hooks/useV4MigrationData.clienttest.ts b/web/src/features/v4-migration/hooks/useV4MigrationData.clienttest.ts
index 0e7c2fa219..b355259819 100644
--- a/web/src/features/v4-migration/hooks/useV4MigrationData.clienttest.ts
+++ b/web/src/features/v4-migration/hooks/useV4MigrationData.clienttest.ts
@@ -316,6 +316,54 @@ describe("project v4 migration data", () => {
expect(result.current.apis).toEqual({ status: "loaded", count: 0 });
expect(result.current.apiUsage).toHaveLength(1);
});
+
+ it("orders API routes and their callers by most recent usage", () => {
+ mocks.legacyApiUsageSummaryUseQuery.mockReturnValue(
+ loadedQuery([
+ {
+ entrypoint: "publicapi: GET /api/public/sessions",
+ count: 2,
+ lastSeen: "2026-07-23T09:00:00Z",
+ callers: [
+ {
+ userAgent: "recent-sessions-caller",
+ count: 1,
+ lastSeen: "2026-07-23T09:00:00Z",
+ },
+ ],
+ },
+ {
+ entrypoint: "publicapi: GET /api/public/traces",
+ count: 11,
+ lastSeen: "2026-07-23T11:00:00Z",
+ callers: [
+ {
+ userAgent: "frequent-older-caller",
+ count: 10,
+ lastSeen: "2026-07-23T10:00:00Z",
+ },
+ {
+ userAgent: "recent-caller",
+ count: 1,
+ lastSeen: "2026-07-23T11:00:00Z",
+ },
+ ],
+ },
+ ]),
+ );
+
+ const { result } = renderHook(() =>
+ useProjectV4MigrationData({ projectId: "project-1", enabled: true }),
+ );
+
+ expect(result.current.apiUsage.map((row) => row.endpoint)).toEqual([
+ "GET /api/public/traces",
+ "GET /api/public/sessions",
+ ]);
+ expect(
+ result.current.apiUsage[0]?.callers.map((caller) => caller.userAgent),
+ ).toEqual(["recent-caller", "frequent-older-caller"]);
+ });
});
describe("migration actions", () => {
diff --git a/web/src/features/v4-migration/hooks/useV4MigrationData.ts b/web/src/features/v4-migration/hooks/useV4MigrationData.ts
index 729e7b93f9..cd11516428 100644
--- a/web/src/features/v4-migration/hooks/useV4MigrationData.ts
+++ b/web/src/features/v4-migration/hooks/useV4MigrationData.ts
@@ -233,12 +233,14 @@ export function useProjectV4MigrationData(params: {
endpoint: normalizeLegacyApiEntrypoint(row.entrypoint),
count: row.count,
lastSeen: row.lastSeen,
- callers: row.callers ?? [
- {
- count: row.count,
- lastSeen: row.lastSeen,
- },
- ],
+ callers: Array.from(
+ row.callers ?? [
+ {
+ count: row.count,
+ lastSeen: row.lastSeen,
+ },
+ ],
+ ).sort((left, right) => right.lastSeen.localeCompare(left.lastSeen)),
}))
.sort(
(left, right) =>