refactor(agent): trim obsolete loop surfaces

This commit is contained in:
_Kerman
2026-07-24 21:58:07 +08:00
parent 194b18a32f
commit 009d113e0e
40 changed files with 252 additions and 288 deletions
@@ -50,6 +50,16 @@ function textResponse(text: string): StreamChunk[] {
]
}
function toolResponse(callId: string, name: string): StreamChunk[] {
const id = CallId(callId)
return [
{ type: 'block-start', index: 0, blockType: 'tool-call' },
{ type: 'tool-call-delta', index: 0, id, name, argumentsDelta: '{}' },
{ type: 'block-end', index: 0, block: { type: 'tool-call', id, name, arguments: '{}' } },
{ type: 'finish', reason: { kind: 'tool-calls' } },
]
}
async function harness(
adapter: LlmAdapter,
config: retry.Config = {},
@@ -263,6 +273,43 @@ describe('bounded transient retry policy', () => {
expect(adapter.requests).toHaveLength(4)
})
it('resets the retry budget after a successful tool-call response within the same drain', async () => {
vi.useFakeTimers()
const adapter = new ScriptedAdapter([
new LlmError('first busy', 'SERVER'),
toolResponse('work-1', 'work'),
new LlmError('second busy', 'SERVER'),
textResponse('done'),
])
;({ ctx: context } = await harness(adapter, { maxTransientRetries: 1 }))
context.tools.register(defineContentToolFixture({
name: 'work',
description: 'continue into another model step',
parameters: {},
async execute() {
return [{ type: 'text', text: 'worked' }]
},
}))
const agent = context.agentLoop.create(SessionId('retry-reset-after-success'), {
provider: 'mock',
model: 'mock',
})
const firstRetry = waitForRetry(context, agent, 1)
agent.followup([{ type: 'text', text: 'go' }])
await firstRetry
const secondRetry = waitForRetry(context, agent, 1)
await vi.advanceTimersByTimeAsync(500)
await secondRetry
const idle = waitForIdle(context, agent)
await vi.advanceTimersByTimeAsync(500)
await idle
expect(agent.session.events.filter(event => event.type === 'llm/retry').map(event => event.data.retry))
.toEqual([1, 1])
expect(adapter.requests).toHaveLength(4)
})
it('accepts the zero-delay lower jitter bound', async () => {
vi.useFakeTimers()
const adapter = new ScriptedAdapter([