Coordinate shared GPU access across studio instances

This commit is contained in:
Towsty
2026-09-06 16:32:18 -05:00
parent 911ddeab55
commit 0c6a035d04
17 changed files with 582 additions and 64 deletions
+12 -1
View File
@@ -1,3 +1,4 @@
import { assertSharedGpu, sharedGpuHeaders } from '~/server/utils/sharedGpu'
import { LTX_NEGATIVE } from '~/utils/videoModels'
import { createHash } from 'node:crypto'
import { comfyJobPrefix } from '~/utils/outputNames'
@@ -73,6 +74,9 @@ function configuredComfyBase() {
}
export function getComfyHost() {
// Shared studios must never bypass the reservation-enforcing proxy.
const sharedHost = agentFrontDoorOrigin()
if (sharedHost) return sharedHost
if (comfyHostOverride) return viaAgentFrontDoor(comfyHostOverride) || comfyHostOverride
return viaAgentFrontDoor(configuredComfyBase()) || configuredComfyBase()
}
@@ -83,6 +87,12 @@ export function comfyWsUrl(clientId: string) {
export async function comfyFetch(path: string, init?: RequestInit) {
const url = `${getComfyHost()}${path}`
if (init?.method && !['GET', 'HEAD'].includes(init.method.toUpperCase())) {
await assertSharedGpu()
const headers = new Headers(init.headers)
for (const [key, value] of Object.entries(sharedGpuHeaders())) headers.set(key, value)
init = { ...init, headers }
}
try {
return await fetch(url, init)
} catch (error) {
@@ -623,7 +633,8 @@ async function purgeOnDesktop(opts: {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {})
...(token ? { Authorization: `Bearer ${token}` } : {}),
...sharedGpuHeaders()
},
body: JSON.stringify({
imageName: imageNames[0] || '',