refactor(agent): simplify inbox-driven turn admission

This commit is contained in:
_Kerman
2026-08-02 00:27:37 +08:00
parent d38c8bfaf3
commit dbdf270af0
104 changed files with 550 additions and 511 deletions

View File

@@ -181,9 +181,7 @@ describe('llm-retry invariants', () => {
const closedTurn = openStep(ctx, 'retry-invariant-closed-turn')
closedTurn.append('step/end', { turn: 1, step: 1 })
closedTurn.append('turn/end', {
turn: 1,
reason: { kind: 'aborted', reason: { kind: 'user' } },
closedTurn.append('turn/end', { turn: 1, step: 1, reason: { kind: 'aborted', reason: { kind: 'user' } },
})
expect(() => {
closedTurn.append('llm/retry', { turn: 1, step: 1, ...normal })
@@ -230,7 +228,7 @@ describe('llm-retry invariants', () => {
appendRetryTurn(missingEnd, 2)
const nonFailureEnd = ctx.sessions.create(SessionId('retry-invariant-non-failure-end'))
nonFailureEnd.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
nonFailureEnd.append('turn/end', { turn: 1, step: 0, reason: { kind: 'completed' } })
nonFailureEnd.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'idle context' }],
source: { kind: 'user' },
@@ -238,9 +236,7 @@ describe('llm-retry invariants', () => {
appendRetryTurn(nonFailureEnd, 2)
const missingStart = ctx.sessions.create(SessionId('retry-invariant-missing-start'))
missingStart.append('turn/end', {
turn: 1,
reason: { kind: 'error', error: failure },
missingStart.append('turn/end', { turn: 1, step: 0, reason: { kind: 'error', error: failure },
})
appendRetryTurn(missingStart, 2)

View File

@@ -49,12 +49,8 @@ describe.each(['jsonl', 'sqlite'] as const)('%s retry-event persistence', (kind)
failure: { message: 'provider busy', code: 'RATE_LIMIT', status: 429 },
})
session.append('step/end', { turn: 1, step: 1 })
session.append('turn/end', {
turn: 1,
reason: {
kind: 'error',
error: { message: 'provider busy', code: 'RATE_LIMIT', status: 429 },
},
session.append('turn/end', { turn: 1, step: 1, reason: { kind: 'error', error: { message: 'provider busy', code: 'RATE_LIMIT', status: 429 },
},
})
expect(session.deriveMessages()).toEqual([])

View File

@@ -337,7 +337,7 @@ describe('provider-routed retry policy', () => {
expect(agent.session.events.filter(event => event.type === 'llm/retry')).toHaveLength(2)
expect(agent.session.events.at(-1)).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'error', error: { message: 'busy three', code: 'SERVER' } } },
data: { step: 1, reason: { kind: 'error', error: { message: 'busy three', code: 'SERVER' } } },
})
})
@@ -450,7 +450,7 @@ describe('provider-routed retry policy', () => {
expect(agent.session.events.some(event => event.type === 'llm/retry')).toBe(false)
expect(agent.session.events.at(-1)).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'error', error: { code: 'NO_ADAPTER' } } },
data: { step: 1, reason: { kind: 'error', error: { code: 'NO_ADAPTER' } } },
})
})

View File

@@ -193,7 +193,7 @@ describe('bounded retry through the real DeepSeek HTTP/SSE adapter', () => {
expect(agent.session.events.some(event => event.type === 'llm/retry')).toBe(false)
expect(agent.session.events.at(-1)).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'error', error: { code: 'STREAM_CLOSED' } } },
data: { step: 1, reason: { kind: 'error', error: { code: 'STREAM_CLOSED' } } },
})
})
@@ -235,7 +235,7 @@ describe('bounded retry through the real DeepSeek HTTP/SSE adapter', () => {
expect(agent.session.events.filter(event => event.type === 'llm/retry')).toHaveLength(2)
expect(agent.session.events.at(-1)).toMatchObject({
type: 'turn/end',
data: { reason: { kind: 'error', error: { code: 'TRANSPORT' } } },
data: { step: 1, reason: { kind: 'error', error: { code: 'TRANSPORT' } } },
})
})
})