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:
YeonGyu-Kim
2026-03-11 21:45:39 +09:00
parent d4232c9eac
commit cc1c23032f
2 changed files with 54 additions and 2 deletions
@@ -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(