Count sync subagent spawns against descendant limits
This commit is contained in:
@@ -27,15 +27,23 @@ export async function executeSyncTask(
|
||||
const toastManager = getTaskToastManager()
|
||||
let taskId: string | undefined
|
||||
let syncSessionID: string | undefined
|
||||
let spawnReservation:
|
||||
| Awaited<ReturnType<ExecutorContext["manager"]["reserveSubagentSpawn"]>>
|
||||
| undefined
|
||||
|
||||
try {
|
||||
const spawnContext = typeof manager?.assertCanSpawn === "function"
|
||||
? await manager.assertCanSpawn(parentContext.sessionID)
|
||||
: {
|
||||
rootSessionID: parentContext.sessionID,
|
||||
parentDepth: 0,
|
||||
childDepth: 1,
|
||||
}
|
||||
if (typeof manager?.reserveSubagentSpawn === "function") {
|
||||
spawnReservation = await manager.reserveSubagentSpawn(parentContext.sessionID)
|
||||
}
|
||||
|
||||
const spawnContext = spawnReservation?.spawnContext
|
||||
?? (typeof manager?.assertCanSpawn === "function"
|
||||
? await manager.assertCanSpawn(parentContext.sessionID)
|
||||
: {
|
||||
rootSessionID: parentContext.sessionID,
|
||||
parentDepth: 0,
|
||||
childDepth: 1,
|
||||
})
|
||||
|
||||
const createSessionResult = await deps.createSyncSession(client, {
|
||||
parentSessionID: parentContext.sessionID,
|
||||
@@ -45,10 +53,12 @@ export async function executeSyncTask(
|
||||
})
|
||||
|
||||
if (!createSessionResult.ok) {
|
||||
spawnReservation?.rollback()
|
||||
return createSessionResult.error
|
||||
}
|
||||
|
||||
const sessionID = createSessionResult.sessionID
|
||||
spawnReservation?.commit()
|
||||
syncSessionID = sessionID
|
||||
subagentSessions.add(sessionID)
|
||||
syncSubagentSessions.add(sessionID)
|
||||
@@ -156,6 +166,7 @@ session_id: ${sessionID}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
spawnReservation?.rollback()
|
||||
return formatDetailedError(error, {
|
||||
operation: "Execute task",
|
||||
args,
|
||||
|
||||
Reference in New Issue
Block a user