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

@@ -29,13 +29,10 @@ function stubAgent(ctx: Context, id: string): { agent: Agent; session: Session }
inbox,
ctx: new Context(),
get status() { return status },
get acceptsNextStep() { return status === 'running' },
send: () => {},
updateInbox: () => 'not-found',
followup: () => {},
steer: () => {},
inject(input) { inbox.append('next-step', input) },
reserveTurnAdmission: () => undefined,
cancel() { status = 'idle' },
whenIdle() { return Promise.resolve() },
}

View File

@@ -994,7 +994,7 @@ describe('same-session goal driving', () => {
orphan.append('turn/start', {
turn: 1,
})
orphan.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
orphan.append('turn/end', { turn: 1, step: 0, reason: { kind: 'completed' } })
const handle = await test.ctx.agents.create({
sessionId: SessionId('goal-session-disposed'),

View File

@@ -41,7 +41,7 @@ function appendRound(session: Session, turn: number, content = renderGoalRoundPr
session.append('user/message', createUserMessage({
content, source,
}), { surfaceOp: 'append' })
session.append('turn/end', { turn, reason: { kind: 'completed' } })
session.append('turn/end', { turn, step: 0, reason: { kind: 'completed' } })
}
async function mount(sessionFirst = false): Promise<{ ctx: Context; session: Session }> {
@@ -73,7 +73,7 @@ describe('goal-session prompt invariants', () => {
content: [{ type: 'text', text: 'ordinary human message' }],
source: userSource,
}), { surfaceOp: 'append' })
session.append('turn/end', { turn: 4, reason: { kind: 'completed' } })
session.append('turn/end', { turn: 4, step: 0, reason: { kind: 'completed' } })
const stateSource = {
kind: 'goal', goalId: change.goal.id, revision: change.goal.revision, round: 0,

View File

@@ -38,13 +38,10 @@ function stubAgentForSession(session: Session): StubAgent {
inbox,
ctx: new Context(),
status: 'idle',
acceptsNextStep: false,
send: () => {},
updateInbox: () => 'not-found',
followup: () => {},
steer: () => {},
inject(input) { inbox.append('next-step', input) },
reserveTurnAdmission: () => undefined,
cancel() {},
whenIdle() { return Promise.resolve() },
}
@@ -76,7 +73,7 @@ function appendRound(session: Session, ref: GoalRef, round: number): void {
session.append('user/message', createUserMessage({
content: [{ type: 'text', text: `round ${round}` }], source,
}), { surfaceOp: 'append' })
session.append('turn/end', { turn, reason: { kind: 'completed' } })
session.append('turn/end', { turn, step: 0, reason: { kind: 'completed' } })
}
describe('GoalService creation and replay', () => {
@@ -584,7 +581,7 @@ describe('goal replay validation', () => {
session.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'ordinary' }], source,
}), { surfaceOp: 'append' })
session.append('turn/end', { turn, reason: { kind: 'completed' } })
session.append('turn/end', { turn, step: 0, reason: { kind: 'completed' } })
expect(foldGoal(session.events)).toEqual({ roundsStarted: 0 })
})
@@ -726,7 +723,7 @@ describe('goal replay validation', () => {
session.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'missing' }], source,
}), { surfaceOp: 'append' })
session.append('turn/end', { turn, reason: { kind: 'completed' } })
session.append('turn/end', { turn, step: 0, reason: { kind: 'completed' } })
expect(() => foldGoal(session.events)).toThrow('goal message source is invalid')
})

View File

@@ -45,7 +45,6 @@ function liveAgent(ctx: Context, session: Session): Agent {
inject(input: UserMessage) {
inbox.append('next-step', input)
},
reserveTurnAdmission: () => undefined,
cancel() {},
whenIdle() { return Promise.resolve() },
}

View File

@@ -38,7 +38,6 @@ function stubAgent(rawId: string, supplied?: Session): StubAgent {
inject(input) {
this.inbox.append('next-step', input)
},
reserveTurnAdmission: () => undefined,
cancel() {},
whenIdle() { return Promise.resolve() },
}
@@ -66,7 +65,7 @@ function openTurn(stub: StubAgent, source: MessageSource, text = 'prompt'): numb
/** Close the currently open test turn. */
function closeTurn(stub: StubAgent, turn: number): void {
stub.session.append('turn/end', { turn, reason: { kind: 'completed' } })
stub.session.append('turn/end', { turn, step: 0, reason: { kind: 'completed' } })
}
async function harness(config: toolGoal.Config = {}) {