diff --git a/src/main/native-chat/agent-session-wire/delivery/structured-agent-session-queued-mutations.ts b/src/main/native-chat/agent-session-wire/delivery/structured-agent-session-queued-mutations.ts index 731ed1de416..1b69c874bf6 100644 --- a/src/main/native-chat/agent-session-wire/delivery/structured-agent-session-queued-mutations.ts +++ b/src/main/native-chat/agent-session-wire/delivery/structured-agent-session-queued-mutations.ts @@ -134,20 +134,19 @@ export function sendQueuedStructuredAgentMessage( if (row.body.command && work.working()) { return invalid("A command can't be sent while the agent is working.") } + // An earlier unechoed send never blocks: delivery orders handovers behind it and its opening turn. if ( (work.activeTurnId() !== null || work.queueState().owedEnteredSubmissions.length > 0) && - (work.activeTurnId() === null || - work.queueState().owedEnteredSubmissions.length > 0 || - !canSteerStructuredQueuedMessage( - { - record, - work, - child: context.sessions.get(ctx.sessionId)?.child, - stopping: await context.readStopping(ctx.sessionId), - adapter: context.deps.adapter - }, - row - )) + !canSteerStructuredQueuedMessage( + { + record, + work, + child: context.sessions.get(ctx.sessionId)?.child, + stopping: await context.readStopping(ctx.sessionId), + adapter: context.deps.adapter + }, + row + ) ) { return { ok: false, diff --git a/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-queued-messages.test.ts b/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-queued-messages.test.ts index 9cc24d687f2..e7b2a074bcb 100644 --- a/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-queued-messages.test.ts +++ b/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-queued-messages.test.ts @@ -72,3 +72,16 @@ it('a steer send waiting on approval joins the running turn when approval clears await eventually(async () => expect((await rig.handoff(steer.id))?.handedOverAt).toBeDefined()) expect(await rig.handoff(queueOnly.id)).toBeUndefined() }) + +it('Send-now steers a second card while the first steer is still unechoed', async () => { + const opener = await rig.workingSend() + await rig.settleAccepted(opener, 'opening') + await openRigTurnFor(rig, opener) + const first = rig.send('first card', 'queue-if-active') + const second = rig.send('second card', 'queue-if-active') + await Promise.all([first.result, second.result]) + expect(await rig.sendNow(first.id)).toMatchObject({ ok: true }) + await eventually(async () => expect((await rig.handoff(first.id))?.handedOverAt).toBeDefined()) + expect(await rig.sendNow(second.id)).toMatchObject({ ok: true }) + await eventually(async () => expect((await rig.handoff(second.id))?.handedOverAt).toBeDefined()) +})