diff --git a/src/main/runtime/orchestration/federation/remote-owned/remote-owed-actions.test.ts b/src/main/runtime/orchestration/federation/remote-owned/remote-owed-actions.test.ts index 0eaa1a967ef..3de7d7e3381 100644 --- a/src/main/runtime/orchestration/federation/remote-owned/remote-owed-actions.test.ts +++ b/src/main/runtime/orchestration/federation/remote-owned/remote-owed-actions.test.ts @@ -407,6 +407,22 @@ describe('what the coordinating Orca owes a paired server', () => { expect(getRemoteRunLink(db, link.conversation_id)?.state).toBe('closed') expect(owed().stop_owed).toBe(0) }) + it('names the re-pair, not a reset, when another path closed the link while a send waited', async () => { + startedOnB() + oweRemoteDispatchStop(db, 'ctx_b1', 'intent_1') + let release!: () => void + beforeSend = () => new Promise((resolve) => (release = resolve)) + const pending = sendOwedRemoteStop(runtime, owed()) + await vi.waitFor(() => expect(release).toBeDefined()) + server = { ...server, peerFingerprint: 'host_b_new' } + openRemoteRunLink(db, run.id, server) + release() + await expect(pending).rejects.toMatchObject({ + code: 'remote_link_closed', + message: `The pairing with devB was re-made, so it no longer runs Run ${run.id}'s workers. No effects were applied.` + }) + expect(sent).toEqual([]) + }) }) describe('S4 orphan lookup', () => { diff --git a/src/main/runtime/orchestration/federation/remote-owned/remote-owned-calls.ts b/src/main/runtime/orchestration/federation/remote-owned/remote-owned-calls.ts index cbffc6b7379..56deee8a68c 100644 --- a/src/main/runtime/orchestration/federation/remote-owned/remote-owned-calls.ts +++ b/src/main/runtime/orchestration/federation/remote-owned/remote-owned-calls.ts @@ -53,11 +53,14 @@ export async function callRemoteOwnedServer( ) } if (!current || !call.whileLink.includes(current.state)) { - throw new OrchestrationError( - 'remote_link_closed', - `Run ${link.run_id} was reset on this Orca, so nothing more goes to ${server.name} for it. No effects were applied.`, - { effectsApplied: false } - ) + // Only a re-made pairing closes a link; a reset leaves it owing a cancel. + const why = + current?.state === 'closed' + ? `The pairing with ${server.name} was re-made, so it no longer runs Run ${link.run_id}'s workers.` + : `Run ${link.run_id} was reset on this Orca, so nothing more goes to ${server.name} for it.` + throw new OrchestrationError('remote_link_closed', `${why} No effects were applied.`, { + effectsApplied: false + }) } } requireLink()