This commit is contained in:
Dmitry R. 2026-09-01 06:53:45 -04:00 committed by GitHub
commit 3cc2da592c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 4 deletions

View file

@ -171,6 +171,25 @@ describe("RequestLogsPanel", () => {
expect(within(row("req-llm") as HTMLElement).getByText("3")).toBeInTheDocument();
});
it("prefers a caller-sent call over an auto-router classifier sub-call as the representative", async () => {
const classifierSubCall: Partial<LogEntry> = {
request_id: "req-classify",
session_id: "sess-1",
session_total_count: 2,
metadata: { internal_call_origin: "autorouter_classifier" },
};
const callerSentCall: Partial<LogEntry> = {
request_id: "req-main",
session_id: "sess-1",
session_total_count: 2,
};
respondWith([logEntry(classifierSubCall), logEntry(callerSentCall)]);
renderPanel();
await waitFor(() => expect(row("req-main")).not.toBeNull());
expect(row("req-classify")).toBeNull();
});
it("leaves single-call rows untouched", async () => {
respondWith([
logEntry({ request_id: "req-solo-a", session_id: "sess-a", session_total_count: 1 }),

View file

@ -175,13 +175,18 @@ export default function RequestLogsPanel({ accessToken, token, userRole, userID,
return acc;
}, {});
const sessionRepresentativeMap = new Map<string, { requestId: string; isMcp: boolean }>();
// Lower rank wins: caller-sent non-MCP call, then MCP call, then internal
// sub-calls (metadata.internal_call_origin, e.g. auto-router classifier).
const representativeRank = (log: LogEntry): number =>
(log.metadata?.internal_call_origin ? 2 : 0) + (MCP_CALL_TYPES.includes(log.call_type) ? 1 : 0);
const sessionRepresentativeMap = new Map<string, { requestId: string; rank: number }>();
for (const log of searchedLogs) {
if (!log.session_id || (log.session_total_count || 1) <= 1) continue;
const isMcp = MCP_CALL_TYPES.includes(log.call_type);
const rank = representativeRank(log);
const existing = sessionRepresentativeMap.get(log.session_id);
if (!existing || (existing.isMcp && !isMcp)) {
sessionRepresentativeMap.set(log.session_id, { requestId: log.request_id, isMcp });
if (!existing || rank < existing.rank) {
sessionRepresentativeMap.set(log.session_id, { requestId: log.request_id, rank });
}
}