diff --git a/src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts b/src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts index 4fbe9d527ae..aa3430ec5bf 100644 --- a/src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts +++ b/src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts @@ -28,7 +28,14 @@ export const ORCHESTRATION_FEDERATION_CONTROL_METHODS = [ params: FederationFleetSnapshotParams, handler: async (params, { runtime, authenticatedCallerFingerprint }) => { const items = await mapWithConcurrency(params.dispatchIds, 16, async (dispatchId) => { - requireHomeAttachment(runtime, dispatchId, authenticatedCallerFingerprint) + const attachment = runtime.getOrchestrationDb().getRemoteDispatchAttachment(dispatchId) + // A Dispatch this home no longer holds here, such as one from an earlier pairing, must not hide the rest. + if (!attachment || attachment.home_peer_fingerprint !== authenticatedCallerFingerprint) { + return { + dispatchId, + observation: { status: 'unverifiable' as const, exactWorker: false } + } + } const observation = await observeRemoteAttachmentLiveness(runtime, dispatchId) const db = runtime.getOrchestrationDb() const autoReleaseAt = db.getLiveWorkerTerminalAutoReleaseAt(dispatchId) diff --git a/src/main/runtime/rpc/methods/orchestration/federation/federation-liveness-verdict.test.ts b/src/main/runtime/rpc/methods/orchestration/federation/federation-liveness-verdict.test.ts index 65bd9c84da4..fc8dd1dad5c 100644 --- a/src/main/runtime/rpc/methods/orchestration/federation/federation-liveness-verdict.test.ts +++ b/src/main/runtime/rpc/methods/orchestration/federation/federation-liveness-verdict.test.ts @@ -234,6 +234,83 @@ describe('federation host liveness verdicts', () => { }) }) + it('still reports its own workers when one requested Dispatch belongs to an earlier pairing', async () => { + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: observation reads only these terminal fields. + vi.spyOn(runtime, 'showTerminal').mockResolvedValue({ + handle: HANDLE, + worktreeId: 'repo::remote-worktree', + connected: true, + status: 'running' + } as never) + vi.spyOn(runtime, 'getTerminalLivenessVerdict').mockReturnValue(null) + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: observation reads only the host scope. + vi.spyOn(runtime, 'getOrchestrationDispatchAuthority').mockReturnValue({ + hostScope: { kind: 'local', hostId: 'local' } + } as never) + + const earlierPane = 'tab_earlier:cccccccc-cccc-4ccc-8ccc-cccccccccccc' + vi.mocked(runtime.getTerminalPaneKey).mockImplementation((handle) => + handle === 'term_earlier_worker' ? earlierPane : PANE_KEY + ) + vi.mocked(runtime.getTerminalProcessIncarnation).mockImplementation((handle) => + handle === 'term_earlier_worker' ? 'runtime:pty:earlier' : INCARNATION + ) + // Started for this server's earlier pairing with the home, so it is held under another fingerprint. + db.createRemoteDispatchAttachment({ + runId: 'run-home', + dispatchId: 'ctx_from_an_earlier_pairing', + taskId: 'task_earlier', + homePeerFingerprint: 'earlier-pairing-fingerprint', + protocolVersion: ORCHESTRATION_CONTRACT_VERSION, + runtimeEpoch: runtime.getRuntimeId(), + mutationReceipt: { + callerFingerprint: 'earlier-pairing-fingerprint', + requestId: 'rpc_attach_earlier', + method: 'orchestration.federationStart', + payloadHash: 'hash' + } + }) + db.prepareRemoteAttachmentAuthority({ + dispatchId: 'ctx_from_an_earlier_pairing', + paneKey: earlierPane, + processIncarnation: 'runtime:pty:earlier', + worktreeId: 'repo::remote-worktree', + terminalHandle: 'term_earlier_worker', + setupState: 'not_applicable', + effects: [], + terminalOwnership: 'created' + }) + db.markRemoteAttachmentReady('ctx_from_an_earlier_pairing') + + await expect( + call('orchestration.federationFleetSnapshot', { + dispatchIds: ['ctx_from_an_earlier_pairing', DISPATCH_ID] + }) + ).resolves.toMatchObject({ + items: [ + { + dispatchId: 'ctx_from_an_earlier_pairing', + // Nothing of another fingerprint's Dispatch is read or returned. + observation: { status: 'unverifiable', exactWorker: false } + }, + { dispatchId: DISPATCH_ID, observation: { status: 'live', exactWorker: true } } + ] + }) + await expect( + call('orchestration.federationFleetSnapshot', { + dispatchIds: ['ctx_from_an_earlier_pairing'] + }) + ).resolves.toEqual({ + runtimeEpoch: runtime.getRuntimeId(), + items: [ + { + dispatchId: 'ctx_from_an_earlier_pairing', + observation: { status: 'unverifiable', exactWorker: false } + } + ] + }) + }) + it('keeps a disconnected verdict-less pane unverifiable rather than exited', async () => { vi.spyOn(runtime, 'getTerminalLivenessVerdict').mockReturnValue(null) vi.spyOn(runtime, 'getOrchestrationDispatchAuthority').mockReturnValue(null)