perf(host): scan the own-suffix for a subagent descriptor without copying
`hasSubagentDescriptor` sliced the whole own-suffix events array on every Agent-bound RPC — including each `session.prompt` and `sessions.models` call on long transcripts — and `ensureSession` rescans the same suffix after creation. Replace the slice-then-some with an indexed loop from the seed boundary, so the classification is a plain O(suffix) read with no allocation.
This commit is contained in:
1 file changed
+8
-2
@@ -1017,8 +1017,14 @@ export function createApiProxy(ctx: Context, defaults: ApiProxyDefaults): ApiPro
|
||||
|
||||
/** Whether the session's own suffix carries the durable subagent discriminator. */
|
||||
function hasSubagentDescriptor(session: Pick<Session, 'events' | 'header'>): boolean {
|
||||
const ownStart = session.header.seedLength ?? 0
|
||||
return session.events.slice(ownStart).some(event => event.type === 'subagent/descriptor')
|
||||
const events = session.events
|
||||
// Indexed scan from the own-suffix start: slicing copies the whole suffix
|
||||
// on every Agent-bound RPC, including each `session.prompt` on long
|
||||
// transcripts.
|
||||
for (let index = session.header.seedLength ?? 0; index < events.length; index += 1) {
|
||||
if (events[index]?.type === 'subagent/descriptor') return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user