fix(background-agent): handle SDK error response in spawn limit lineage lookup
- Check response.error and !response.data after session.get() to fail closed - Prevents unlimited spawning when SDK returns non-throwing error responses - Added regression tests for SDK error and missing data scenarios
This commit is contained in:
@@ -36,10 +36,18 @@ export async function resolveSubagentSpawnContext(
|
||||
|
||||
let nextParentSessionID: string | undefined
|
||||
try {
|
||||
const session = await client.session.get({
|
||||
const response = await client.session.get({
|
||||
path: { id: currentSessionID },
|
||||
})
|
||||
nextParentSessionID = session.data?.parentID
|
||||
if (response.error) {
|
||||
throw new Error(String(response.error))
|
||||
}
|
||||
|
||||
if (!response.data) {
|
||||
throw new Error("No session data returned")
|
||||
}
|
||||
|
||||
nextParentSessionID = response.data.parentID
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error ? error.message : String(error)
|
||||
throw new Error(
|
||||
|
||||
Reference in New Issue
Block a user