diff --git a/src/main/runtime/rpc/methods/orchestration/federation/peer-mail.test.ts b/src/main/runtime/rpc/methods/orchestration/federation/peer-mail.test.ts index 590d1af17c0..c624b2989fa 100644 --- a/src/main/runtime/rpc/methods/orchestration/federation/peer-mail.test.ts +++ b/src/main/runtime/rpc/methods/orchestration/federation/peer-mail.test.ts @@ -181,6 +181,10 @@ describe('agent mail between paired Orca servers', () => { thread_id: onB!.id }) + await expect( + mutation(a, 'orchestration.reply', { id: back!.id, body: 'x', from: 'term_a', on: 'devB' }) + ).resolves.toMatchObject({ ok: false, error: { code: 'request_mismatch' } }) + // The opener can keep answering, and the reply reaches the same agent again. await expect( mutation(a, 'orchestration.reply', { id: back!.id, body: 'Thanks.', from: 'term_a' }) diff --git a/src/main/runtime/rpc/methods/orchestration/messaging/peer-mail-reply.ts b/src/main/runtime/rpc/methods/orchestration/messaging/peer-mail-reply.ts index 1533bdf31c5..e78a9abda6a 100644 --- a/src/main/runtime/rpc/methods/orchestration/messaging/peer-mail-reply.ts +++ b/src/main/runtime/rpc/methods/orchestration/messaging/peer-mail-reply.ts @@ -41,14 +41,15 @@ export async function replyOverPeerMail(args: { const threadId = original.thread_id ?? original.id const senderLabel = peerMailSenderLabel(runtime, replier) + if (params.on !== undefined) { + throw new OrchestrationError( + 'request_mismatch', + `${original.id} came from ${original.from_handle}; its reply goes back there by itself. Drop --on. No reply was sent.`, + NOTHING_SENT + ) + } + if (conversation.role === 'peer') { - if (params.on !== undefined) { - throw new OrchestrationError( - 'request_mismatch', - `${original.id} came from ${original.from_handle}; its reply goes back there by itself. Drop --on. No reply was sent.`, - NOTHING_SENT - ) - } db.enqueueFederationRelay({ dispatchId: conversation.conversation_id, direction: 'to_home', @@ -72,16 +73,6 @@ export async function replyOverPeerMail(args: { } const environmentId = conversation.environment_id ?? '' - if (params.on !== undefined) { - const named = runtime.resolveOrchestrationWorkerServer(params.on) - if (named.environmentId !== environmentId) { - throw new OrchestrationError( - 'request_mismatch', - `${original.id} came from server ${original.from_handle}, not ${named.name}. Drop --on; the reply goes back there by itself. No reply was sent.`, - NOTHING_SENT - ) - } - } if (!route.remote_party) { throw new OrchestrationError( 'request_mismatch',