Skip to content

Commit aa24dc9

Browse files
committed
perf: avoid redundant isSubagentSession API calls
1 parent 54e981e commit aa24dc9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/hooks.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,12 @@ export function createChatParamsHandler(
7575
// Track the last seen session ID for fetch wrapper correlation
7676
state.lastSeenSessionId = sessionId
7777

78-
// Check if this is a subagent session and track it to skip fetch wrapper processing
79-
if (!state.subagentSessions.has(sessionId)) {
78+
// Check if this is a subagent session
79+
if (!state.checkedSessions.has(sessionId)) {
80+
state.checkedSessions.add(sessionId)
8081
const isSubagent = await isSubagentSession(client, sessionId)
8182
if (isSubagent) {
8283
state.subagentSessions.add(sessionId)
83-
logger.info("chat.params", "Detected subagent session, will skip DCP processing", {
84-
sessionId: sessionId.substring(0, 8)
85-
})
8684
}
8785
}
8886

lib/state.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface PluginState {
2222
googleToolCallMapping: Map<string, Map<string, string>>
2323
/** Set of session IDs that have been restored from disk */
2424
restoredSessions: Set<string>
25+
/** Set of session IDs we've already checked for subagent status (to avoid redundant API calls) */
26+
checkedSessions: Set<string>
2527
/** Set of session IDs that are subagents (have a parentID) - used to skip fetch wrapper processing */
2628
subagentSessions: Set<string>
2729
/** The most recent session ID seen in chat.params - used to correlate fetch requests */
@@ -49,6 +51,7 @@ export function createPluginState(): PluginState {
4951
model: new Map(),
5052
googleToolCallMapping: new Map(),
5153
restoredSessions: new Set(),
54+
checkedSessions: new Set(),
5255
subagentSessions: new Set(),
5356
lastSeenSessionId: null,
5457
}

0 commit comments

Comments
 (0)