fix(ui): prefer caller-sent requests over internal classifier calls

Extend session representative selection to rank internal sub-calls
(e.g. auto-router classifier calls, marked via
metadata.internal_call_origin) lowest, so caller-sent calls are
preferred over both MCP and internal sub-calls when collapsing
multi-call sessions into a single row.
This commit is contained in:
Dmitry Rubtsov 2026-08-27 22:33:23 +06:00
parent cd63c7e5a7
commit 598729c5f4
No known key found for this signature in database
GPG key ID: E1D60D21325EB8DA
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

@ -166,13 +166,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 });
}
}