fix(agent-loop): fail closed on invalid parallel scheduling

This commit is contained in:
Dudu-0223
2026-07-13 17:31:01 +08:00
parent 50f0d3a299
commit ca2dd34291
4 changed files with 44 additions and 1 deletions

View File

@@ -971,7 +971,8 @@ export class ToolRegistry extends Service {
const tool = this.get(exec.name, exec.agent)
if (!tool?.isConcurrencySafe) return { kind: 'exclusive' }
try {
return tool.isConcurrencySafe(exec.arguments) ? { kind: 'parallel' } : { kind: 'exclusive' }
const concurrencySafe: unknown = tool.isConcurrencySafe(exec.arguments)
return concurrencySafe === true ? { kind: 'parallel' } : { kind: 'exclusive' }
} catch {
return { kind: 'exclusive' }
}

View File

@@ -99,6 +99,19 @@ describe('ToolRegistry.executionMode', () => {
expect(ctx.tools.executionMode(exec('thrower', {}))).toEqual({ kind: 'exclusive' })
})
it('a truthy non-boolean classifier result fails closed to exclusive (raw definition)', async () => {
const ctx = await setup()
const raw = {
name: 'truthy',
description: 'classifier returns a truthy string',
parameters: { type: 'object', properties: {} },
isConcurrencySafe() { return 'yes' },
async execute() { return [] },
} as unknown as ToolDefinition
ctx.tools.register(raw)
expect(ctx.tools.executionMode(exec('truthy', {}))).toEqual({ kind: 'exclusive' })
})
it('a raw definition (no defineTool) receives the raw parsed value', async () => {
const ctx = await setup()
let seen: unknown